Cypress: Add additional flags when running Chrome

Created on 3 Mar 2019  路  9Comments  路  Source: cypress-io/cypress

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.

Most helpful comment

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.

All 9 comments

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

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.

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.

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

https://github.com/electron/electron/issues/4491

So that isn't fun...

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:

  • --disable-background-networking caused issues: #1320
  • --disable-component-extensions-with-background-pages seems like a performance optimization, unlikely to improve test reliability
  • --disable-extensions, --disable-features

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 (#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.

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: 7247dcfa78ad3e1d0ad032474e724a083007edda Opened a new issue (with workaround) for that flag specifically: #5336

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.

Released in 3.5.0.

Was this page helpful?
0 / 5 - 0 ratings