Support shadow-piercing combinator >>> in trusted-click-element · gorhill/uBlock@941077a (original) (raw)

Original file line number Diff line number Diff line change
@@ -4077,10 +4077,21 @@ function trustedClickElement(
4077 4077 ? ((...args) => { safe.uboLog(...args); })
4078 4078 : (( ) => { });
4079 4079
4080 +const querySelectorEx = (selector, context = document) => {
4081 +const pos = selector.indexOf(' >>> ');
4082 +if ( pos === -1 ) { return context.querySelector(selector); }
4083 +const outside = selector.slice(0, pos).trim();
4084 +const inside = selector.slice(pos + 5).trim();
4085 +const elem = context.querySelector(outside);
4086 +if ( elem === null ) { return null; }
4087 +const shadowRoot = elem.shadowRoot;
4088 +return shadowRoot && querySelectorEx(inside, shadowRoot);
4089 +};
4090 +
4080 4091 const selectorList = selectors.split(/\s*,\s*/)
4081 4092 .filter(s => {
4082 4093 try {
4083 -void document.querySelector(s);
4094 +void querySelectorEx(s);
4084 4095 } catch(_) {
4085 4096 return false;
4086 4097 }
@@ -4154,7 +4165,7 @@ function trustedClickElement(
4154 4165 if ( Date.now() < tnext ) { return next(); }
4155 4166 const selector = selectorList.shift();
4156 4167 if ( selector === undefined ) { return terminate(); }
4157 -const elem = document.querySelector(selector);
4168 +const elem = querySelectorEx(selector);
4158 4169 if ( elem === null ) {
4159 4170 selectorList.unshift(selector);
4160 4171 return next(true);