Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] New browser windows are opened instead of tabs on every newPage() #5034

Closed
apmcodes opened this issue Jan 15, 2021 · 6 comments
Closed

Comments

@apmcodes
Copy link

Trying to use a single browser instance with mutiple sessions (pages/ tabs), but on every newPage() a new window is launched instead of a tab.

main.js

const chromium = require('playwright').chromium;
const options =  {
  headless: false,
  timeout: 30000,
},
const browser = await chromium.launch(options);
app.set('browser', browser);

At this point browser window is not opened. (Unlike puppeteer which opens a new browser window on launch)

/lib/other.js

const browser = app.get('browser');
const page = await browser.newPage();

Now a new browser window is opened every time newPage is called, instead of opening a new page in the existing window.

So, Is this the expected behaviour with PlayWright?

NOTE: Puppeteer would open a window once (on launch) and add tabs on every newPage().

@yury-s
Copy link
Member

yury-s commented Jan 16, 2021

So, Is this the expected behaviour with PlayWright?

Yes, this intentional behavior. Each page is opened in its own window. We had to split it for video recording to properly work in other browsers and wanted to keep it consistent across browsers. Moreover, in your code snippet each page created by const page = await browser.newPage(); will have its own context and we do not want to mix pages from separate contexts in the same window (similar to how pages from different chrome profiles could never be combined as tabs in the same window). Your code is equivalent to:

const context = await browser.newContext();
const page = await context.newPage();

Is there a test scenario that doesn't work with separate window per page approach?

@shirshak55
Copy link

@yury-s Yes it doesn't work when you are using headful mode and vnc server. If it was multi tab we could access all tab easily but multiple windows are not accessible. We test chat application and it has become too annoying. and we need headful mode because some of the tests are done in headful mode with manual intervention. It only happens in launchPersistantContext .

@pavelfeldman
Copy link
Member

It is unclear why vnc has a problem with multiple windows though?

@shirshak55
Copy link

@pavelfeldman vnc is always like that. When there is window on top on another window old window is hidden . And its usually hard to manage window and tabs are easier to manage in heedful mode too.

@pavelfeldman
Copy link
Member

But there is bringToFront that is equivalent to surfacing the tab or does that not work?

@apmcodes
Copy link
Author

Is there a test scenario that doesn't work with separate window per page approach?

Well, our use case is not exactly related to testing but scrapping at high volume. Thus, opening many windows paralelly would hamper the memory footprint of our apps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants