mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Improve prevent-addEventListener scriptlet
Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3360
This commit is contained in:
parent
8a6b12a319
commit
9c26a07b53
1 changed files with 24 additions and 22 deletions
|
|
@ -1281,30 +1281,32 @@ function addEventListenerDefuser(
|
|||
}
|
||||
return matchesBoth;
|
||||
};
|
||||
runAt(( ) => {
|
||||
proxyApplyFn('EventTarget.prototype.addEventListener', function(context) {
|
||||
const { callArgs, thisArg } = context;
|
||||
let t, h;
|
||||
try {
|
||||
t = String(callArgs[0]);
|
||||
if ( typeof callArgs[1] === 'function' ) {
|
||||
h = String(safe.Function_toString(callArgs[1]));
|
||||
} else if ( typeof callArgs[1] === 'object' && callArgs[1] !== null ) {
|
||||
if ( typeof callArgs[1].handleEvent === 'function' ) {
|
||||
h = String(safe.Function_toString(callArgs[1].handleEvent));
|
||||
}
|
||||
} else {
|
||||
h = String(callArgs[1]);
|
||||
const proxyFn = function(context) {
|
||||
const { callArgs, thisArg } = context;
|
||||
let t, h;
|
||||
try {
|
||||
t = String(callArgs[0]);
|
||||
if ( typeof callArgs[1] === 'function' ) {
|
||||
h = String(safe.Function_toString(callArgs[1]));
|
||||
} else if ( typeof callArgs[1] === 'object' && callArgs[1] !== null ) {
|
||||
if ( typeof callArgs[1].handleEvent === 'function' ) {
|
||||
h = String(safe.Function_toString(callArgs[1].handleEvent));
|
||||
}
|
||||
} catch {
|
||||
} else {
|
||||
h = String(callArgs[1]);
|
||||
}
|
||||
if ( type === '' && pattern === '' ) {
|
||||
safe.uboLog(logPrefix, `Called: ${t}\n${h}\n${elementDetails(thisArg)}`);
|
||||
} else if ( shouldPrevent(thisArg, t, h) ) {
|
||||
return safe.uboLog(logPrefix, `Prevented: ${t}\n${h}\n${elementDetails(thisArg)}`);
|
||||
}
|
||||
return context.reflect();
|
||||
});
|
||||
} catch {
|
||||
}
|
||||
if ( type === '' && pattern === '' ) {
|
||||
safe.uboLog(logPrefix, `Called: ${t}\n${h}\n${elementDetails(thisArg)}`);
|
||||
} else if ( shouldPrevent(thisArg, t, h) ) {
|
||||
return safe.uboLog(logPrefix, `Prevented: ${t}\n${h}\n${elementDetails(thisArg)}`);
|
||||
}
|
||||
return context.reflect();
|
||||
};
|
||||
runAt(( ) => {
|
||||
proxyApplyFn('EventTarget.prototype.addEventListener', proxyFn);
|
||||
proxyApplyFn('document.addEventListener', proxyFn);
|
||||
}, extraArgs.runAt);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue