tor-browser

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

commit c3503f7d195f367cd0e0826305f4653414c70346
parent 0f032496e6e0d0ee09a0463b7c0e0dcdf8aef0d9
Author: Emma Zuehlcke <emz@mozilla.com>
Date:   Wed,  8 Oct 2025 13:38:22 +0000

Bug 1966696 - Prevent setPointerCapture for SmartBlock embed placeholders. r=webcompat-reviewers,twisniewski

Differential Revision: https://phabricator.services.mozilla.com/D263935

Diffstat:
Mbrowser/extensions/webcompat/lib/smartblock_embeds_helper.js | 31++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/browser/extensions/webcompat/lib/smartblock_embeds_helper.js b/browser/extensions/webcompat/lib/smartblock_embeds_helper.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* globals browser */ +/* globals browser exportFunction */ "use strict"; @@ -156,6 +156,10 @@ const embedHelperLib = (() => { // Create the placeholder inside a shadow dom const placeholderDiv = document.createElement("div"); + // Workaround to make sure clicks reach our placeholder button if the site + // uses pointer capture. See Bug 1966696 for an example. + disableSetPointerCaptureFor(placeholderDiv); + if (isTestShim) { // Tag the div with a class to make it easily detectable FOR THE TEST SHIM ONLY placeholderDiv.classList.add("shimmed-embedded-content"); @@ -255,6 +259,31 @@ const embedHelperLib = (() => { } /** + * Disables the setPointerCapture method for a given element to prevent + * pointer capture issues. + * + * @param {HTMLElement} el - The element to disable setPointerCapture for. + */ + function disableSetPointerCaptureFor(el) { + const pageEl = el.wrappedJSObject; + + Object.defineProperty(pageEl, "setPointerCapture", { + configurable: true, + writable: true, + enumerable: false, + // no-op ONLY for this element + value: exportFunction(function (_pointerId) { + console.warn( + "Blocked setPointerCapture on SmartBlock embed placeholder.", + this, + _pointerId + ); + // swallow + }, window), + }); + } + + /** * Initializes a smartblock embeds shim on the page. * * @param {object} SHIM_INFO - Information about the shim wrapped in an object.