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 `FirefoxLauncher.ts`
75 // - Create a PR to upstream the change on `FirefoxLauncher.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 // Do not allow background tabs to be zombified on Android, otherwise for
149 // tests that open additional tabs, the test harness tab itself might get
151 ["browser.tabs.disableBackgroundZombification", false],
153 // Don't unload tabs when available memory is running low
154 ["browser.tabs.unloadOnLowMemory", false],
156 // Do not warn when closing all open tabs
157 ["browser.tabs.warnOnClose", false],
159 // Do not warn when closing all other open tabs
160 ["browser.tabs.warnOnCloseOtherTabs", false],
162 // Do not warn when multiple tabs will be opened
163 ["browser.tabs.warnOnOpen", false],
165 // Don't show the Bookmarks Toolbar on any tab (the above pref that
166 // disables the New Tab Page ends up showing the toolbar on about:blank).
167 ["browser.toolbars.bookmarks.visibility", "never"],
169 // Make sure Topsites doesn't hit the network to retrieve tiles from Contile.
170 ["browser.topsites.contile.enabled", false],
172 // Disable first run splash page on Windows 10
173 ["browser.usedOnWindows10.introURL", ""],
175 // Disable the UI tour.
177 // Should be set in profile.
178 ["browser.uitour.enabled", false],
180 // Turn off Merino suggestions in the location bar so as not to trigger
181 // network connections.
182 ["browser.urlbar.merino.endpointURL", ""],
184 // Turn off search suggestions in the location bar so as not to trigger
185 // network connections.
186 ["browser.urlbar.suggest.searches", false],
188 // Do not warn on quitting Firefox
189 ["browser.warnOnQuit", false],
191 // Do not show datareporting policy notifications which can
192 // interfere with tests
194 "datareporting.healthreport.documentServerURI",
195 "http://%(server)s/dummy/healthreport/",
197 ["datareporting.healthreport.logging.consoleEnabled", false],
198 ["datareporting.healthreport.service.enabled", false],
199 ["datareporting.healthreport.service.firstRun", false],
200 ["datareporting.healthreport.uploadEnabled", false],
201 ["datareporting.policy.dataSubmissionEnabled", false],
202 ["datareporting.policy.dataSubmissionPolicyAccepted", false],
203 ["datareporting.policy.dataSubmissionPolicyBypassNotification", true],
205 // Disable popup-blocker
206 ["dom.disable_open_during_load", false],
208 // Enabling the support for File object creation in the content process
209 ["dom.file.createInChild", true],
211 // Disable the ProcessHangMonitor
212 ["dom.ipc.reportProcessHangs", false],
214 // Disable slow script dialogues
215 ["dom.max_chrome_script_run_time", 0],
216 ["dom.max_script_run_time", 0],
218 // Disable location change rate limitation
219 ["dom.navigation.locationChangeRateLimit.count", 0],
222 ["dom.push.connection.enabled", false],
224 // Screen Orientation API
225 ["dom.screenorientation.allow-lock", true],
227 // Disable dialog abuse if alerts are triggered too quickly.
228 ["dom.successive_dialog_time_limit", 0],
230 // Only load extensions from the application and user profile
231 // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
233 // Should be set in profile.
234 ["extensions.autoDisableScopes", 0],
235 ["extensions.enabledScopes", 5],
237 // Disable metadata caching for installed add-ons by default
238 ["extensions.getAddons.cache.enabled", false],
240 // Disable installing any distribution extensions or add-ons.
241 // Should be set in profile.
242 ["extensions.installDistroAddons", false],
244 // Turn off extension updates so they do not bother tests
245 ["extensions.update.enabled", false],
246 ["extensions.update.notifyUser", false],
248 // Make sure opening about:addons will not hit the network
249 ["extensions.getAddons.discovery.api_url", "data:, "],
251 // Allow the application to have focus even it runs in the background
252 ["focusmanager.testmode", true],
254 // Disable useragent updates
255 ["general.useragent.updates.enabled", false],
257 // Always use network provider for geolocation tests so we bypass the
258 // macOS dialog raised by the corelocation provider
259 ["geo.provider.testing", true],
262 ["geo.wifi.scan", false],
264 // Do not prompt with long usernames or passwords in URLs
265 ["network.http.phishy-userpass-length", 255],
267 // Do not prompt for temporary redirects
268 ["network.http.prompt-temp-redirect", false],
270 // Do not automatically switch between offline and online
271 ["network.manage-offline-status", false],
273 // Make sure SNTP requests do not hit the network
274 ["network.sntp.pools", "%(server)s"],
276 // Privacy and Tracking Protection
277 ["privacy.trackingprotection.enabled", false],
279 // Don't do network connections for mitm priming
280 ["security.certerrors.mitm.priming.enabled", false],
282 // Local documents have access to all other local documents,
283 // including directory listings
284 ["security.fileuri.strict_origin_policy", false],
286 // Tests do not wait for the notification button security delay
287 ["security.notification_enable_delay", 0],
289 // Ensure blocklist updates do not hit the network
290 ["services.settings.server", "http://%(server)s/dummy/blocklist/"],
292 // Do not automatically fill sign-in forms with known usernames and
294 ["signon.autofillForms", false],
296 // Disable password capture, so that tests that include forms are not
297 // influenced by the presence of the persistent doorhanger notification
298 ["signon.rememberSignons", false],
300 // Disable first-run welcome page
301 ["startup.homepage_welcome_url", "about:blank"],
302 ["startup.homepage_welcome_url.additional", ""],
304 // Prevent starting into safe mode after application crashes
305 ["toolkit.startup.max_resumed_crashes", -1],
307 // Disable window occlusion on Windows, which can prevent webdriver commands
308 // such as WebDriver:FindElements from working properly (Bug 1802473).
309 ["widget.windows.window_occlusion_tracking.enabled", false],
312 export const RecommendedPreferences = {
313 alteredPrefs: new Set(),
315 isInitialized: false,
318 * Apply the provided map of preferences.
319 * They will be automatically reset on application shutdown.
321 * @param {Map} preferences
322 * Map of preference key to preference value.
324 applyPreferences(preferences) {
325 if (!lazy.useRecommendedPrefs) {
326 // If remote.prefs.recommended is set to false, do not set any preference
327 // here. Needed for our Firefox CI.
331 // Only apply common recommended preferences on first call to
333 if (!this.isInitialized) {
334 // Merge common preferences and provided preferences in a single map.
335 preferences = new Map([...COMMON_PREFERENCES, ...preferences]);
336 Services.obs.addObserver(this, "quit-application");
337 this.isInitialized = true;
340 for (const [k, v] of preferences) {
341 if (!lazy.Preferences.isSet(k)) {
342 lazy.logger.debug(`Setting recommended pref ${k} to ${v}`);
343 lazy.Preferences.set(k, v);
345 // Keep track all the altered preferences to restore them on
347 this.alteredPrefs.add(k);
352 observe(subject, topic) {
353 if (topic === "quit-application") {
354 Services.obs.removeObserver(this, "quit-application");
355 this.restoreAllPreferences();
360 * Restore all the altered preferences.
362 restoreAllPreferences() {
363 this.restorePreferences(this.alteredPrefs);
364 this.isInitialized = false;
368 * Restore provided preferences.
370 * @param {Map} preferences
371 * Map of preferences that should be restored.
373 restorePreferences(preferences) {
374 for (const k of preferences.keys()) {
375 lazy.logger.debug(`Resetting recommended pref ${k}`);
376 lazy.Preferences.reset(k);
377 this.alteredPrefs.delete(k);