st Desktop Site" mode enabled. The UA for the desktop mode // is set inside Gecko with a simple string replace, so we can use // that as a check, see https://searchfox.org/mozilla-central/rev/89d33e1c3b0a57a9377b4815c2f4b58d933b7c32/mobile/android/chrome/geckoview/GeckoViewSettingsChild.js#23-28 let isMobileWithDesktopMode = override.currentPlatform == "android" && header.value.includes("X11; Linux x86_64"); if (!isMobileWithDesktopMode) { header.value = uaTransformer(header.value); } } } } return { requestHeaders: details.requestHeaders }; }; browser.webRequest.onBeforeSendHeaders.addListener( listener, { urls: matches }, ["blocking", "requestHeaders"] ); const listeners = { onBeforeSendHeaders: listener }; if (blocks) { const blistener = details => { return { cancel: true }; }; browser.webRequest.onBeforeRequest.addListener( blistener, { urls: blocks }, ["blocking"] ); listeners.onBeforeRequest = blistener; } this._activeListeners.set(override, listeners); override.active = true; } onOverrideConfigChanged(override) { // Check whether the override should be hidden from about:compat. override.hidden = override.config.hidden; // Setting the override's permanent pref overrules whether it is hidden. if (override.permanentPrefEnabled !== undefined) { override.hidden = !override.permanentPrefEnabled; } // Also check whether the override should be active. let shouldBeActive = true; // Overrides can be force-deactivated by their permanent preference. if (override.permanentPrefEnabled === false) { shouldBeActive = false; } // Overrides gated behind an experiment the user is not part of do not // have to be activated, unless they are gathering telemetry, or the // user has force-enabled them with their permanent pref. if (override.config.experiment && override.permanentPrefEnabled !== true) { shouldBeActive = false; } if (shouldBeActive) { this.enableOverride(override); } else { this.disableOverride(override); } if (this._overridesEnabled) { this._aboutCompatBroker.portsToAboutCompatTabs.broadcast({ overridesChanged: this._aboutCompatBroker.filterOverrides( this._availableOverrides ), }); } } async registerUAOverrides() { const platformMatches = ["all"]; let platformInfo = await browser.runtime.getPlatformInfo(); platformMatches.push(platformInfo.os == "android" ? "android" : "desktop"); for (const override of this._availableOverrides) { if (platformMatches.includes(override.platform)) { override.availableOnPlatform = true; override.currentPlatform = platformInfo.os; // If there is a specific about:config preference governing // this override, monitor its state. const pref = override.config.permanentPref; override.permanentPrefEnabled = pref && (await browser.aboutConfigPrefs.getPref(pref)); if (pref) { const checkOverridePref = () => { browser.aboutConfigPrefs.getPref(pref).then(value => { override.permanentPrefEnabled = value; this.onOverrideConfigChanged(override); }); }; browser.aboutConfigPrefs.onPrefChange.addListener( checkOverridePref, pref ); } this.onOverrideConfigChanged(override); } } this._overridesEnabled = true; this._aboutCompatBroker.portsToAboutCompatTabs.broadcast({ overridesChanged: this._aboutCompatBroker.filterOverrides( this._availableOverrides ), }); } unregisterUAOverrides() { for (const override of this._availableOverrides) { this.disableOverride(override); } this._overridesEnabled = false; this._aboutCompatBroker.portsToAboutCompatTabs.broadcast({ overridesChanged: false, }); } disableOverride(override) { if (!override.active) { return; } const listeners = this._activeListeners.get(override); for (const [name, listener] of Object.entries(listeners)) { browser.webRequest[name].removeListener(listener); } override.active = false; this._activeListeners.delete(override); } } module.exports = UAOverrides; PK !<‰D>¢ manifest.json{ "manifest_version": 2, "name": "Web Compatibility Interventions", "description": "Urgent post-release fixes for web compatibility.", "version": "27.1.0", "applications": { "gecko": { "id": "webcompat@mozilla.org", "strict_min_version": "59.0b5" } }, "experiment_apis": { "aboutConfigPrefs": { "schema": "experiment-apis/aboutConfigPrefs.json", "parent": { "scopes": ["addon_parent"], "script": "experiment-apis/aboutConfigPrefs.js", "paths": [["aboutConfigPrefs"]] } }, "appConstants": { "schema": "experiment-apis/appConstants.json", "parent": { "scopes": ["addon_parent"], "script": "experiment-apis/appConstants.js", "paths": [["appConstants"]] } }, "aboutPage": { "schema": "about-compat/aboutPage.json", "parent": { "scopes": ["addon_parent"], "script": "about-compat/aboutPage.js", "events": ["startup"] } }, "matchPatterns": { "schema": "experiment-apis/matchPatterns.json", "child": { "scopes": ["addon_child"], "script": "experiment-apis/matchPatterns.js", "paths": [["matchPatterns"]] } }, "systemManufacturer": { "schema": "experiment-apis/systemManufacturer.json", "child": { "scopes": ["addon_child"], "script": "experiment-apis/systemManufacturer.js", "paths": [["systemManufacturer"]] } }, "trackingProtection": { "schema": "experiment-apis/trackingProtection.json", "parent": { "scopes": ["addon_parent"], "script": "experiment-apis/trackingProtection.js", "paths": [["trackingProtection"]] } } }, "content_security_policy": "script-src 'self' 'sha256-MmZkN2QaIHhfRWPZ8TVRjijTn5Ci1iEabtTEWrt9CCo='; default-src 'self'; base-uri moz-extension://*; object-src 'none'", "permissions": [ "tabs", "webNavigation", "webRequest", "webRequestBlocking", "" ], "background": { "scripts": [ "lib/module_shim.js", "lib/messaging_helper.js", "lib/intervention_helpers.js", "lib/ua_helpers.js", "data/injections.js", "data/shims.js", "data/ua_overrides.js", "lib/about_compat_broker.js", "lib/custom_functions.js", "lib/injections.js", "lib/shims.js", "lib/ua_overrides.js", "run.js" ] }, "web_accessible_resources": [ "shims/addthis-angular.js", "shims/adform.js", "shims/adnexus-prebid.js", "shims/adsafeprotected-ima.js", "shims/apstag.js", "shims/bmauth.js", "shims/chartbeat.js", "shims/criteo.js", "shims/cxense.js", "shims/eluminate.js", "shims/empty-script.js", "shims/empty-shim.txt", "shims/facebook-sdk.js", "shims/facebook.svg", "shims/google-ads.js", "shims/google-analytics-and-tag-manager.js", "shims/google-analytics-ecommerce-plugin.js", "shims/google-analytics-legacy.js", "shims/google-ima.js", "shims/google-page-ad.js", "shims/google-publisher-tags.js", "shims/google-safeframe.html", "shims/iaspet.js", "shims/live-test-shim.js", "shims/moat.js", "shims/mochitest-shim-1.js", "shims/mochitest-shim-2.js", "shims/mochitest-shim-3.js", "shims/optimizely.js", "shims/play.svg", "shims/rambler-authenticator.js", "shims/rich-relevance.js", "shims/stackblitz.js", "shims/tracking-pixel.png", "shims/vast2.xml", "shims/vast3.xml", "shims/vidible.js", "shims/vmad.xml" ] } PK !