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 ChromeUtils.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/packages/browsers/src/browser-data/firefox.ts
46 // - testing/geckodriver/src/prefs.rs
47 // - testing/marionette/client/marionette_driver/geckoinstance.py
49 // The preferences in `firefox.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 // Make sure Topsites doesn't hit the network to retrieve sponsored tiles.
109 ["browser.newtabpage.activity-stream.showSponsoredTopSites", false],
111 // Always display a blank page
112 ["browser.newtabpage.enabled", false],
114 // Background thumbnails in particular cause grief, and disabling
115 // thumbnails in general cannot hurt
116 ["browser.pagethumbnails.capturing_disabled", true],
118 // Disable geolocation ping(#1)
119 ["browser.region.network.url", ""],
121 // Disable safebrowsing components.
123 // These should also be set in the profile prior to starting Firefox,
124 // as it is picked up at runtime.
125 ["browser.safebrowsing.blockedURIs.enabled", false],
126 ["browser.safebrowsing.downloads.enabled", false],
127 ["browser.safebrowsing.malware.enabled", false],
128 ["browser.safebrowsing.phishing.enabled", false],
130 // Disable updates to search engines.
132 // Should be set in profile.
133 ["browser.search.update", false],
135 // Do not restore the last open set of tabs if the browser has crashed
136 ["browser.sessionstore.resume_from_crash", false],
138 // Don't check for the default web browser during startup.
140 // These should also be set in the profile prior to starting Firefox,
141 // as it is picked up at runtime.
142 ["browser.shell.checkDefaultBrowser", false],
144 // Disable session restore infobar
145 ["browser.startup.couldRestoreSession.count", -1],
147 // Do not redirect user when a milstone upgrade of Firefox is detected
148 ["browser.startup.homepage_override.mstone", "ignore"],
150 // Do not close the window when the last tab gets closed
151 ["browser.tabs.closeWindowWithLastTab", 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 // 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 delayed user input event handling
207 ["dom.input_events.security.minNumTicks", 0],
208 ["dom.input_events.security.minTimeElapsedInMS", 0],
210 // Disable the ProcessHangMonitor
211 ["dom.ipc.reportProcessHangs", false],
213 // Disable slow script dialogues
214 ["dom.max_chrome_script_run_time", 0],
215 ["dom.max_script_run_time", 0],
217 // Disable location change rate limitation
218 ["dom.navigation.locationChangeRateLimit.count", 0],
221 ["dom.push.connection.enabled", false],
223 // Screen Orientation API
224 ["dom.screenorientation.allow-lock", true],
226 // Disable dialog abuse if alerts are triggered too quickly.
227 ["dom.successive_dialog_time_limit", 0],
229 // Only load extensions from the application and user profile
230 // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
232 // Should be set in profile.
233 ["extensions.autoDisableScopes", 0],
234 ["extensions.enabledScopes", 5],
236 // Disable metadata caching for installed add-ons by default
237 ["extensions.getAddons.cache.enabled", false],
239 // Disable installing any distribution extensions or add-ons.
240 // Should be set in profile.
241 ["extensions.installDistroAddons", false],
243 // Turn off extension updates so they do not bother tests
244 ["extensions.update.enabled", false],
245 ["extensions.update.notifyUser", false],
247 // Make sure opening about:addons will not hit the network
248 ["extensions.getAddons.discovery.api_url", "data:, "],
250 // Redirect various extension update URLs
252 "extensions.blocklist.detailsURL",
253 "http://%(server)s/extensions-dummy/blocklistDetailsURL",
256 "extensions.blocklist.itemURL",
257 "http://%(server)s/extensions-dummy/blocklistItemURL",
259 ["extensions.hotfix.url", "http://%(server)s/extensions-dummy/hotfixURL"],
261 "extensions.systemAddon.update.url",
262 "http://%(server)s/dummy-system-addons.xml",
265 "extensions.update.background.url",
266 "http://%(server)s/extensions-dummy/updateBackgroundURL",
268 ["extensions.update.url", "http://%(server)s/extensions-dummy/updateURL"],
270 // Make sure opening about: addons won't hit the network
271 ["extensions.getAddons.discovery.api_url", "data:, "],
273 "extensions.getAddons.get.url",
274 "http://%(server)s/extensions-dummy/repositoryGetURL",
277 "extensions.getAddons.search.browseURL",
278 "http://%(server)s/extensions-dummy/repositoryBrowseURL",
281 // Allow the application to have focus even it runs in the background
282 ["focusmanager.testmode", true],
284 // Disable useragent updates
285 ["general.useragent.updates.enabled", false],
287 // Disable geolocation ping(#2)
288 ["geo.provider.network.url", ""],
290 // Always use network provider for geolocation tests so we bypass the
291 // macOS dialog raised by the corelocation provider
292 ["geo.provider.testing", true],
295 ["geo.wifi.scan", false],
297 // Disable Firefox accounts ping
298 ["identity.fxaccounts.auth.uri", "https://{server}/dummy/fxa"],
300 // Disable connectivity service pings
301 ["network.connectivity-service.enabled", false],
303 // Do not prompt with long usernames or passwords in URLs
304 ["network.http.phishy-userpass-length", 255],
306 // Do not prompt for temporary redirects
307 ["network.http.prompt-temp-redirect", false],
309 // Do not automatically switch between offline and online
310 ["network.manage-offline-status", false],
312 // Make sure SNTP requests do not hit the network
313 ["network.sntp.pools", "%(server)s"],
315 // Privacy and Tracking Protection
316 ["privacy.trackingprotection.enabled", false],
318 // Don't do network connections for mitm priming
319 ["security.certerrors.mitm.priming.enabled", false],
321 // Local documents have access to all other local documents,
322 // including directory listings
323 ["security.fileuri.strict_origin_policy", false],
325 // Tests do not wait for the notification button security delay
326 ["security.notification_enable_delay", 0],
328 // Do not download intermediate certificates
329 ["security.remote_settings.intermediates.enabled", false],
331 // Ensure remote settings do not hit the network
332 ["services.settings.server", "data:,#remote-settings-dummy/v1"],
334 // Do not automatically fill sign-in forms with known usernames and
336 ["signon.autofillForms", false],
338 // Disable password capture, so that tests that include forms are not
339 // influenced by the presence of the persistent doorhanger notification
340 ["signon.rememberSignons", false],
342 // Disable first-run welcome page
343 ["startup.homepage_welcome_url", "about:blank"],
344 ["startup.homepage_welcome_url.additional", ""],
346 // Prevent starting into safe mode after application crashes
347 ["toolkit.startup.max_resumed_crashes", -1],
349 // Disable all telemetry pings
350 ["toolkit.telemetry.server", "https://%(server)s/telemetry-dummy/"],
352 // Disable window occlusion on Windows, which can prevent webdriver commands
353 // such as WebDriver:FindElements from working properly (Bug 1802473).
354 ["widget.windows.window_occlusion_tracking.enabled", false],
357 export const RecommendedPreferences = {
358 alteredPrefs: new Set(),
360 isInitialized: false,
363 * Apply the provided map of preferences.
364 * They will be automatically reset on application shutdown.
366 * @param {Map} preferences
367 * Map of preference key to preference value.
369 applyPreferences(preferences) {
370 if (!lazy.useRecommendedPrefs) {
371 // If remote.prefs.recommended is set to false, do not set any preference
372 // here. Needed for our Firefox CI.
376 // Only apply common recommended preferences on first call to
378 if (!this.isInitialized) {
379 // Merge common preferences and provided preferences in a single map.
380 preferences = new Map([...COMMON_PREFERENCES, ...preferences]);
381 Services.obs.addObserver(this, "quit-application");
382 this.isInitialized = true;
385 for (const [k, v] of preferences) {
386 if (!lazy.Preferences.isSet(k)) {
387 lazy.logger.debug(`Setting recommended pref ${k} to ${v}`);
388 lazy.Preferences.set(k, v);
390 // Keep track all the altered preferences to restore them on
392 this.alteredPrefs.add(k);
397 observe(subject, topic) {
398 if (topic === "quit-application") {
399 Services.obs.removeObserver(this, "quit-application");
400 this.restoreAllPreferences();
405 * Restore all the altered preferences.
407 restoreAllPreferences() {
408 this.restorePreferences(this.alteredPrefs);
409 this.isInitialized = false;
413 * Restore provided preferences.
415 * @param {Map} preferences
416 * Map of preferences that should be restored.
418 restorePreferences(preferences) {
419 for (const k of preferences.keys()) {
420 lazy.logger.debug(`Resetting recommended pref ${k}`);
421 lazy.Preferences.reset(k);
422 this.alteredPrefs.delete(k);