If website overrides Function.prototype.toString then prevent-addEventListener might not works.
Related to - AdguardTeam/AdguardFilters#143847
Steps to reproduce:
- Add this rule:
example.org#%#//scriptlet('prevent-addEventListener', '', 'alert')
- Go to - https://example.org/
- In browser console run:
const nativeToString = Function.prototype.toString;
Function.prototype.toString = function (arg) {
return nativeToString.call(this).includes('alert')
? ""
: nativeToString.call(this);
};
document.documentElement.addEventListener('click', () => {
alert(1);
});
- Click somewhere
Alert should be prevented by prevent-addEventListener rule, but it doesn't work.
We probably could just save reference to Function.prototype.toString and use it in listenerToString
|
export const listenerToString = (listener) => { |
|
return typeof listener === 'function' |
|
? listener.toString() |
|
: listener.handleEvent.toString(); |
|
}; |
Something like:
const nativeToString = Function.prototype.toString;
nativeToString.call(listener);
If website overrides
Function.prototype.toStringthenprevent-addEventListenermight not works.Related to - AdguardTeam/AdguardFilters#143847
Steps to reproduce:
Alert should be prevented by
prevent-addEventListenerrule, but it doesn't work.We probably could just save reference to
Function.prototype.toStringand use it inlistenerToStringScriptlets/src/helpers/add-event-listener-utils.js
Lines 39 to 43 in b1e0bda
Something like: