Skip to content

Instantly share code, notes, and snippets.

@jakeayy
Created December 31, 2025 21:25
Show Gist options
  • Select an option

  • Save jakeayy/672dff2d9b7e1b1d58b117d4d99bb3d6 to your computer and use it in GitHub Desktop.

Select an option

Save jakeayy/672dff2d9b7e1b1d58b117d4d99bb3d6 to your computer and use it in GitHub Desktop.
JS hack with Proxy that overrides isTrusted's state in Element events to true
Element.prototype.addEventListener = new Proxy(
Element.prototype.addEventListener,
{
apply(target, props, args) {
const h = args[1];
args[1] = (ev) =>
h(
new Proxy(ev, {
get: (target, p) => p === "isTrusted" || target[p],
}),
);
return Reflect.apply(target, props, args);
},
},
);
@jakeayy
Copy link
Author

jakeayy commented Dec 31, 2025

It's a POC. It most likely breaks removeEventListener so you need to write your own code for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment