LogoLogo
About GitLabAcceptable Ads
  • Getting Started
  • Browser Ad-Filtering Solution
    • Features
    • Getting Started
      • Quickstart
      • Integrate the Solution
      • Set up user counting
    • Guides
      • User counting
      • Configure Solution settings
      • Run separate instances of the filtering engine
      • Update the Solution
      • Understand the snippets library
      • Create a filter list
      • Testing
    • Advanced
      • Services and classes
      • Sitekey
      • ADRs
      • Frame hierarchy
  • Snippets
    • Snippets Overview
    • Behavioral Snippets
      • abort-current-inline-script
      • abort-on-property-read
      • abort-on-property-write
      • abort-on-iframe-property-read
      • abort-on-iframe-property-write
      • array-override
      • cookie-remover
      • freeze-element
      • json-override
      • json-prune
      • override-property-read
      • prevent-listener
      • replace-fetch-response
      • replace-xhr-response
      • simulate-mouse-event
      • skip-video
      • strip-fetch-query-parameter
    • Conditional Hiding Snippets
      • hide-if-canvas-contains
      • hide-if-contains
      • hide-if-contains-image
      • hide-if-contains-similar-text
      • hide-if-contains-visible-text
      • hide-if-contains-and-matches-style
      • hide-if-has-and-matches-style
      • hide-if-labelled-by
      • hide-if-matches-computed-xpath
      • hide-if-matches-xpath
      • hide-if-matches-xpath3
      • hide-if-shadow-contains
    • Debugging Snippets
      • debug
      • log
      • profile
      • trace
    • Performance Snippets
      • race
    • Snippets Support by Platform
    • Node Highlighting
    • Accessing shadow DOM elements
  • Working with filters
  • DATA AND PRIVACY
    • Data collection at eyeo
Powered by GitBook
On this page
  • Parameters
  • Filter examples
  • Debugging

Was this helpful?

Edit on GitLab
Export as PDF
  1. Snippets
  2. Behavioral Snippets

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 (/), the text in between is treated as a regular expression.

Yes

handler

A pattern that matches the event handler's declaration. If the string starts and ends with a slash (/), the text in between is treated as a regular expression.

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: window.addEventListener("click", ()=>console.log("click")) document.body.addEventListener("click", ()=>console.log("click")) But this listener would be added: omeDiv.addEventListener("click", ()=>console.log("click"))

prevent-listener click console

No listener will be added for click events whose handler matches console. For example, these listeners won't be added: someElement.addEventListener("click", () => console.log("click")) But these listeners would be added: someElement.addEventListener("click", () => alert("click"))

Debugging

The following table contains messages you'll find useful during debugging:

Message
When the message occurs
Definition

DEBUG [prevent] Wrapped addEventListener

After wrapping

Displayed after addEventListener has been wrapped.

DEBUG [prevent] was successful DEBUG [prevent] type: actualType matching providedType DEBUG [prevent]handler: actualHandler DEBUG [prevent] matching providedHandler DEBUG [prevent] on element actualElement matching selector DEBUG [prevent] was prevented from being added

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 2 years ago

Was this helpful?