Skip to content

Commit 367abb5

Browse files
fix: Add new flags and preferences for Chrome (#32811)
* fix: Add new flags and preferences for Chrome * add back the check * remove some flags * Add changelog entry * updating merging and write test * add tests * clean up mocks * export for mocking * update to async * Update cli/CHANGELOG.md
1 parent 2279857 commit 367abb5

File tree

4 files changed

+522
-11
lines changed

4 files changed

+522
-11
lines changed

cli/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ _Released 10/20/2025 (PENDING)_
99

1010
**Bugfixes:**
1111

12-
- Fixed an issue where grouped command text jumps up and down when expanding and collapsing in the command log. Addressed in [#32757](https://github.com/cypress-io/cypress/pull/32757).
1312
- Fixed an issue where command snapshots were not correctly displayed in Studio. Addressed in [#32808](https://github.com/cypress-io/cypress/pull/32808).
13+
- Chrome's autofill popup is now disabled when filling address and credit card forms during test execution. We also added some other Chrome flags and preferences that are common when automating browsers. Fixes [#25608](https://github.com/cypress-io/cypress/issues/25608). Addressed in [#32811](https://github.com/cypress-io/cypress/pull/32811).
14+
- Fixed an issue where grouped command text jumps up and down when expanding and collapsing in the command log. Addressed in [#32757](https://github.com/cypress-io/cypress/pull/32757).
1415
- Fixed an issue with grouped console prop items having a hard to read blue color in the console log and duplicate `:` characters being displayed. Addressed in [#32776](https://github.com/cypress-io/cypress/pull/32776).
1516
- Added more context to the error message shown when `cy.prompt()` fails to download. Addressed in [#32822](https://github.com/cypress-io/cypress/pull/32822).
1617

packages/server/lib/browsers/chrome.ts

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@ const pathToTheme = extension.getPathToTheme()
4949

5050
let browserCriClient: BrowserCriClient | undefined
5151

52+
// Generates default Chrome preferences that Cypress applies to all Chrome instances
53+
const _getDefaultChromePreferences = (): ChromePreferences => {
54+
return {
55+
default: {
56+
autofill: {
57+
profile_enabled: false, // Disable Chrome's "Save address" pop up
58+
credit_card_enabled: false, // Disable Chrome's "Save card" pop up
59+
},
60+
},
61+
defaultSecure: {},
62+
localState: {
63+
browser: {
64+
// Hide security warnings when potentially dangerous command-line flags are used.
65+
command_line_flag_security_warnings_enabled: false,
66+
// Setting the policy controls the presentation of promotional content,
67+
// including the welcome pages that help users sign in to Google Chrome, set
68+
// Google Chrome as users' default browser, or otherwise inform them of product features.
69+
promotions_enabled: false,
70+
},
71+
},
72+
}
73+
}
74+
5275
/**
5376
* Reads all known preference files (CHROME_PREFERENCE_PATHS) from disk and return
5477
* @param userDir
@@ -78,6 +101,16 @@ const _getChromePreferences = (userDir: string): Bluebird<ChromePreferences> =>
78101
}))
79102
}
80103

104+
// Reads raw preferences from disk and merges them with defaults
105+
const _getChromePreferencesWithDefaults = async (userDir: string): Promise<ChromePreferences> => {
106+
const existingPrefs = await _getChromePreferences(userDir)
107+
108+
// Merge default preferences with existing preferences
109+
const defaultPrefs = module.exports._getDefaultChromePreferences()
110+
111+
return _mergeChromePreferences(defaultPrefs, existingPrefs)
112+
}
113+
81114
const _mergeChromePreferences = (originalPrefs: ChromePreferences, newPrefs: ChromePreferences): ChromePreferences => {
82115
return _.mapValues(CHROME_PREFERENCE_PATHS, (_v, prefPath) => {
83116
const original = _.cloneDeep(originalPrefs[prefPath])
@@ -118,10 +151,16 @@ const _writeChromePreferences = (userDir: string, originalPrefs: ChromePreferenc
118151
const newJson = newPrefs[key]
119152

120153
if (!newJson || _.isEqual(originalJson, newJson)) {
154+
debug('skipping writing preferences for %s: no changes detected', key)
155+
121156
return
122157
}
123158

124-
return fs.outputJson(path.join(userDir, CHROME_PREFERENCE_PATHS[key]), newJson)
159+
const prefPath = path.join(userDir, CHROME_PREFERENCE_PATHS[key])
160+
161+
debug('writing Chrome preferences to %s: %o', prefPath, newJson)
162+
163+
return fs.outputJson(prefPath, newJson)
125164
})
126165
.return()
127166
}
@@ -296,6 +335,10 @@ export = {
296335

297336
_getChromePreferences,
298337

338+
_getChromePreferencesWithDefaults,
339+
340+
_getDefaultChromePreferences,
341+
299342
_mergeChromePreferences,
300343

301344
_writeChromePreferences,
@@ -535,15 +578,15 @@ export = {
535578

536579
const userDir = utils.getProfileDir(browser, isTextTerminal)
537580

538-
const [port, preferences] = await Bluebird.all([
581+
const [port, rawPreferences] = await Bluebird.all([
539582
protocol.getRemoteDebuggingPort(),
540583
_getChromePreferences(userDir),
541584
])
542585

543586
const defaultArgs = this._getArgs(browser, options, port)
544587

545588
const defaultLaunchOptions = utils.getDefaultLaunchOptions({
546-
preferences,
589+
preferences: rawPreferences,
547590
args: defaultArgs,
548591
})
549592

@@ -554,10 +597,16 @@ export = {
554597
utils.executeBeforeBrowserLaunch(browser, defaultLaunchOptions, options),
555598
])
556599

600+
// Merge preferences BEFORE writing them to disk
601+
// Start with defaults merged with raw preferences
602+
let finalPreferences = _mergeChromePreferences(module.exports._getDefaultChromePreferences(), rawPreferences)
603+
557604
if (launchOptions.preferences) {
558-
launchOptions.preferences = _mergeChromePreferences(preferences, launchOptions.preferences as ChromePreferences)
605+
finalPreferences = _mergeChromePreferences(finalPreferences, launchOptions.preferences as ChromePreferences)
559606
}
560607

608+
debug('final Chrome preferences to be written: %o', finalPreferences)
609+
561610
const [extDest] = await Bluebird.all([
562611
this._writeExtension(
563612
browser,
@@ -567,7 +616,8 @@ export = {
567616
_disableRestorePagesPrompt(userDir),
568617
// Chrome adds a lock file to the user data dir. If we are restarting the run and browser, we need to remove it.
569618
fs.unlink(path.join(userDir, 'SingletonLock')).catch(() => {}),
570-
_writeChromePreferences(userDir, preferences, launchOptions.preferences as ChromePreferences),
619+
// Write the final merged preferences BEFORE launching the browser
620+
_writeChromePreferences(userDir, rawPreferences, finalPreferences),
571621
])
572622
// normalize the --load-extensions argument by
573623
// massaging what the user passed into our own

packages/server/lib/util/chromium_flags.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
const disabledFeatures = [
2-
// Disable manual option and popup prompt of Chrome translation
3-
// https://github.com/cypress-io/cypress/issues/28225
4-
'Translate',
2+
// Uncomment to force the deprecation of unload events
3+
// 'DeprecateUnloadByUserAndOrigin',
4+
5+
// Hide toolbar button that opens dialog for controlling media sessions.
6+
'GlobalMediaControls',
7+
8+
// Disables the Interest Feed Content Suggestions,
9+
// which is a feature that shows content suggestions based on the user's interests.
10+
// https://www.google.com/interests/saved
11+
'InterestFeedContentSuggestions',
12+
13+
// Hides the Lens feature in the URL address bar.
14+
'LensOverlay',
15+
16+
// Avoid the startup dialog for _Do you want the application 'Chromium.app' to accept incoming network connections?_.
17+
// Also disables the Chrome Media Router https://chromium.googlesource.com/chromium/src/+/HEAD/docs/media/media_router.md
18+
// which creates background networking activity to discover cast targets. A superset of disabling `DialMediaRouteProvider`.
19+
'MediaRouter',
20+
21+
// Disable the Chrome Optimization Guide https://chromium.googlesource.com/chromium/src/+/HEAD/components/optimization_guide/)
22+
// and networking with its service API
23+
'OptimizationHints',
24+
525
// Disables "Enhanced ad privacy in Chrome" dialog
626
// https://github.com/cypress-io/cypress/issues/29199
727
'PrivacySandboxSettings4',
8-
// Uncomment to force the deprecation of unload events
9-
// 'DeprecateUnloadByUserAndOrigin',
28+
29+
// Disable manual option and popup prompt of Chrome translation
30+
// https://github.com/cypress-io/cypress/issues/28225
31+
'Translate',
1032
]
1133

1234
// Common Chrome Flags for Automation
@@ -20,6 +42,11 @@ const DEFAULT_FLAGS = [
2042
'no-first-run',
2143
'noerrdialogs',
2244
'enable-fixed-layout',
45+
// Disables Domain Reliability Monitoring, which tracks whether the browser has
46+
// difficulty contacting Google-owned sites and uploads reports to Google.
47+
'disable-domain-reliability',
48+
// Disable field trial tests configured in fieldtrial_testing_config.json.
49+
'disable-field-trial-config',
2350
'disable-popup-blocking',
2451
'disable-password-generation',
2552
'disable-single-click-autofill',

0 commit comments

Comments
 (0)