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

No way to determine native DPR of device #2358

Closed
ebidel opened this issue Apr 11, 2018 · 5 comments
Closed

No way to determine native DPR of device #2358

ebidel opened this issue Apr 11, 2018 · 5 comments

Comments

@ebidel
Copy link
Contributor

ebidel commented Apr 11, 2018

The following code doesn't allow someone to use the device's native DPR by setting await page.setViewport({deviceScaleFactor: 0,...}):

https://github.com/GoogleChrome/puppeteer/blob/master/lib/Page.js#L729
https://github.com/GoogleChrome/puppeteer/blob/294f33b75c5a7c87d447816218438f56c2d56f0e/lib/EmulationManager.js

That makes it impossible to determine the real DPR of the device:

await page.evaluate('window.devicePixelRatio'); 
@JoelEinbinder
Copy link
Contributor

Easy fix, but why do you need the native DPR? It should be largely irrelevant in headless afaik.

@ebidel
Copy link
Contributor Author

ebidel commented Apr 12, 2018

You want to know this information for taking high quality screenshots.

For my particular case, I'm running an app in both mac and linux. So I want to use the correct DPR per the device without hard coding numbers.

aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Apr 12, 2018
This patch:
- teaches page.setViewpot() to accept `null` to disable
viewport emulation.
- allows passing `0` as deviceScaleFactor to use machine-defined
deviceScaleFactor.

References puppeteer#1183.
Fixes puppeteer#2358.
@JoelEinbinder
Copy link
Contributor

Why would the dpr of the device affect the screenshot quality? The device doesn’t necessarily have a single dpr

@ebidel
Copy link
Contributor Author

ebidel commented Apr 12, 2018

You need to emulate a viewport with deviceScaleFactor: 2 to produce crisp screenshots on a retina mac. On Linux, using that produces a screenshot that's 2x what you actually need...and it's buggy. See our pptr chat.

@aslushnikov
Copy link
Contributor

Let's introduce a viewport option to the launcher as a part of #1183. One of the values could be null to disable viewport override altogether.

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

No branches or pull requests

3 participants