1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-26 04:12:50 +01:00

Improve noeval-if scriptlet

Related feedback:
https://github.com/uBlockOrigin/uBlock-discussions/discussions/841#discussioncomment-9320245
This commit is contained in:
Raymond Hill 2024-05-05 11:46:16 -04:00
parent a351852268
commit 4d8ee35ef7
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -2015,12 +2015,19 @@ function noEvalIf(
) {
if ( typeof needle !== 'string' ) { return; }
const safe = safeSelf();
const logPrefix = safe.makeLogPrefix('noeval-if', needle);
const reNeedle = safe.patternToRegex(needle);
window.eval = new Proxy(window.eval, { // jshint ignore: line
apply: function(target, thisArg, args) {
const a = args[0];
if ( reNeedle.test(a.toString()) ) { return; }
return target.apply(thisArg, args);
const a = String(args[0]);
if ( needle !== '' && reNeedle.test(a) ) {
safe.uboLog(logPrefix, 'Prevented:\n', a);
return;
}
if ( needle === '' || safe.logLevel > 1 ) {
safe.uboLog(logPrefix, 'Not prevented:\n', a);
}
return Reflect.apply(target, thisArg, args);
}
});
}