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

docs: add new doc for multi-page scenarios #2737

Merged
merged 5 commits into from
Jun 29, 2020

Conversation

arjunattam
Copy link
Contributor

Closes #2602

const pageTwo = await context.newPage();

// Get pages of a brower context
const allPages = await context.pages();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to await pages(), it is sync.

console.log(await newPage.title());

// Get all new pages (including popups) in the context
context.on('page', page => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • async page => ... for it to compile :)
  • same thing about domcontentloaded

await popup.title();

// Get all popups when they open
page.on('popup', popup => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

  • async
  • waitForLoadState

context.waitForEvent('page'),
page.evaluate(() => window.open('https://google.com', '_blank'))
])
console.log(await newPage.title());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need at least domcontentloaded before accessing title, but preferably load for everything else.

await newPage.waitForLoadState('domcontentloaded');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Updated to use newPage.waitForLoadState() since that covers more scenarios for the audience of a guide like this.

page.waitForEvent('popup'),
page.click('#open')
]);
await popup.title();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use popup.waitForLoadState()

@arjunattam arjunattam merged commit c807612 into microsoft:master Jun 29, 2020
@arjunattam arjunattam deleted the multi-page branch June 29, 2020 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to handle multiple pages
2 participants