1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

Add logging ability to trusted-click-element

If the vararg `, log, 1` is present, the scriptlet will log to
the console it's execution steps. Works only in dev build.
This commit is contained in:
Raymond Hill 2023-10-16 19:53:48 -04:00
parent 5a24fad8ad
commit f122ce7320
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -3896,6 +3896,7 @@ builtinScriptlets.push({
world: 'ISOLATED',
dependencies: [
'run-at-html-element.fn',
'safe-self.fn',
],
});
function trustedClickElement(
@ -3905,6 +3906,12 @@ function trustedClickElement(
) {
if ( extraMatch !== '' ) { return; }
const safe = safeSelf();
const extraArgs = safe.getExtraArgs(Array.from(arguments), 3);
const uboLog = extraArgs.log !== undefined
? ((...args) => { safe.uboLog(...args); })
: (( ) => { });
const selectorList = selectors.split(/\s*,\s*/)
.filter(s => {
try {
@ -3928,15 +3935,22 @@ function trustedClickElement(
};
const next = notFound => {
if ( selectorList.length === 0 ) { return terminate(); }
if ( selectorList.length === 0 ) {
uboLog(`trusted-click-element: Completed`);
return terminate();
}
const tnow = Date.now();
if ( tnow >= tbye ) { return terminate(); }
if ( tnow >= tbye ) {
uboLog(`trusted-click-element: Timed out`);
return terminate();
}
if ( notFound ) { observe(); }
const delay = Math.max(notFound ? tbye - tnow : tnext - tnow, 1);
next.timer = setTimeout(( ) => {
next.timer = undefined;
process();
}, delay);
uboLog(`trusted-click-element: Waiting for ${selectorList[0]}...`);
};
next.stop = ( ) => {
if ( next.timer === undefined ) { return; }
@ -3980,6 +3994,7 @@ function trustedClickElement(
selectorList.unshift(selector);
return next(true);
}
uboLog(`trusted-click-element: Clicked ${selector}`);
elem.click();
tnext += clickDelay;
next();