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
Height of screenshots with cy.screenshot() in Chrome headless new is 79px smaller than viewportHeight config that is set #27260
Comments
After more investigation, my "fix" is no real fix, it just makes the problem less obvious. The viewport is still taking the default height (e.g. 596px for chrome), but cypress default |
Alright, after reading this article (in particular, the distinction between viewport and window) I feel a little less flabbergasted. The only important thing to note, though, is that starting in cypress 12.15, chrome subtracts 124px from the window's height. I have no idea why, but the release notes for 12.15 mention that "Chrome versions 112 and above will now be run in the headless mode that matches the headed browser implementation". So, there's definitely something there. In a nutshell, I don't know if this is a bug or not, but if you want to keep the same behavior as in before cypress 12.15, you need to add this to your on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome') {
launchOptions.args.push(`--window-size=1280,${720 + 124}`);
}
return launchOptions;
}); (note the magical |
I could be misunderstanding or doing it wrong, but I could not reproduce this. I tried making a page that is 738px high (4x 180px + 18px) and used Cypress 12.14, then Cypress 12.17. Both screenshots are the same - 738px high:
I tried with Would be nice to find out what exactly changed, this could be a huge rabbit hole. Any recommendation for moving forward? We are using Percy for visual regression and none of our tests (500+ screenshots) had any changes... strange. |
That is really strange, @lmiller1990 . Adding that
|
I've just run those two commands in my computer as well and got the exact same results as @jmeleropager 🤯 So, the problem is caused indeed by Cypress 12.15 changing to |
To clarify what headless: new is, see https://developer.chrome.com/articles/new-headless/. As for this discovery; is the proposed fix to simply add a hard-coded value of 124 to the viewport height during a chrome headless=new screenshot? If this really fixes the issue and Cypress continues to work how you'd expect, this seems like a reasonable proposed fix to me. |
I suspect it's also related to #27291. The screenshotting mechanics seems totally broken:
|
@yktoo is this a general bug report of specific to chrome 114+ and the new headless mode (which seems to be the general consensus here in this issue). If there's a separate bug, we should file a separate issue - if something is totally broken, this is a high priority (although all the screenshots in my projects look okay, it's definitely possible something regressed, although my understanding is nothing changed around there lately). |
@lmiller1990 Well it depends of course on the definition of "totally," but to me the combination of this one and #27291 renders screenshots pretty much unusable. The good news is failure screenshots are not affected (so it seems at least). I believe these two bugs cover the existing problems. |
#27291 looks like a huge problem - I don't see this on my apps, but we will look into what's happening there - a core feature like this should work perfectly (and our tests say it does... maybe we missed some cases). |
this workaround doesn't work if we screenshot elements, not full page. Elements are smaller than they need to be, if our website is flexible. |
I am also experiencing issues with screenshots (viewportwidth / viewportheight are not respected and or screenshot is made with a zoomlevel). Very annoying when using visual testing (for example with cypress-image-diff-js), especially on specific elements. @4knort did you already find a workaround or solution for your problem? |
Any updates here? We've been stuck with v12.14.0 because of this issue (upgrading breaks our snapshot tests). |
Same here, recently upgraded to cypress The report at the end of the tests
Expected size: 1242x2208. Two of them are not correctly sized (first and last), but actually all of them are screwed: on the ones that seem to have the right height, the actual bit below 1857 and down to the bottom is filled with garbage that seem to be previous screenshots or some cache of what was rendered before. This seems pretty random as it occurs on the same run. Here, with my settings, the padding could be 117 (x3 which the scaleFactor). If this works for this resolution it feels clunky. And I tried with success the forcing of
|
There are two things going on here: Wont Fix - Browser BehaviorCypress updated to use Chrome's Bug - Capture
|
After a thorough evaluation of this described issue, Cypress has decided that the new behavior from Chrome headless=new in this case is something that we will not be changing our behavior around. With Chrome updating their headless browser to be the same codebase as the headed browser, this introduced Chrome's 'chrome' and UI like info bars taking up space within the window. This height is not under our control and it is able to change based on Chrome's implementation. I did find this issue on Chromium's side, where someone was saying this behavior should be the same as headless=old and Chromium should change it. I'm not sure if they intend to act on this though: https://issues.chromium.org/issues/40275252 We could arbitrarily add some height calculations, but this won't solve anything since this height is able to change based on Chrome's implementation. We'll be closing this issue. |
Current behavior
Currently, calling
cy.screenshot()
during a test will use the viewport dimensions (specified incypress.config.js
) if the test is run using "headed" mode. However, when using headless mode:viewportWidth
is respectedviewportHeight
is respected only if it's smaller than the "default". Otherwise, it's ignored.That "default" height seems to depend on the browser being used. In cypress 12.14, the default was 720px for both chrome and firefox. However, in cypress 12.17, it's 720px for firefox, but 596px for chrome.
If you watch the video corresponding to the headless executions, sometimes you can even see, for a small fraction of a second, that the screen changes, removing all the Cypress UI elements, but also changing the viewport height.
cypress.bug.mp4
A straightforward workaround for this is adding this line before capturing the screenshot:
Desired behavior
Cypress should respect the specified
viewportHeight
.Test code to reproduce
https://github.com/lgenzelis/cypress-bug-screenshot-viewportheight-ignored
If you run this using
npm run cypress:open
, the screenshot is captured with the correct dimensions (specified incypress.config.js
). If run it usingnpm run cypress:run
, though, the resulting screenshot is 400px wide (as expected), but only 596px tall.Cypress Version
12.17.0
Node version
v18.14.0
Operating System
macos 13.4.1
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: