tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 1322860b6d3a6a07156e32f59e97fb38782d53b5
parent ef267bb694d7a63048a125de46218665b93104b6
Author: Alexandru Marc <amarc@mozilla.com>
Date:   Mon, 27 Oct 2025 12:28:57 +0200

Revert (Bug 1996081, Bug 1996037) for causing dt failures @ browser_allocations_browser_console.js

This reverts commit 5faf40439da7e5f4005f4661ebdd78075276b1ab.

Revert "Bug 1996037 - Add the ability to disable webcompat interventions by default in the JSON config, while still being togglable in about:compat; r=denschub,webcompat-reviewers"

This reverts commit ac1828333c2954b693a6e80a65824156d44547da.

Diffstat:
Mbrowser/extensions/webcompat/lib/about_compat_broker.js | 2+-
Mbrowser/extensions/webcompat/lib/interventions.js | 87+++++++++++++++++++------------------------------------------------------------
Mbrowser/extensions/webcompat/manifest.json | 2+-
Mbrowser/extensions/webcompat/tests/browser/browser.toml | 1-
Mbrowser/extensions/webcompat/tests/browser/browser_aboutcompat.js | 3---
Mbrowser/extensions/webcompat/tests/browser/browser_intervention_gating.js | 368-------------------------------------------------------------------------------
Mbrowser/extensions/webcompat/tests/browser/browser_interventions.js | 7+++++--
7 files changed, 28 insertions(+), 442 deletions(-)

diff --git a/browser/extensions/webcompat/lib/about_compat_broker.js b/browser/extensions/webcompat/lib/about_compat_broker.js @@ -84,7 +84,7 @@ class AboutCompatBroker { if (active) { await this._interventions?.disableIntervention(what); } else { - await this._interventions?.enableIntervention(what, true); + await this._interventions?.enableIntervention(what); } break; } diff --git a/browser/extensions/webcompat/lib/interventions.js b/browser/extensions/webcompat/lib/interventions.js @@ -16,8 +16,6 @@ class Interventions { this._readyPromise = new Promise(done => (this._resolveReady = done)); - this._disabledPrefListeners = {}; - this._availableInterventions = this._reformatSourceJSON( availableInterventions ); @@ -98,6 +96,19 @@ class Interventions { }); } + checkOverridePref() { + navigator.locks.request("pref_check_lock", async () => { + const value = await browser.aboutConfigPrefs.getPref(this.OVERRIDE_PREF); + if (value === undefined) { + await browser.aboutConfigPrefs.setPref(this.OVERRIDE_PREF, true); + } else if (value === false) { + await this.unregisterUAOverrides(); + } else { + await this.registerUAOverrides(); + } + }); + } + getAvailableInterventions() { return this._availableInterventions; } @@ -121,14 +132,6 @@ class Interventions { ) { return navigator.locks.request("intervention_lock", async () => { for (const config of whichInterventions) { - const disabling_pref_listener = this._disabledPrefListeners[config.id]; - if (disabling_pref_listener) { - browser.aboutConfigPrefs.onPrefChange.removeListener( - disabling_pref_listener - ); - delete this._disabledPrefListeners[config.id]; - } - await this._disableInterventionNow(config); } @@ -202,39 +205,6 @@ class Interventions { continue; } - config.DISABLING_PREF = `disabled_interventions.${config.id}`; - const disabledPrefListener = () => { - navigator.locks.request("pref_check_lock", async () => { - const value = await browser.aboutConfigPrefs.getPref( - config.DISABLING_PREF - ); - if (value === true) { - await this.disableIntervention(config); - console.debug( - `Webcompat intervention for ${config.label} disabled by pref` - ); - } else { - await this.enableIntervention(config); - console.debug( - `Webcompat intervention for ${config.label} enabled by pref` - ); - } - this._aboutCompatBroker.portsToAboutCompatTabs.broadcast({ - interventionsChanged: - this._aboutCompatBroker.filterInterventions(whichInterventions), - }); - }); - }; - this._disabledPrefListeners[config.id] = disabledPrefListener; - browser.aboutConfigPrefs.onPrefChange.addListener( - disabledPrefListener, - config.DISABLING_PREF - ); - - const disablingPrefValue = await browser.aboutConfigPrefs.getPref( - config.DISABLING_PREF - ); - for (const intervention of config.interventions) { intervention.enabled = false; if (!(await this._check_for_needed_prefs(intervention))) { @@ -249,6 +219,9 @@ class Interventions { ) { continue; } + if (!(await InterventionHelpers.checkPlatformMatches(intervention))) { + continue; + } if ( InterventionHelpers.isMissingCustomFunctions( intervention, @@ -257,17 +230,6 @@ class Interventions { ) { continue; } - if (!(await InterventionHelpers.checkPlatformMatches(intervention))) { - // special case: allow platforms=[] to indicate "disabled by default" - if ( - intervention.platforms && - !intervention.platforms.length && - !intervention.not_platforms - ) { - config.availableOnPlatform = true; - } - continue; - } intervention.enabled = true; config.availableOnPlatform = true; } @@ -276,10 +238,6 @@ class Interventions { skipped.push(config.label); continue; } - if (disablingPrefValue === true) { - skipped.push(config.label); - continue; - } try { await this._enableInterventionNow(config); @@ -306,9 +264,9 @@ class Interventions { resolveReady(); } - async enableIntervention(config, force = false) { + async enableIntervention(config) { return navigator.locks.request("intervention_lock", async () => { - await this._enableInterventionNow(config, force); + await this._enableInterventionNow(config); }); } @@ -318,7 +276,7 @@ class Interventions { }); } - async _enableInterventionNow(config, force = false) { + async _enableInterventionNow(config) { if (config.active) { return; } @@ -333,9 +291,8 @@ class Interventions { .flat() .filter(v => v !== undefined); - let somethingWasEnabled = false; for (const intervention of config.interventions) { - if (!intervention.enabled && !force) { + if (!intervention.enabled) { continue; } @@ -350,8 +307,6 @@ class Interventions { } await this._enableUAOverrides(label, intervention, matches); await this._enableRequestBlocks(label, intervention, blocks); - somethingWasEnabled = true; - intervention.enabled = true; } if (!this._getActiveInterventionById(config.id)) { @@ -370,7 +325,7 @@ class Interventions { } } - config.active = somethingWasEnabled; + config.active = true; } async _disableInterventionNow(_config) { diff --git a/browser/extensions/webcompat/manifest.json b/browser/extensions/webcompat/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Web Compatibility Interventions", "description": "Urgent post-release fixes for web compatibility.", - "version": "146.5.0", + "version": "146.4.0", "browser_specific_settings": { "gecko": { "id": "webcompat@mozilla.org", diff --git a/browser/extensions/webcompat/tests/browser/browser.toml b/browser/extensions/webcompat/tests/browser/browser.toml @@ -11,7 +11,6 @@ support-files = [ "smartblock_embed_test.html", "embed_test.js", ] -prefs = ["extensions.webcompat.disabled_interventions.test6=true","extensions.webcompat.disabled_interventions.test7=false"] ["browser_aboutcompat.js"] skip-if = ["debug"] # disabled until bug 1961939 is fixed. diff --git a/browser/extensions/webcompat/tests/browser/browser_aboutcompat.js b/browser/extensions/webcompat/tests/browser/browser_aboutcompat.js @@ -1,9 +1,6 @@ "use strict"; add_task(async function test_about_compat_loads_properly() { - // wait for all interventions to load before testing (can be quite slow on tsan builds). - await WebCompatExtension.noOngoingInterventionChanges(); - const tab = await BrowserTestUtils.openNewForegroundTab({ gBrowser, opening: "about:compat", diff --git a/browser/extensions/webcompat/tests/browser/browser_intervention_gating.js b/browser/extensions/webcompat/tests/browser/browser_intervention_gating.js @@ -157,371 +157,3 @@ add_task(async function test_min_max_versions() { await WebCompatExtension.disableInterventions(["test2"]); await WebCompatExtension.overrideFirefoxVersion(); }); - -add_task(async function test_disabling_by_default() { - // platforms=[] means disabled by default - const config3 = getConfig("test3", [ - { - platforms: [], - js: ["lib/run.js"], - }, - ]); - // also check that other criteria not matching still disables completely - const config4 = getConfig("test4", [ - { - platforms: [], - not_platforms: ["android", "desktop"], - js: ["lib/shims.js"], - }, - ]); - const configs = await WebCompatExtension.updateInterventions([ - config3, - config4, - ]); - Assert.deepEqual( - configs.map(c => c.active), - [false, false], - "The correct interventions were activated on startup" - ); - Assert.deepEqual( - configs.map(c => c.interventions.map(i => i.enabled)), - [[false], [false]], - "The interventions were not enabled by default" - ); - const reg = await WebCompatExtension.getRegisteredContentScriptsFor(["test"]); - Assert.deepEqual( - reg.map(r => r.js).flat(), - [], - "Content scripts were not registered" - ); - - const tab = await BrowserTestUtils.openNewForegroundTab({ - gBrowser, - opening: "about:compat", - waitForLoad: true, - }); - await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { - is( - content.origin, - "moz-extension://9a310967-e580-48bf-b3e8-4eafebbc122d", - "Expected origin of about:compat" - ); - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test3] [data-l10n-id=label-enable]" - ), - "test3 is correctly shown" - ); - ok( - !content.document.querySelector("#interventions tr[data-id=test4]"), - "test4 is correctly hidden" - ); - - // click enable, confirm it is enabled - content.document - .querySelector( - "#interventions tr[data-id=test3] [data-l10n-id=label-enable]" - ) - .click(); - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test3] [data-l10n-id=label-disable]" - ), - "test3 is correctly enabled on click" - ); - - // now click disable, confirm it is disabled - content.document - .querySelector( - "#interventions tr[data-id=test3] [data-l10n-id=label-disable]" - ) - .click(); - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test3] [data-l10n-id=label-enable]" - ), - "test3 is correctly disabled again on second click" - ); - }); - await BrowserTestUtils.removeTab(tab); - - await WebCompatExtension.disableInterventions(["test3", "test4"]); -}); - -add_task(async function test_individual_interventions_prefs() { - const config5 = getConfig("test5", [ - { - js: ["lib/run.js"], - }, - ]); - // the pref for this one is set to true before app-startup - const config6 = getConfig("test6", [ - { - js: ["lib/shims.js"], - }, - ]); - // the pref for this one is set to false before app-startup - const config7 = getConfig("test7", [ - { - js: ["lib/custom_functions.js"], - }, - ]); - let configs = await WebCompatExtension.updateInterventions([ - config5, - config6, - config7, - ]); - Assert.deepEqual( - configs.map(c => c.active), - [true, false, true], - "The correct interventions were activated on startup" - ); - Assert.deepEqual( - configs.map(c => c.interventions.map(i => i.enabled)), - [[true], [true], [true]], - "The correct interventions were made available on startup" - ); - let reg = await WebCompatExtension.getRegisteredContentScriptsFor(["test"]); - Assert.deepEqual( - reg.map(r => r.js).flat(), - ["lib/run.js", "lib/custom_functions.js"], - "The correct content scripts were registered on startup" - ); - - Services.prefs.setBoolPref( - "extensions.webcompat.disabled_interventions.test5", - true - ); - Services.prefs.setBoolPref( - "extensions.webcompat.disabled_interventions.test6", - false - ); - Services.prefs.setBoolPref( - "extensions.webcompat.disabled_interventions.test7", - true - ); - await WebCompatExtension.noOngoingInterventionChanges(); - configs = await WebCompatExtension.updateInterventions([ - config5, - config6, - config7, - ]); - Assert.deepEqual( - configs.map(c => c.active), - [false, true, false], - "The correct interventions were activated by pref changes" - ); - Assert.deepEqual( - configs.map(c => c.interventions.map(i => i.enabled)), - [[true], [true], [true]], - "The correct interventions were made available by pref changes" - ); - reg = await WebCompatExtension.getRegisteredContentScriptsFor(["test"]); - Assert.deepEqual( - reg.map(r => r.js).flat(), - ["lib/shims.js"], - "The correct content scripts are registered after pref changes" - ); - - Services.prefs.setBoolPref( - "extensions.webcompat.disabled_interventions.test5", - false - ); - Services.prefs.setBoolPref( - "extensions.webcompat.disabled_interventions.test6", - true - ); - Services.prefs.setBoolPref( - "extensions.webcompat.disabled_interventions.test7", - false - ); - await WebCompatExtension.noOngoingInterventionChanges(); - configs = await WebCompatExtension.updateInterventions([ - config5, - config6, - config7, - ]); - Assert.deepEqual( - configs.map(c => c.active), - [true, false, true], - "The correct interventions were activated by pref changes" - ); - Assert.deepEqual( - configs.map(c => c.interventions.map(i => i.enabled)), - [[true], [true], [true]], - "The correct interventions were made available by pref changes" - ); - reg = await WebCompatExtension.getRegisteredContentScriptsFor(["test"]); - Assert.deepEqual( - reg.map(r => r.js).flat(), - ["lib/run.js", "lib/custom_functions.js"], - "The correct content scripts are registered after pref changes" - ); - - const tab = await BrowserTestUtils.openNewForegroundTab({ - gBrowser, - opening: "about:compat", - waitForLoad: true, - }); - await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { - is( - content.origin, - "moz-extension://9a310967-e580-48bf-b3e8-4eafebbc122d", - "Expected origin of about:compat" - ); - - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test5] [data-l10n-id=label-disable]" - ), - "test5 is correctly shown as disabled" - ); - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test6] [data-l10n-id=label-enable]" - ), - "test6 is correctly shown as enabled" - ); - - // click to disable test5 and confirm - content.document - .querySelector( - "#interventions tr[data-id=test5] [data-l10n-id=label-disable]" - ) - .click(); - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test5] [data-l10n-id=label-enable]" - ), - "test5 is correctly disabled" - ); - - // click to enable test6 and confirm - content.document - .querySelector( - "#interventions tr[data-id=test6] [data-l10n-id=label-enable]" - ) - .click(); - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test6] [data-l10n-id=label-disable]" - ), - "test6 is correctly enabled" - ); - - // click to disable test7 and confirm - content.document - .querySelector( - "#interventions tr[data-id=test7] [data-l10n-id=label-disable]" - ) - .click(); - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test5] [data-l10n-id=label-enable]" - ), - "test7 is correctly disabled" - ); - }); - - configs = [ - await WebCompatExtension.getInterventionById("test5"), - await WebCompatExtension.getInterventionById("test6"), - await WebCompatExtension.getInterventionById("test7"), - ]; - Assert.deepEqual( - configs.map(c => c.active), - [false, true, false], - "The correct interventions were activated by about:compat changes" - ); - Assert.deepEqual( - configs.map(c => c.interventions.map(i => i.enabled)), - [[true], [true], [true]], - "The correct interventions were made available by about:compat changes" - ); - reg = await WebCompatExtension.getRegisteredContentScriptsFor(["test"]); - Assert.deepEqual( - reg.map(r => r.js).flat(), - ["lib/shims.js"], - "The correct content scripts are registered after about:compat changes" - ); - - await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { - // click to re-enable test5 and confirm - content.document - .querySelector( - "#interventions tr[data-id=test5] [data-l10n-id=label-enable]" - ) - .click(); - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test5] [data-l10n-id=label-disable]" - ), - "test5 is correctly disabled" - ); - - // click to re-disable test6 and confirm - content.document - .querySelector( - "#interventions tr[data-id=test6] [data-l10n-id=label-disable]" - ) - .click(); - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test6] [data-l10n-id=label-enable]" - ), - "test6 is correctly disabled" - ); - - // click to re-enable test7 and confirm - content.document - .querySelector( - "#interventions tr[data-id=test7] [data-l10n-id=label-enable]" - ) - .click(); - await ContentTaskUtils.waitForCondition( - () => - content.document.querySelector( - "#interventions tr[data-id=test7] [data-l10n-id=label-disable]" - ), - "test7 is correctly disabled" - ); - }); - await BrowserTestUtils.removeTab(tab); - - configs = [ - await WebCompatExtension.getInterventionById("test5"), - await WebCompatExtension.getInterventionById("test6"), - await WebCompatExtension.getInterventionById("test7"), - ]; - Assert.deepEqual( - configs.map(c => c.active), - [true, false, true], - "The correct interventions were activated by about:compat changes" - ); - Assert.deepEqual( - configs.map(c => c.interventions.map(i => i.enabled)), - [[true], [true], [true]], - "The correct interventions were made available by about:compat changes" - ); - reg = await WebCompatExtension.getRegisteredContentScriptsFor(["test"]); - Assert.deepEqual( - reg.map(r => r.js).flat(), - ["lib/run.js", "lib/custom_functions.js"], - "The correct content scripts are registered after about:compat changes" - ); - - await WebCompatExtension.disableInterventions(["test5", "test6", "test7"]); - Services.prefs.clearUserPref( - "extensions.webcompat.disabled_interventions.test5" - ); -}); diff --git a/browser/extensions/webcompat/tests/browser/browser_interventions.js b/browser/extensions/webcompat/tests/browser/browser_interventions.js @@ -54,8 +54,11 @@ function check_valid_array(a, key, id) { if (a === undefined) { return false; } - const valid = Array.isArray(a); - ok(valid, `if defined, ${key} is an array for id ${id}`); + const valid = Array.isArray(a) && a.length; + ok( + valid, + `if defined, ${key} is an array with at least one element for id ${id}` + ); return valid; }