-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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(api.md): add notes on race condition in page.setViewport #4319
docs(api.md): add notes on race condition in page.setViewport #4319
Conversation
docs/api.md
Outdated
@@ -1799,6 +1804,20 @@ puppeteer.launch().then(async browser => { | |||
|
|||
In the case of multiple pages in a single browser, each page can have its own viewport size. | |||
|
|||
To avoid race condition with page's logic that sniffs for viewport properties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like inside baseball. Can we phrase it in a way that will make more sense to puppeteer users? Is this a bug or intended behavior? What happens if I emulate after navigating? If its a bug where is the link?
This also implies that I can't use setViewport to simulate a resize event. Is that true?
docs/api.md
Outdated
@@ -1799,6 +1804,20 @@ puppeteer.launch().then(async browser => { | |||
|
|||
In the case of multiple pages in a single browser, each page can have its own viewport size. | |||
|
|||
To avoid race condition with page's logic that sniffs for viewport properties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
page.setViewport will resize the page. A lot of websites don't expect phones to change size, so you should set the viewport before navigating to the page.
@@ -1236,7 +1236,8 @@ Emulates given device metrics and user agent. This method is a shortcut for call | |||
- [page.setViewport(viewport)](#pagesetviewportviewport) | |||
|
|||
To aid emulation, puppeteer provides a list of device descriptors which can be obtained via the [`puppeteer.devices`](#puppeteerdevices). | |||
Below is an example of emulating an iPhone 6 in puppeteer: | |||
|
|||
`page.emulate` will resize the page. A lot of websites don't expect phones to change size, so you should emulate before navigating to the page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is even easier. The user agent needs to be sent before the first navigation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair! Keeping it as-is doesn't hurt.
Fixes #2755.