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

cy.screenshot not respecting the viewport size on Firefox. #15481

Closed
aayknija opened this issue Mar 15, 2021 · 4 comments · Fixed by #15686
Closed

cy.screenshot not respecting the viewport size on Firefox. #15481

aayknija opened this issue Mar 15, 2021 · 4 comments · Fixed by #15686

Comments

@aayknija
Copy link

aayknija commented Mar 15, 2021

Using: Cypress package version: 6.6.0, OS-Windows 10 , Firefox -86.0.1 (64-bit)

As per the documentation, I have added the below code snippet in plugins/index.js still it is not working as expected. The expectation is to take the screenshot in provided resolution.

Command: cypress run --browser firefox --headless

on('before:browser:launch', (browser = {}, launchOptions) => {
    if (browser.name === 'firefox') {
      launchOptions.args.push('--width=1680');
      launchOptions.args.push('--height=1024');
      return launchOptions;
    }
  });

P.S: It works perfectly on chrome with the below code snippet in plugins/index.js

on('before:browser:launch', (browser = {}, launchOptions) => {
   if (browser.name === 'chrome') {
     launchOptions.args.push('--disable-dev-shm-usage');
     launchOptions.args.push('--window-size=1680,1024');
     launchOptions.args.push('--disable-gpu');
     return launchOptions;
   }
 });

I tried adding --disable-dev-shm-usage and --disable-gpu for firefox also but it did not work.

@kuceb
Copy link
Contributor

kuceb commented Mar 25, 2021

@aayknija can you provide what screenshot size you're seeing with those options in firefox? It's possible the window size for firefox includes the ~74 pixels of titlebar/menu, so the screenshots may be 1680x950. If that's the case you can try adding 74px to the height argument. We haven't normalized this for users since it's unclear how stable it would be.

   if (browser.name === 'firefox') {
      launchOptions.args.push('--width=1680');
      launchOptions.args.push('--height=1098');
      return launchOptions;
    }

@aayknija
Copy link
Author

@bkucera Apologies for the delayed response. I did try the above option as well. The issue was it was not respecting the width and height provided in launch options. I was getting an image with a resolution of 1680x950 and size did vary in the docker image.

Finally, after some google search, I found one solution where I have to define MOZ_HEADLESS_WIDTH and MOZ_HEADLESS_HEIGHT in the environment variable and that worked for me.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 1, 2021

The code for this is done in cypress-io/cypress#15686, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@bahmutov
Copy link
Contributor

bahmutov commented Apr 7, 2021

Released in v7.0.0

@cypress-io cypress-io locked as resolved and limited conversation to collaborators May 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants