Reputation: 31
I use chromium.launchPersistentContext with extra args, and one of the args is --load-and-launch-app. The app got launched successfully but I could not interact with the app.
I tried adding a promise.all and waited for long time and get the pages that are opened, but nothing identifies the app the was opened by Playwright only the browser tab is accessible.
Is there any way that the app can be accessible?
In selenium, it can be easily done by driver.getWindowHandles() and then switch tab based on title/URL.
const { chromium } = require('playwright');
(async () => {
const context = await chromium.launchPersistentContext(' ', {
headless: false,
args: [
'--disable-extensions-except=dist', '--load-and-launch-app=dist']
});
// Wait for the new page (app window) to be created
let appPage;
for (let i = 0; i < 10; i++) {
const pages = context.pages();
if (pages.length > 1) {
appPage = pages[pages.length - 1];
break;
}
await new Promise(resolve => setTimeout(resolve, 5000)); // wait 5000ms before checking again, I can see the app opened but the playwright couldnot access or find it
}
if (!appPage) {
console.log('App page not found.');
await context.close();
return;
}
// interact with the appPage
await appPage.waitForLoadState('domcontentloaded'); // Ensure the app is loaded
console.log('App page found and loaded.');
// interaction
await appPage.click('selector*');
// context when done
await context.close();
})();
Upvotes: 0
Views: 75