Open
Description
Steps to reproduce:
- Add this rule:
example.org#%#//scriptlet('trusted-suppress-native-method', 'Document.prototype.querySelector', '"h1"', 'prevent', 'testFunc')
- Go to - https://example.org/
- In browser console run:
Code:
const testFunc = () => {
// console.log('testFunc');
const h1 = document.querySelector('h1');
if (h1 === undefined) {
console.log('h1 is undefined, prevented');
return;
}
console.log(h1);
};
testFunc();
const test = () => {
// console.log('test');
const testQuerySelector = document.querySelector('querySelector');
};
test();
const testFunc1 = () => {
// console.log('testFunc1');
const h1 = document.querySelector('h1');
if (h1 === undefined) {
console.log('h1 is undefined, prevented');
return;
}
console.log(h1);
};
testFunc1();
It should print h1 is undefined, prevented
2 times in console, but it looks like that isMatchingSuspended
is not reset when stack is not matched:
Scriptlets/src/scriptlets/trusted-suppress-native-method.ts
Lines 190 to 192 in 3ba245f
so second time is not prevented and element
<h1>Example Domain</h1>
is logged, but it should not be (it works fine when test()
is commented out).
Adding isMatchingSuspended = false;
before return Reflect.apply(target, thisArg, argumentsList);
should fixes it.