From 4e3d157780cb4a2fba28cbe808d1762261955997 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Sun, 9 Jul 2023 18:04:37 -0400 Subject: [PATCH] Update options for browsers - Extract common options from ChromeBrowser and ChromiumBrowser - Introduce function `getOptions` - Introduce options to chromium for parity - Add --disable-renderer-backgrounding - Add --disable-device-discovery-notifications - Introduce new options - Introduce options to prevent password dialogs when running tests - Add --password-store=basic. Prevents gnome keyring/kde wallet popup on Linux - Add --use-mock-keychain. Prevents permissions dialog on Mac. - Introduce options to disable interactivity - Add --disable-popup-blocking - Add --disable-notifications - Add --mute-audio - Add --disable-client-side-phishing-detection - Replace removed flags - Replace --disable-translate with --disable-features=Translate --- index.js | 58 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 9404037..aa4ec7b 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,37 @@ function sanitizeJSFlags (flag) { return flag.replace(startExp, '--js-flags=').replace(endExp, '') } +function getOptions (userDataDir, flags, url) { + // These are all the default options + return [ + '--user-data-dir=' + userDataDir, + + // Disable chrome features + // https://github.com/GoogleChrome/chrome-launcher/blob/master/docs/chrome-flags-for-tools.md#--enable-automation + '--enable-automation', + '--no-default-browser-check', + '--no-first-run', + '--disable-client-side-phishing-detection', + '--disable-default-apps', + '--disable-popup-blocking', + '--disable-features=Translate', + '--disable-background-timer-throttling', + '--disable-notifications', + '--mute-audio', + + // Disable password prompt dialogs + // see: https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md#chromium-annoyances + '--password-store=basic', + '--use-mock-keychain', + + // on macOS, disable-background-timer-throttling is not enough + // and we need disable-renderer-backgrounding too + // see https://github.com/karma-runner/karma-chrome-launcher/issues/123 + '--disable-renderer-backgrounding', + '--disable-device-discovery-notifications' + ].concat(flags, [url]) +} + var ChromeBrowser = function (baseBrowserDecorator, args) { baseBrowserDecorator(this) @@ -32,22 +63,7 @@ var ChromeBrowser = function (baseBrowserDecorator, args) { } }) - return [ - '--user-data-dir=' + userDataDir, - // https://github.com/GoogleChrome/chrome-launcher/blob/master/docs/chrome-flags-for-tools.md#--enable-automation - '--enable-automation', - '--no-default-browser-check', - '--no-first-run', - '--disable-default-apps', - '--disable-popup-blocking', - '--disable-translate', - '--disable-background-timer-throttling', - // on macOS, disable-background-timer-throttling is not enough - // and we need disable-renderer-backgrounding too - // see https://github.com/karma-runner/karma-chrome-launcher/issues/123 - '--disable-renderer-backgrounding', - '--disable-device-discovery-notifications' - ].concat(flags, [url]) + return getOptions(userDataDir, flags, url) } } @@ -88,15 +104,7 @@ var ChromiumBrowser = function (baseBrowserDecorator, args) { } }) - return [ - '--user-data-dir=' + userDataDir, - '--no-default-browser-check', - '--no-first-run', - '--disable-default-apps', - '--disable-popup-blocking', - '--disable-translate', - '--disable-background-timer-throttling' - ].concat(flags, [url]) + return getOptions(userDataDir, flags, url) } }