prevent-listener
The prevent-listener
snippet prevents the addition of event listeners.
You can use prevent-listener
by wrapping EventTarget.prototype.addEventListener
and not allowing listeners to be added for certain event types.
Parameters
Name | Description | Mandatory |
---|---|---|
type | A pattern that matches the type(s) of events you want to prevent. If the string starts and ends with a slash ( | Yes |
handler | A pattern that matches the event handler's declaration. If the string starts and ends with a slash ( | No |
selector | The CSS selector that the event target must match. If the event target is not an HTML element, the event handler is added. | No |
Filter examples
The following table lists examples that use the abort-on-iframe-property-write
snippet:
Filter | Result |
---|---|
prevent-listener click | No event listener will be added for click events. |
prevent-listener click console div | No click event listener will be added on div elements whose handler matches console. For example, these listeners won't be added:
|
prevent-listener click console | No listener will be added for click events whose handler matches console.
For example, these listeners won't be added:
|
Debugging
The following table contains messages you'll find useful during debugging:
Message | When the message occurs | Definition |
---|---|---|
| After wrapping | Displayed after |
| Each time a listener is prevented from being added | This is a group of logs containing detailed information about the event type and its handler. They're displayed each time we prevent a listener from being added. If the optional handler or selector parameter was omitted, the corresponding log(s) will be skipped. |
Last updated