Skip to content

Fix 'trusted-click-element' — throws error when trying to set 'cancelBubble' #555

@AdamWr

Description

@AdamWr

Related to - AdguardTeam/AdguardFilters#228144

Steps to reproduce:

  1. Ensure that scriptlets library v2.2.16 or newer is used
  2. Add to user rules:
example.org#%#//scriptlet('trusted-click-element', '#whatever_test')
  1. Navigate to - https://example.org/
  2. Run in console:
document.body.addEventListener('click', (event) => {
    event.cancelBubble = true;
    alert('Clicked');
});

document.body.click();

Alert should be displayed, but it throws error: Uncaught TypeError: Illegal invocation.

Screenshot Image

It seems that adding:

set(target, property, value) {
    return Reflect.set(target, property, value);
}

here:

const proxied = new Proxy(event, {
get(target, prop) {
if (prop === 'isTrusted') {
return true;
}
const val = Reflect.get(target, prop);
if (typeof val === 'function') {
return val.bind(target);
}
return val;
},

fixes it.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions