mirror of https://github.com/gorhill/uBlock.git
Improve `trusted-click-element` scriptlet
Use `openOrClosedShadowRoot` to lookup shadow root. Related issue: https://github.com/AdguardTeam/AdguardFilters/issues/178995
This commit is contained in:
parent
e738eaa447
commit
ee67cd6284
|
@ -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 querySelectorEx = (selector, context = document) => {
|
||||||
const pos = selector.indexOf(' >>> ');
|
const pos = selector.indexOf(' >>> ');
|
||||||
if ( pos === -1 ) { return context.querySelector(selector); }
|
if ( pos === -1 ) { return context.querySelector(selector); }
|
||||||
|
@ -4489,7 +4503,7 @@ function trustedClickElement(
|
||||||
const inside = selector.slice(pos + 5).trim();
|
const inside = selector.slice(pos + 5).trim();
|
||||||
const elem = context.querySelector(outside);
|
const elem = context.querySelector(outside);
|
||||||
if ( elem === null ) { return null; }
|
if ( elem === null ) { return null; }
|
||||||
const shadowRoot = elem.shadowRoot;
|
const shadowRoot = getShadowRoot(elem);
|
||||||
return shadowRoot && querySelectorEx(inside, shadowRoot);
|
return shadowRoot && querySelectorEx(inside, shadowRoot);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue