event-override

event-override

The event-override snippet proxies events and event handlers to defuse events or change their attributes. It works by proxying addEventListener and the original Event class with a CustomEvent class.

Parameters

Name

Description

Mandatory

Default

eventType

The type of the event to target (e.g., click, mouseover, someCustomEvent).

Yes

n.a.

mode

Operation mode: trusted (makes isTrusted true), disable (disables the matching event), or rewrite (replaces text inside a string property of the event — see below).

Yes

n.a.

needle

Needle to look for in the event listener function's source — not in the event payload. Enclose in / for regex.

No

''

property

The name of the event property to rewrite, for example data. Ignored outside rewrite mode.

Only in rewrite mode

null

pattern

Regex or literal text matched against the property value. Every match is replaced. Ignored outside rewrite mode.

Only in rewrite mode

null

replacement

The replacement text. Defaults to an empty string, which deletes the matched text. Ignored outside rewrite mode.

No

''

rewrite mode

rewrite adjusts the payload a listener reads off an event instead of suppressing the event entirely — useful when defusing the listener would break the page.

  • Only string values are rewritten. Any other type, and any value that does not match pattern, is passed through untouched.

  • Every match of pattern inside the value is replaced, not just the first. If the replacement produces no change, the original value is returned as-is.

  • Rules are matched by property name, so one filter handles one property. If two rewrite filters target the same property on the same event type, the first registered wins.

  • Both property and pattern are required. If either is missing the snippet logs an error and does nothing.

  • Leave needle empty unless the string you are matching on actually appears in the listener's own source code. It is tested against the listener, not against the payload, so a token that only exists in the event data will never match it.

Filter examples

Filter

Result

event-override click disable

Disables all event listeners for the click event.

event-override someCustomEvent disable

Disables all event listeners for the custom event.

event-override click trusted serveAd

Makes isTrusted true for click events whose listener function matches "serveAd".

event-override message rewrite '' data /"ads":true/ '"ads":false'

For every message listener, rewrites "ads":true to "ads":false inside event.data.

event-override message rewrite '' data /trackingId=[^&]*/

Deletes every trackingId=... match from event.data. replacement is omitted, so matches are removed rather than replaced.

Debugging

Message

When

Definition

rewrite mode requires the property and pattern params.

Right after the snippet fires

mode is rewrite but property or pattern is missing. The rule is not registered and the snippet does nothing.

Initialized event-override snippet

After addEventListener has been wrapped

Calls to addEventListener are now intercepted. Logged once per page, for the first event-override filter.

Wrapping event listener for <<eventType>>

A listener matching the event type and needle was registered

That listener will receive the proxied event. If this never appears, either the event type does not match, the needle does not match the listener source, or the page registered the listener before the snippet ran.

Disabling <<eventType>> event

disable mode, a matching listener was registered

The listener was dropped and never reached the native addEventListener.

Providing trusted value for <<eventType>> event

trusted mode, the listener read isTrusted

The listener asked for isTrusted and got true. Only fires when the property is actually read, so a listener that never checks it produces no log.

Rewriting <<property>> of <<eventType>> event

rewrite mode, the property was read and its value changed

The rewrite happened. If the wrapping message appears but this one never does, the listener either does not read property, the value is not a string, or pattern is not matching.