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(api.md): add notes on race condition in page.setViewport #4319

Merged

Conversation

aslushnikov
Copy link
Contributor

Fixes #2755.

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,
Copy link
Collaborator

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,
Copy link
Collaborator

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.
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

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.

blurry canvas if deviceScaleFactor > 1
2 participants