1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
9 ChromeUtils.defineESModuleGetters(lazy, {
10 Preferences: "resource://gre/modules/Preferences.sys.mjs",
12 Log: "chrome://remote/content/shared/Log.sys.mjs",
15 XPCOMUtils.defineLazyPreferenceGetter(
17 "useRecommendedPrefs",
18 "remote.prefs.recommended",
22 XPCOMUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get());
24 // Ensure we are in the parent process.
25 if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
27 "RecommendedPreferences should only be loaded in the parent process"
31 // ALL CHANGES TO THIS LIST MUST HAVE REVIEW FROM A WEBDRIVER PEER!
33 // Preferences are set for automation on startup, unless
34 // remote.prefs.recommended has been set to false.
36 // Note: Clients do not always use the latest version of the application. As
37 // such backward compatibility has to be ensured at least for the last three
40 // INSTRUCTIONS TO ADD A NEW PREFERENCE
42 // Preferences for remote control and automation can be set from several entry
44 // - remote/shared/RecommendedPreferences.sys.mjs
45 // - remote/test/puppeteer/src/node/FirefoxLauncher.ts
46 // - testing/geckodriver/src/prefs.rs
47 // - testing/marionette/client/marionette_driver/geckoinstance.py
49 // The preferences in `FirefoxLauncher.ts`, `prefs.rs` and `geckoinstance.py`
50 // will be applied before the Application starts, and should typically be used
51 // for preferences which cannot be updated during the lifetime of the Application.
53 // The preferences in `RecommendedPreferences.sys.mjs` are applied after
54 // the Application has started, which means that the application must apply this
55 // change dynamically and behave correctly. Note that you can also define
56 // protocol specific preferences (CDP, WebDriver, ...) which are merged with the
57 // COMMON_PREFERENCES from `RecommendedPreferences.sys.mjs`.
59 // Additionally, users relying on the Marionette Python client (ie. using
60 // geckoinstance.py) set `remote.prefs.recommended = false`. This means that
61 // preferences from `RecommendedPreferences.sys.mjs` are not applied and have to
62 // be added to the list of preferences in that Python file. Note that there are
63 // several lists of preferences, either common or specific to a given application
64 // (Firefox Desktop, Fennec, Thunderbird).
66 // Depending on how users interact with the Remote Agent, they will use different
67 // combinations of preferences. So it's important to update the preferences files
68 // so that all users have the proper preferences.
70 // When adding a new preference, follow this guide to decide where to add it:
71 // - Add the preference to `geckoinstance.py`
72 // - If the preference has to be set before startup:
73 // - Add the preference to `prefs.rs`
74 // - Add the preference `browser-data/firefox.ts` in the puppeteer folder
75 // - Create a PR to upstream the change on `browser-data/firefox.ts` to puppeteer
76 // - Otherwise, if the preference can be set after startup:
77 // - Add the preference to `RecommendedPreferences.sys.mjs`
78 const COMMON_PREFERENCES = new Map([
79 // Make sure Shield doesn't hit the network.
80 ["app.normandy.api_url", ""],
82 // Disable automatically upgrading Firefox
84 // Note: This preference should have already been set by the client when
85 // creating the profile. But if not and to absolutely make sure that updates
86 // of Firefox aren't downloaded and applied, enforce its presence.
87 ["app.update.disabledForTesting", true],
89 // Increase the APZ content response timeout in tests to 1 minute.
90 // This is to accommodate the fact that test environments tends to be
91 // slower than production environments (with the b2g emulator being
92 // the slowest of them all), resulting in the production timeout value
93 // sometimes being exceeded and causing false-positive test failures.
95 // (bug 1176798, bug 1177018, bug 1210465)
96 ["apz.content_response_timeout", 60000],
98 // Don't show the content blocking introduction panel.
99 // We use a larger number than the default 22 to have some buffer
100 // This can be removed once Firefox 69 and 68 ESR and are no longer supported.
101 ["browser.contentblocking.introCount", 99],
103 // Indicate that the download panel has been shown once so that
104 // whichever download test runs first doesn't show the popup
106 ["browser.download.panel.shown", true],
108 // Always display a blank page
109 ["browser.newtabpage.enabled", false],
111 // Background thumbnails in particular cause grief, and disabling
112 // thumbnails in general cannot hurt
113 ["browser.pagethumbnails.capturing_disabled", true],
115 // Disable safebrowsing components.
117 // These should also be set in the profile prior to starting Firefox,
118 // as it is picked up at runtime.
119 ["browser.safebrowsing.blockedURIs.enabled", false],
120 ["browser.safebrowsing.downloads.enabled", false],
121 ["browser.safebrowsing.passwords.enabled", false],
122 ["browser.safebrowsing.malware.enabled", false],
123 ["browser.safebrowsing.phishing.enabled", false],
125 // Disable updates to search engines.
127 // Should be set in profile.
128 ["browser.search.update", false],
130 // Do not restore the last open set of tabs if the browser has crashed
131 ["browser.sessionstore.resume_from_crash", false],
133 // Don't check for the default web browser during startup.
135 // These should also be set in the profile prior to starting Firefox,
136 // as it is picked up at runtime.
137 ["browser.shell.checkDefaultBrowser", false],
139 // Disable session restore infobar
140 ["browser.startup.couldRestoreSession.count", -1],
142 // Do not redirect user when a milstone upgrade of Firefox is detected
143 ["browser.startup.homepage_override.mstone", "ignore"],
145 // Do not close the window when the last tab gets closed
146 ["browser.tabs.closeWindowWithLastTab", false],
148 // Don't unload tabs when available memory is running low
149 ["browser.tabs.unloadOnLowMemory", false],
151 // Do not warn when closing all open tabs
152 ["browser.tabs.warnOnClose", false],
154 // Do not warn when closing all other open tabs
155 ["browser.tabs.warnOnCloseOtherTabs", false],
157 // Do not warn when multiple tabs will be opened
158 ["browser.tabs.warnOnOpen", false],
160 // Don't show the Bookmarks Toolbar on any tab (the above pref that
161 // disables the New Tab Page ends up showing the toolbar on about:blank).
162 ["browser.toolbars.bookmarks.visibility", "never"],
164 // Make sure Topsites doesn't hit the network to retrieve tiles from Contile.
165 ["browser.topsites.contile.enabled", false],
167 // Disable first run splash page on Windows 10
168 ["browser.usedOnWindows10.introURL", ""],
170 // Disable the UI tour.
172 // Should be set in profile.
173 ["browser.uitour.enabled", false],
175 // Turn off Merino suggestions in the location bar so as not to trigger
176 // network connections.
177 ["browser.urlbar.merino.endpointURL", ""],
179 // Turn off search suggestions in the location bar so as not to trigger
180 // network connections.
181 ["browser.urlbar.suggest.searches", false],
183 // Do not warn on quitting Firefox
184 ["browser.warnOnQuit", false],
186 // Do not show datareporting policy notifications which can
187 // interfere with tests
189 "datareporting.healthreport.documentServerURI",
190 "http://%(server)s/dummy/healthreport/",
192 ["datareporting.healthreport.logging.consoleEnabled", false],
193 ["datareporting.healthreport.service.enabled", false],
194 ["datareporting.healthreport.service.firstRun", false],
195 ["datareporting.healthreport.uploadEnabled", false],
196 ["datareporting.policy.dataSubmissionEnabled", false],
197 ["datareporting.policy.dataSubmissionPolicyAccepted", false],
198 ["datareporting.policy.dataSubmissionPolicyBypassNotification", true],
200 // Disable popup-blocker
201 ["dom.disable_open_during_load", false],
203 // Enabling the support for File object creation in the content process
204 ["dom.file.createInChild", true],
206 // Disable the ProcessHangMonitor
207 ["dom.ipc.reportProcessHangs", false],
209 // Disable slow script dialogues
210 ["dom.max_chrome_script_run_time", 0],
211 ["dom.max_script_run_time", 0],
213 // Disable location change rate limitation
214 ["dom.navigation.locationChangeRateLimit.count", 0],
217 ["dom.push.connection.enabled", false],
219 // Screen Orientation API
220 ["dom.screenorientation.allow-lock", true],
222 // Disable dialog abuse if alerts are triggered too quickly.
223 ["dom.successive_dialog_time_limit", 0],
225 // Only load extensions from the application and user profile
226 // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
228 // Should be set in profile.
229 ["extensions.autoDisableScopes", 0],
230 ["extensions.enabledScopes", 5],
232 // Disable metadata caching for installed add-ons by default
233 ["extensions.getAddons.cache.enabled", false],
235 // Disable installing any distribution extensions or add-ons.
236 // Should be set in profile.
237 ["extensions.installDistroAddons", false],
239 // Turn off extension updates so they do not bother tests
240 ["extensions.update.enabled", false],
241 ["extensions.update.notifyUser", false],
243 // Make sure opening about:addons will not hit the network
244 ["extensions.getAddons.discovery.api_url", "data:, "],
246 // Allow the application to have focus even it runs in the background
247 ["focusmanager.testmode", true],
249 // Disable useragent updates
250 ["general.useragent.updates.enabled", false],
252 // Always use network provider for geolocation tests so we bypass the
253 // macOS dialog raised by the corelocation provider
254 ["geo.provider.testing", true],
257 ["geo.wifi.scan", false],
259 // Do not prompt with long usernames or passwords in URLs
260 ["network.http.phishy-userpass-length", 255],
262 // Do not prompt for temporary redirects
263 ["network.http.prompt-temp-redirect", false],
265 // Do not automatically switch between offline and online
266 ["network.manage-offline-status", false],
268 // Make sure SNTP requests do not hit the network
269 ["network.sntp.pools", "%(server)s"],
271 // Privacy and Tracking Protection
272 ["privacy.trackingprotection.enabled", false],
274 // Don't do network connections for mitm priming
275 ["security.certerrors.mitm.priming.enabled", false],
277 // Local documents have access to all other local documents,
278 // including directory listings
279 ["security.fileuri.strict_origin_policy", false],
281 // Tests do not wait for the notification button security delay
282 ["security.notification_enable_delay", 0],
284 // Ensure blocklist updates do not hit the network
285 ["services.settings.server", "http://%(server)s/dummy/blocklist/"],
287 // Do not automatically fill sign-in forms with known usernames and
289 ["signon.autofillForms", false],
291 // Disable password capture, so that tests that include forms are not
292 // influenced by the presence of the persistent doorhanger notification
293 ["signon.rememberSignons", false],
295 // Disable first-run welcome page
296 ["startup.homepage_welcome_url", "about:blank"],
297 ["startup.homepage_welcome_url.additional", ""],
299 // Prevent starting into safe mode after application crashes
300 ["toolkit.startup.max_resumed_crashes", -1],
302 // Disable window occlusion on Windows, which can prevent webdriver commands
303 // such as WebDriver:FindElements from working properly (Bug 1802473).
304 ["widget.windows.window_occlusion_tracking.enabled", false],
307 export const RecommendedPreferences = {
308 alteredPrefs: new Set(),
310 isInitialized: false,
313 * Apply the provided map of preferences.
314 * They will be automatically reset on application shutdown.
316 * @param {Map} preferences
317 * Map of preference key to preference value.
319 applyPreferences(preferences) {
320 if (!lazy.useRecommendedPrefs) {
321 // If remote.prefs.recommended is set to false, do not set any preference
322 // here. Needed for our Firefox CI.
326 // Only apply common recommended preferences on first call to
328 if (!this.isInitialized) {
329 // Merge common preferences and provided preferences in a single map.
330 preferences = new Map([...COMMON_PREFERENCES, ...preferences]);
331 Services.obs.addObserver(this, "quit-application");
332 this.isInitialized = true;
335 for (const [k, v] of preferences) {
336 if (!lazy.Preferences.isSet(k)) {
337 lazy.logger.debug(`Setting recommended pref ${k} to ${v}`);
338 lazy.Preferences.set(k, v);
340 // Keep track all the altered preferences to restore them on
342 this.alteredPrefs.add(k);
347 observe(subject, topic) {
348 if (topic === "quit-application") {
349 Services.obs.removeObserver(this, "quit-application");
350 this.restoreAllPreferences();
355 * Restore all the altered preferences.
357 restoreAllPreferences() {
358 this.restorePreferences(this.alteredPrefs);
359 this.isInitialized = false;
363 * Restore provided preferences.
365 * @param {Map} preferences
366 * Map of preferences that should be restored.
368 restorePreferences(preferences) {
369 for (const k of preferences.keys()) {
370 lazy.logger.debug(`Resetting recommended pref ${k}`);
371 lazy.Preferences.reset(k);
372 this.alteredPrefs.delete(k);