From ee67cd628440c642c22e2811f0c39ff0c3804d20 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 14 May 2024 11:36:17 -0400 Subject: [PATCH] Improve `trusted-click-element` scriptlet Use `openOrClosedShadowRoot` to lookup shadow root. Related issue: https://github.com/AdguardTeam/AdguardFilters/issues/178995 --- assets/resources/scriptlets.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index d4756a727..46f0e9535 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -4482,6 +4482,20 @@ function trustedClickElement( } } + const getShadowRoot = elem => { + // Firefox + if ( elem.openOrClosedShadowRoot ) { + return elem.openOrClosedShadowRoot; + } + // Chromium + if ( typeof chrome === 'object' ) { + if ( chrome.dom && chrome.dom.openOrClosedShadowRoot ) { + return chrome.dom.openOrClosedShadowRoot(elem); + } + } + return null; + }; + const querySelectorEx = (selector, context = document) => { const pos = selector.indexOf(' >>> '); if ( pos === -1 ) { return context.querySelector(selector); } @@ -4489,7 +4503,7 @@ function trustedClickElement( const inside = selector.slice(pos + 5).trim(); const elem = context.querySelector(outside); if ( elem === null ) { return null; } - const shadowRoot = elem.shadowRoot; + const shadowRoot = getShadowRoot(elem); return shadowRoot && querySelectorEx(inside, shadowRoot); };