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

Add additional flags when running Chrome #3633

Closed
mitar opened this issue Mar 3, 2019 · 9 comments · Fixed by #5310
Closed

Add additional flags when running Chrome #3633

mitar opened this issue Mar 3, 2019 · 9 comments · Fixed by #5310
Labels
stage: needs review The PR code is done & tested, needs review

Comments

@mitar
Copy link

mitar commented Mar 3, 2019

Current behavior:

Currently, Cypress is regularly failing inside Docker. This is a known problem, even described in documentation.

In documentation the workaround is to add --ipc=host and there is a link to this issue: #350

Another solution mentioned is increasing /dev/shm size for the container.

But none of this is a solution one can use on public CI systems where you do not control how Docker container is run.

Desired behavior:

When rendering large pages using Cypress inside Docker-based CI systems, Cypress should not crash.

Solution:

Adopt switches used by Google Chrome official puppeteer project. They have various list of switches to fix these and similar problems. See the list here:

  '--disable-background-networking',
  '--enable-features=NetworkService,NetworkServiceInProcess',
  '--disable-background-timer-throttling',
  '--disable-backgrounding-occluded-windows',
  '--disable-breakpad',
  '--disable-client-side-phishing-detection',
  '--disable-default-apps',
  '--disable-dev-shm-usage',
  '--disable-extensions',
  '--disable-features=site-per-process,TranslateUI',
  '--disable-hang-monitor',
  '--disable-ipc-flooding-protection',
  '--disable-popup-blocking',
  '--disable-prompt-on-repost',
  '--disable-renderer-backgrounding',
  '--disable-sync',
  '--force-color-profile=srgb',
  '--metrics-recording-only',
  '--no-first-run',
  '--safebrowsing-disable-auto-update',
  '--enable-automation',
  '--password-store=basic',
  '--use-mock-keychain',

Not all are relevant here, but some are. I think it would be great if most of those would be added to Chrome and Electron runners for Cypress, especially when they run inside CI.

The one which seems it will fix the problem with Chrome failing inside Docker-based CI is --disable-dev-shm-usage, so at least that one should be added. This is available since Chrome 65.

You could even detect if running inside Docker and set this flag automatically (if you do not want to simply set it always). Or if your run Cypress from command line instead of GUI.

For more information see tips section here.

@brian-mann
Copy link
Member

We'll take a look at these. You can control which additional command line args get passed to chrome as per documented here:

https://docs.cypress.io/api/plugins/browser-launch-api.html#Usage

@mitar
Copy link
Author

mitar commented Mar 4, 2019

Interesting. I didn't know that you can already set them. Will have to use installed Chrome browser instead of Electron to be able to use new flags though.

@Joelasaur
Copy link

Yeah I'm only seeing this issue in Electron. I'd like to get this working in our pipeline reliably because the videos produced are invaluable to troubleshooting issues with our application.

@Joelasaur
Copy link

Joelasaur commented Mar 4, 2019

It looks like Electron found the root cause back in 2016 and has labeled it as "Won't fix"

electron/electron#4491

So that isn't fun...

@flotwig
Copy link
Contributor

flotwig commented Sep 12, 2019

I compared the list of flags in the OP to chrome.coffee, here are the 12 we don't currently pass:

[
  "--disable-background-networking",
  "--enable-features=NetworkService,NetworkServiceInProcess",
  "--disable-backgrounding-occluded-windows",
  "--disable-breakpad",
  "--disable-component-extensions-with-background-pages",
  "--disable-dev-shm-usage",
  "--disable-extensions",
  "--disable-features=TranslateUI,BlinkGenPropertyTrees",
  "--disable-ipc-flooding-protection",
  "--force-color-profile=srgb",
  "--password-store=basic",
  "--use-mock-keychain"
]

These probably don't need to be added:

I'm not sure about --force-color-profile=srgb, can't figure out how this would be useful for testing.

I think, based on the switch descriptions, these are all a good idea to add:

  • --disable-ipc-flooding-protection Cypress itself can run in to "IPC flooding protection", so disabling it is a good idea (Add Chromium flag --disable-ipc-flooding-protection #5132)
  • --disable-dev-shm-usage I believe that all this does is move shared memory out of /dev/shm. It can probably be enabled for any runtime, not just Docker.
  • --disable-backgrounding-occluded-window, --disable-breakpad, --password-store=basic, --use-mock-keychain all sound great

I also wonder if any/all of these should also be passed to Electron.

@flotwig
Copy link
Contributor

flotwig commented Oct 10, 2019

Opened a PR to add all of the args in the above comment (except --disable-dev-shm-usage) to Chrome: #5310

It doesn't seem like Electron supports passing any of these: https://electronjs.org/docs/api/chrome-command-line-switches

Adding --disable-dev-shm-usage in this commit seems to make the browser sporadically not open: 7247dcf Opened a new issue (with workaround) for that flag specifically: #5336

@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review stage: work in progress labels Oct 10, 2019
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 10, 2019

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

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 23, 2019

Released in 3.5.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stage: needs review The PR code is done & tested, needs review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants