forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pass all chromium flags through to Electron (cypress-io#29443)
* fix: pass all chromium flags through to Electron * Add changelog entry * exclude webkit from test for navigator.webdriver being true * add debug log for switches in electron * Fix the unit test so it passes now * Update packages/server/lib/environment.js Co-authored-by: Matt Schile <mschile@cypress.io> * Update packages/server/lib/environment.js Yes 😝 Probably why a better test would be good around this. Co-authored-by: Matt Schile <mschile@cypress.io> * Update packages/server/test/unit/util/chromium_flags_spec.js Co-authored-by: Bill Glesias <bglesias@gmail.com> * lint fix --------- Co-authored-by: Matt Schile <mschile@cypress.io> Co-authored-by: Bill Glesias <bglesias@gmail.com>
- Loading branch information
Showing
7 changed files
with
170 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Chrome, Firefox, and Electron all have navigator.webdriver set to true in Cypress tests. | ||
// TODO: Webkit should have this set, this needs to be fixed https://github.com/cypress-io/cypress/issues/29446 | ||
// https://w3c.github.io/webdriver/#interface | ||
// https://github.com/cypress-io/cypress/issues/27939 | ||
it('visit', { browser: '!webkit' }, () => { | ||
cy.visit('/fixtures/issue-27939.html') | ||
cy.get('#content').should('have.text', 'navigator.webdriver is true') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<html> | ||
|
||
<body> | ||
<h1 id="content"></h1> | ||
<script> | ||
var text = document.createTextNode(`navigator.webdriver is ${!!navigator.webdriver}`); | ||
document.getElementById("content").append(text); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
const disabledFeatures = [ | ||
// Disable manual option and popup prompt of Chrome translation | ||
// https://github.com/cypress-io/cypress/issues/28225 | ||
'Translate', | ||
// Disables "Enhanced ad privacy in Chrome" dialog | ||
// https://github.com/cypress-io/cypress/issues/29199 | ||
'PrivacySandboxSettings4', | ||
] | ||
|
||
// Common Chrome Flags for Automation | ||
// https://github.com/GoogleChrome/chrome-launcher/blob/master/docs/chrome-flags-for-tools.md | ||
const DEFAULT_FLAGS = [ | ||
'test-type', | ||
'ignore-certificate-errors', | ||
'start-maximized', | ||
'silent-debugger-extension-api', | ||
'no-default-browser-check', | ||
'no-first-run', | ||
'noerrdialogs', | ||
'enable-fixed-layout', | ||
'disable-popup-blocking', | ||
'disable-password-generation', | ||
'disable-single-click-autofill', | ||
'disable-prompt-on-repos', | ||
'disable-background-timer-throttling', | ||
'disable-renderer-backgrounding', | ||
'disable-renderer-throttling', | ||
'disable-backgrounding-occluded-windows', | ||
'disable-restore-session-state', | ||
'disable-new-profile-management', | ||
'disable-new-avatar-menu', | ||
'allow-insecure-localhost', | ||
'reduce-security-for-testing', | ||
'enable-automation', | ||
'disable-print-preview', | ||
'disable-component-extensions-with-background-pages', | ||
|
||
'disable-device-discovery-notifications', | ||
|
||
// https://github.com/cypress-io/cypress/issues/2376 | ||
'autoplay-policy=no-user-gesture-required', | ||
|
||
// http://www.chromium.org/Home/chromium-security/site-isolation | ||
// https://github.com/electron/electron/issues/18214 | ||
// https://github.com/cypress-io/cypress/issues/1951 | ||
'disable-site-isolation-trials', | ||
|
||
// the following come from chromedriver | ||
// https://code.google.com/p/chromium/codesearch#chromium/src/chrome/test/chromedriver/chrome_launcher.cc&sq=package:chromium&l=70 | ||
'metrics-recording-only', | ||
'disable-prompt-on-repost', | ||
'disable-hang-monitor', | ||
'disable-sync', | ||
// this flag is causing throttling of XHR callbacks for | ||
// as much as 30 seconds. If you VNC in and open dev tools or | ||
// click on a button, it'll "instantly" work. with this | ||
// option enabled, it will time out some of our tests in circle | ||
// "disable-background-networking" | ||
'disable-web-resources', | ||
'safebrowsing-disable-download-protection', | ||
'disable-client-side-phishing-detection', | ||
'disable-component-update', | ||
// Simulate when chrome needs an update. | ||
// This prevents an 'update' from displaying til the given date | ||
`simulate-outdated-no-au='Tue, 31 Dec 2099 23:59:59 GMT'`, | ||
'disable-default-apps', | ||
|
||
`disable-features=${disabledFeatures.join(',')}`, | ||
|
||
// These flags are for webcam/WebRTC testing | ||
// https://github.com/cypress-io/cypress/issues/2704 | ||
'use-fake-ui-for-media-stream', | ||
'use-fake-device-for-media-stream', | ||
|
||
// prevent navigation throttling when navigating in the browser rapid fire | ||
// https://github.com/cypress-io/cypress/issues/5132 | ||
// https://github.com/cypress-io/cypress/pull/20271 | ||
'disable-ipc-flooding-protection', | ||
|
||
// misc. options puppeteer passes | ||
// https://github.com/cypress-io/cypress/issues/3633 | ||
'disable-backgrounding-occluded-window', | ||
'disable-breakpad', | ||
'password-store=basic', | ||
'use-mock-keychain', | ||
|
||
// write shared memory files into '/tmp' instead of '/dev/shm' | ||
// https://github.com/cypress-io/cypress/issues/5336 | ||
// https://github.com/cypress-io/cypress/issues/15814 | ||
'disable-dev-shm-usage', | ||
|
||
// enable precise memory info so performance.memory returns more accurate values | ||
'enable-precise-memory-info', | ||
] | ||
|
||
// prepend -- to each flag and concatenate them together | ||
export const formatChromeFlags = (flags) => flags.map((flag) => `--${flag}`) | ||
|
||
// create an array of objects with name and value properties | ||
// for each flag, splitting the flag on the first = character | ||
export const formatElectronFlags = (flags) => { | ||
return flags.map((flag) => { | ||
const [name, value] = flag.split('=') | ||
|
||
return value ? { name, value } : { name } | ||
}) | ||
} | ||
|
||
export const DEFAULT_CHROME_FLAGS = formatChromeFlags(DEFAULT_FLAGS) | ||
|
||
export const DEFAULT_ELECTRON_FLAGS = formatElectronFlags(DEFAULT_CHROME_FLAGS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require('../../spec_helper') | ||
|
||
const { formatChromeFlags, formatElectronFlags } = require(`../../../lib/util/chromium_flags`) | ||
|
||
describe('lib/util/chromium_flags', () => { | ||
context('#formatChromeFlags', () => { | ||
it('formats flags with --', () => { | ||
const flags = ['one', 'two', 'three'] | ||
const chromeFlags = formatChromeFlags(flags) | ||
|
||
expect(chromeFlags).to.deep.eq(['--one', '--two', '--three']) | ||
}) | ||
}) | ||
|
||
context('#formatElectronFlags', () => { | ||
it('formats flags as objects with name', () => { | ||
const flags = ['one', 'two', 'three'] | ||
const electronFlags = formatElectronFlags(flags) | ||
|
||
expect(electronFlags).to.deep.eq([{ name: 'one' }, { name: 'two' }, { name: 'three' }]) | ||
}) | ||
|
||
it('formats flags as objects with name/value pairs', () => { | ||
const flags = ['one=1', 'two=2', 'three'] | ||
const electronFlags = formatElectronFlags(flags) | ||
|
||
expect(electronFlags).to.deep.eq([{ name: 'one', value: '1' }, { name: 'two', value: '2' }, { name: 'three' }]) | ||
}) | ||
}) | ||
}) |