firefox.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. "use strict";
  2. /**
  3. * Copyright 2023 Google Inc. All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. var __importDefault = (this && this.__importDefault) || function (mod) {
  18. return (mod && mod.__esModule) ? mod : { "default": mod };
  19. };
  20. Object.defineProperty(exports, "__esModule", { value: true });
  21. exports.createProfile = exports.resolveBuildId = exports.relativeExecutablePath = exports.resolveDownloadPath = exports.resolveDownloadUrl = void 0;
  22. const fs_1 = __importDefault(require("fs"));
  23. const path_1 = __importDefault(require("path"));
  24. const httpUtil_js_1 = require("../httpUtil.js");
  25. const types_js_1 = require("./types.js");
  26. function archive(platform, buildId) {
  27. switch (platform) {
  28. case types_js_1.BrowserPlatform.LINUX:
  29. return `firefox-${buildId}.en-US.${platform}-x86_64.tar.bz2`;
  30. case types_js_1.BrowserPlatform.MAC_ARM:
  31. case types_js_1.BrowserPlatform.MAC:
  32. return `firefox-${buildId}.en-US.mac.dmg`;
  33. case types_js_1.BrowserPlatform.WIN32:
  34. case types_js_1.BrowserPlatform.WIN64:
  35. return `firefox-${buildId}.en-US.${platform}.zip`;
  36. }
  37. }
  38. function resolveDownloadUrl(platform, buildId, baseUrl = 'https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central') {
  39. return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
  40. }
  41. exports.resolveDownloadUrl = resolveDownloadUrl;
  42. function resolveDownloadPath(platform, buildId) {
  43. return [archive(platform, buildId)];
  44. }
  45. exports.resolveDownloadPath = resolveDownloadPath;
  46. function relativeExecutablePath(platform, _buildId) {
  47. switch (platform) {
  48. case types_js_1.BrowserPlatform.MAC_ARM:
  49. case types_js_1.BrowserPlatform.MAC:
  50. return path_1.default.join('Firefox Nightly.app', 'Contents', 'MacOS', 'firefox');
  51. case types_js_1.BrowserPlatform.LINUX:
  52. return path_1.default.join('firefox', 'firefox');
  53. case types_js_1.BrowserPlatform.WIN32:
  54. case types_js_1.BrowserPlatform.WIN64:
  55. return path_1.default.join('firefox', 'firefox.exe');
  56. }
  57. }
  58. exports.relativeExecutablePath = relativeExecutablePath;
  59. async function resolveBuildId(channel = 'FIREFOX_NIGHTLY') {
  60. const versions = (await (0, httpUtil_js_1.getJSON)(new URL('https://product-details.mozilla.org/1.0/firefox_versions.json')));
  61. const version = versions[channel];
  62. if (!version) {
  63. throw new Error(`Channel ${channel} is not found.`);
  64. }
  65. return version;
  66. }
  67. exports.resolveBuildId = resolveBuildId;
  68. async function createProfile(options) {
  69. if (!fs_1.default.existsSync(options.path)) {
  70. await fs_1.default.promises.mkdir(options.path, {
  71. recursive: true,
  72. });
  73. }
  74. await writePreferences({
  75. preferences: {
  76. ...defaultProfilePreferences(options.preferences),
  77. ...options.preferences,
  78. },
  79. path: options.path,
  80. });
  81. }
  82. exports.createProfile = createProfile;
  83. function defaultProfilePreferences(extraPrefs) {
  84. const server = 'dummy.test';
  85. const defaultPrefs = {
  86. // Make sure Shield doesn't hit the network.
  87. 'app.normandy.api_url': '',
  88. // Disable Firefox old build background check
  89. 'app.update.checkInstallTime': false,
  90. // Disable automatically upgrading Firefox
  91. 'app.update.disabledForTesting': true,
  92. // Increase the APZ content response timeout to 1 minute
  93. 'apz.content_response_timeout': 60000,
  94. // Prevent various error message on the console
  95. // jest-puppeteer asserts that no error message is emitted by the console
  96. 'browser.contentblocking.features.standard': '-tp,tpPrivate,cookieBehavior0,-cm,-fp',
  97. // Enable the dump function: which sends messages to the system
  98. // console
  99. // https://bugzilla.mozilla.org/show_bug.cgi?id=1543115
  100. 'browser.dom.window.dump.enabled': true,
  101. // Disable topstories
  102. 'browser.newtabpage.activity-stream.feeds.system.topstories': false,
  103. // Always display a blank page
  104. 'browser.newtabpage.enabled': false,
  105. // Background thumbnails in particular cause grief: and disabling
  106. // thumbnails in general cannot hurt
  107. 'browser.pagethumbnails.capturing_disabled': true,
  108. // Disable safebrowsing components.
  109. 'browser.safebrowsing.blockedURIs.enabled': false,
  110. 'browser.safebrowsing.downloads.enabled': false,
  111. 'browser.safebrowsing.malware.enabled': false,
  112. 'browser.safebrowsing.passwords.enabled': false,
  113. 'browser.safebrowsing.phishing.enabled': false,
  114. // Disable updates to search engines.
  115. 'browser.search.update': false,
  116. // Do not restore the last open set of tabs if the browser has crashed
  117. 'browser.sessionstore.resume_from_crash': false,
  118. // Skip check for default browser on startup
  119. 'browser.shell.checkDefaultBrowser': false,
  120. // Disable newtabpage
  121. 'browser.startup.homepage': 'about:blank',
  122. // Do not redirect user when a milstone upgrade of Firefox is detected
  123. 'browser.startup.homepage_override.mstone': 'ignore',
  124. // Start with a blank page about:blank
  125. 'browser.startup.page': 0,
  126. // Do not allow background tabs to be zombified on Android: otherwise for
  127. // tests that open additional tabs: the test harness tab itself might get
  128. // unloaded
  129. 'browser.tabs.disableBackgroundZombification': false,
  130. // Do not warn when closing all other open tabs
  131. 'browser.tabs.warnOnCloseOtherTabs': false,
  132. // Do not warn when multiple tabs will be opened
  133. 'browser.tabs.warnOnOpen': false,
  134. // Disable page translations, which can cause issues with tests.
  135. // See https://bugzilla.mozilla.org/show_bug.cgi?id=1836093.
  136. 'browser.translations.enable': false,
  137. // Disable the UI tour.
  138. 'browser.uitour.enabled': false,
  139. // Turn off search suggestions in the location bar so as not to trigger
  140. // network connections.
  141. 'browser.urlbar.suggest.searches': false,
  142. // Disable first run splash page on Windows 10
  143. 'browser.usedOnWindows10.introURL': '',
  144. // Do not warn on quitting Firefox
  145. 'browser.warnOnQuit': false,
  146. // Defensively disable data reporting systems
  147. 'datareporting.healthreport.documentServerURI': `http://${server}/dummy/healthreport/`,
  148. 'datareporting.healthreport.logging.consoleEnabled': false,
  149. 'datareporting.healthreport.service.enabled': false,
  150. 'datareporting.healthreport.service.firstRun': false,
  151. 'datareporting.healthreport.uploadEnabled': false,
  152. // Do not show datareporting policy notifications which can interfere with tests
  153. 'datareporting.policy.dataSubmissionEnabled': false,
  154. 'datareporting.policy.dataSubmissionPolicyBypassNotification': true,
  155. // DevTools JSONViewer sometimes fails to load dependencies with its require.js.
  156. // This doesn't affect Puppeteer but spams console (Bug 1424372)
  157. 'devtools.jsonview.enabled': false,
  158. // Disable popup-blocker
  159. 'dom.disable_open_during_load': false,
  160. // Enable the support for File object creation in the content process
  161. // Required for |Page.setFileInputFiles| protocol method.
  162. 'dom.file.createInChild': true,
  163. // Disable the ProcessHangMonitor
  164. 'dom.ipc.reportProcessHangs': false,
  165. // Disable slow script dialogues
  166. 'dom.max_chrome_script_run_time': 0,
  167. 'dom.max_script_run_time': 0,
  168. // Only load extensions from the application and user profile
  169. // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
  170. 'extensions.autoDisableScopes': 0,
  171. 'extensions.enabledScopes': 5,
  172. // Disable metadata caching for installed add-ons by default
  173. 'extensions.getAddons.cache.enabled': false,
  174. // Disable installing any distribution extensions or add-ons.
  175. 'extensions.installDistroAddons': false,
  176. // Disabled screenshots extension
  177. 'extensions.screenshots.disabled': true,
  178. // Turn off extension updates so they do not bother tests
  179. 'extensions.update.enabled': false,
  180. // Turn off extension updates so they do not bother tests
  181. 'extensions.update.notifyUser': false,
  182. // Make sure opening about:addons will not hit the network
  183. 'extensions.webservice.discoverURL': `http://${server}/dummy/discoveryURL`,
  184. // Temporarily force disable BFCache in parent (https://bit.ly/bug-1732263)
  185. 'fission.bfcacheInParent': false,
  186. // Force all web content to use a single content process
  187. 'fission.webContentIsolationStrategy': 0,
  188. // Allow the application to have focus even it runs in the background
  189. 'focusmanager.testmode': true,
  190. // Disable useragent updates
  191. 'general.useragent.updates.enabled': false,
  192. // Always use network provider for geolocation tests so we bypass the
  193. // macOS dialog raised by the corelocation provider
  194. 'geo.provider.testing': true,
  195. // Do not scan Wifi
  196. 'geo.wifi.scan': false,
  197. // No hang monitor
  198. 'hangmonitor.timeout': 0,
  199. // Show chrome errors and warnings in the error console
  200. 'javascript.options.showInConsole': true,
  201. // Disable download and usage of OpenH264: and Widevine plugins
  202. 'media.gmp-manager.updateEnabled': false,
  203. // Prevent various error message on the console
  204. // jest-puppeteer asserts that no error message is emitted by the console
  205. 'network.cookie.cookieBehavior': 0,
  206. // Disable experimental feature that is only available in Nightly
  207. 'network.cookie.sameSite.laxByDefault': false,
  208. // Do not prompt for temporary redirects
  209. 'network.http.prompt-temp-redirect': false,
  210. // Disable speculative connections so they are not reported as leaking
  211. // when they are hanging around
  212. 'network.http.speculative-parallel-limit': 0,
  213. // Do not automatically switch between offline and online
  214. 'network.manage-offline-status': false,
  215. // Make sure SNTP requests do not hit the network
  216. 'network.sntp.pools': server,
  217. // Disable Flash.
  218. 'plugin.state.flash': 0,
  219. 'privacy.trackingprotection.enabled': false,
  220. // Can be removed once Firefox 89 is no longer supported
  221. // https://bugzilla.mozilla.org/show_bug.cgi?id=1710839
  222. 'remote.enabled': true,
  223. // Don't do network connections for mitm priming
  224. 'security.certerrors.mitm.priming.enabled': false,
  225. // Local documents have access to all other local documents,
  226. // including directory listings
  227. 'security.fileuri.strict_origin_policy': false,
  228. // Do not wait for the notification button security delay
  229. 'security.notification_enable_delay': 0,
  230. // Ensure blocklist updates do not hit the network
  231. 'services.settings.server': `http://${server}/dummy/blocklist/`,
  232. // Do not automatically fill sign-in forms with known usernames and
  233. // passwords
  234. 'signon.autofillForms': false,
  235. // Disable password capture, so that tests that include forms are not
  236. // influenced by the presence of the persistent doorhanger notification
  237. 'signon.rememberSignons': false,
  238. // Disable first-run welcome page
  239. 'startup.homepage_welcome_url': 'about:blank',
  240. // Disable first-run welcome page
  241. 'startup.homepage_welcome_url.additional': '',
  242. // Disable browser animations (tabs, fullscreen, sliding alerts)
  243. 'toolkit.cosmeticAnimations.enabled': false,
  244. // Prevent starting into safe mode after application crashes
  245. 'toolkit.startup.max_resumed_crashes': -1,
  246. };
  247. return Object.assign(defaultPrefs, extraPrefs);
  248. }
  249. /**
  250. * Populates the user.js file with custom preferences as needed to allow
  251. * Firefox's CDP support to properly function. These preferences will be
  252. * automatically copied over to prefs.js during startup of Firefox. To be
  253. * able to restore the original values of preferences a backup of prefs.js
  254. * will be created.
  255. *
  256. * @param prefs - List of preferences to add.
  257. * @param profilePath - Firefox profile to write the preferences to.
  258. */
  259. async function writePreferences(options) {
  260. const lines = Object.entries(options.preferences).map(([key, value]) => {
  261. return `user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`;
  262. });
  263. await fs_1.default.promises.writeFile(path_1.default.join(options.path, 'user.js'), lines.join('\n'));
  264. // Create a backup of the preferences file if it already exitsts.
  265. const prefsPath = path_1.default.join(options.path, 'prefs.js');
  266. if (fs_1.default.existsSync(prefsPath)) {
  267. const prefsBackupPath = path_1.default.join(options.path, 'prefs.js.puppeteer');
  268. await fs_1.default.promises.copyFile(prefsPath, prefsBackupPath);
  269. }
  270. }
  271. //# sourceMappingURL=firefox.js.map