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
Behavior of setViewport() inconsistent in Headful #1910
Comments
Also experimented adding a Same results. 😕 |
➜ testChromium node t.js
Detected window.innerWidth to be 800.
➜ testChromium node t.js
Detected window.innerWidth to be 800.
➜ testChromium node t.js
Detected window.innerWidth to be 800.
➜ testChromium node t.js
Detected window.innerWidth to be 800.
➜ testChromium node t.js
Detected window.innerWidth to be 800.
➜ testChromium node t.js
Detected window.innerWidth to be 800.
|
@aslushnikov THX, I want to create a page demo, show the full page to someone else, but now only show part of viewport. |
@aslushnikov Actually I would just like to use this while developing. I almost always use Chrome maximized, and while developing with PPTR, one of several things happen:
It is helpful to have PPTR match the behavior of my Chrome, no matter which computer/resolution I'm at. Granted, it's not a huge issue, but I find the inconsistency intriguing. |
when i delete some code, that be ok: file line code // Initialize default page size.
if (!appMode)
await page.setViewport({width: 800, height: 600}); I think maybe the |
@aizuyan You don't need to delete it, can just pass However, I have no idea what this option is for, it's not documented anywhere. BTW, care to clarify what you mean by "that be ok"? |
@alixaxel my english is poor 😶🙃🙂 |
I can't reproduce this as of puppeteer v1.7.0. @alixaxel is this still relevant to you? P.S. There's now a |
I work around this by setting the Browser.setWindowBounds to where I guess 64 to approximate the window chrome above the tab viewport in regular headful chrome. |
This helps prevent the irregularity of Emulation.setVisibleSize sometimes reverts back to the window bounds when in headful mode. I have not seen this happen in headless mode. |
I was struggling with a similar issue (trying to resize the viewport in headless), but thanks to aslushnikov's answer on another thread I was able to use this workaround function for both headful and headless modes: async function setWindowSize(page, width, height) {
if(headless) {
const session = await page.target().createCDPSession();
const {windowId} = await session.send('Browser.getWindowForTarget');
await session.send('Browser.setWindowBounds', {windowId, bounds: {width: width, height: height}});
await session.detach();
} else {
await page.setViewport({width: width, height: height});
}
} Apologies that it isn't the most idiomatic async Javascript code.. I would use Maybe someone can put together a workaround that measures the width/height differences between the two methods upon the first call in headful, then accounts for those differences during subsequent calls. That way Note that the width also seems to be inconsistent, but that could be due to css rules in my project. Also the sizes are different between headless and headful, so to avoid a bunch of false positives, you'll need to run your tests completely in one mode or the other for now. In my case that's fine, since I was just trying to make window resizing work headless. If any of the devs read this, please please remove all runtime differences due to implementation details between headful and headless. We shouldn't have to worry about the window bounds not working just because we're running headless. I realize that this is probably a goal of yours, and that you probably have your hands tied by the Chrome devs not realizing the we still need to resize windows during development: |
The only workaround I found to be working is manually adding 16 to the width and 133 to the height (these numbers are different on different platforms...). Does anyone find a more automatic workaround? I tried setting bounds and then measuring client width and height (by |
I guess I forgot to disable |
So, I have found a workaround, but it requires capturing screenshot in the
It works with defaultViewport, because fromSurface ignores it. |
Seems like the |
We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days. |
You can think about |
Environment:
What steps will reproduce the problem?
Running the following code several times.
What is the expected result?
I should get the save
window.innerWidth
all the time.What happens instead?
Seems that sometimes
setViewport()
fails silently and fallbacks to the default viewport size of 800x600.The text was updated successfully, but these errors were encountered: