question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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().

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-scommented, 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?

0reactions
apmcodescommented, Jan 20, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

htmlpage.window.navigate opens a new page or new tab on ...
First click should open a new window and next click should refresh the same opened window or tab which is already opened. –...
Read more >
Why Microsoft is opening every link in a new window
In my case, if Edge opens two tabs in a window, it will show only one instance of Edge in taskbar. Then when...
Read more >
Opening Links in New Browser Windows and Tabs
New windows or tabs can cause disorientation, with users often not realizing that a new window or tab has opened. This problem is ......
Read more >
Window.open() - Web APIs - MDN Web Docs
Users may use browser built-in features or extensions to choose whether to open a link in a new window, in the same window,...
Read more >
How to Make Links Open in a New Window or Tab
How to Open Hyperlinks in a New Browser Tab or Window ... The short answer is: just add a target="_blank" attribute to your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found