[REGRESSION]: context.pages() now works differently
See original GitHub issueContext:
- GOOD Playwright Version: [what Playwright version worked nicely?]
- BAD Playwright Version: [what Playwright version doesn’t work any more?]
- Operating System: [e.g. Windows, Linux or Mac]
- Extra: [any specific details about your environment]
-GOOD Playwright 1.0.1
-BAD Playwright 1.2.0
-Operating System: Windows 10
Code Snippet
Help us help you! Put down a short code snippet that illustrates your bug and that we can run and debug locally. For example:
const {chromium, webkit, firefox} = require('playwright');
(async () => {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.click('[name="Add new child window"]')
//This code worked back in 1.0.1
const allPages = await context.pages();
const childWindowPage = allPages[allPages.length - 1];
///////////////////////////////////////////////////////////////////
// Now you need to do it this way (1.2.0 version)
await page.waitForTimeout(5000);
const allPages = await context.pages();
const childWindowPage = allPages[allPages.length - 1];
})();
Describe the bug
For some reason in current (1.2.0) version you must wait till page is loaded, before you can grab it and assign it to a variable via context.pages() method… This wasnt the case in 1.0.1 version.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Why Do I Get Different Results Each Time in Machine Learning?
That means, when the algorithm is given the same dataset, it learns the same model every time. An example is a linear regression...
Read more >How To Interpret R-squared in Regression Analysis
Statisticians say that a regression model fits the data well if the differences between the observations and the predicted values are small and...
Read more >Interactions in Multiple Linear Regression
Interaction: An interaction occurs when an independent variable has a different effect on the outcome depending on the values of another independent variable....
Read more >Hypothesis Testing in the Multiple regression model - UCL
with the simple two variable regression model. • Now suppose we wish to test that a number of coefficients or ... the regression...
Read more >Introduce config context to make original config and different ...
Set a default configuration context for the page request, ... config() calls in // API functions) will work with the context on the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The old snippet from 1.0.1 happened to work accidentally, because sometimes
page.click()was resolving after the new page has been created. In 1.2, this happens less frequently - that’s why you see that snippet does not work anymore.Overall, Playwright does not guarantee that by the time
page.click()is resolved, all the pages opened by this click are available. Moreover, this is almost impossible to guarantee, because it is hard to determine whether the new page was indeed a result of a click or not, and whether the click will open a page after a timeout.Instead, we recommend the following way to capture popups from clicks:
You can find even more samples in our documentation.
@MihailPertsev The actual change in 1.2.0 is that
page.click()returns earlier instead of taking long enough time for the new page to appear incontext.pages().It would indeed be handy if
context.pages()would give you pages immediately after click, but we cannot guarantee that because:fetch()finishing;page.click()resolves. The alternative would be to wait for undetermined amount of time inpage.click(), but we cannot afford that.Hopefully, this explanation helps a bit.