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
  • Observations
  • Other resources

Was this helpful?

Edit on GitLab
Export as PDF
  1. Snippets
  2. Conditional Hiding Snippets

hide-if-matches-xpath

Last updated 4 months ago

Was this helpful?

The hide-if-matches-xpath snippet hides specific elements through an XPath 1.0 query string.

You can use the hide-if-matches-xpath snippet to hide an element based on its children or siblings. This snippet also lets you use flexible queries to hide elements.

Parameters

Name
Description
Mandatory

query

The XPath query that targets the element to hide.

Yes

scopeQuery

XPath query that defines the scope of the Mutation Observer. It is crucial for the selector to be as specific as possible to prevent matching an excessive number of nodes. If the scopeQuery fails to find a match, the Mutation Observer will default to being attached to the document.

No

waitUntil

Optional parameter that can be used to delay the running of the snippet until the given state is reached. Accepts: loading, interactive, complete, load or any event name.

No

Filter examples

The following table lists examples that use the hide-if-matches-xpath snippet:

Filter
Result

hide-if-matches-xpath '//*'

Hides all elements.

hide-if-matches-xpath '//*[@id="Ad"]'

Hides the element with the id of Ad.

hide-if-matches-xpath '//*[contains(concat(" ",normalize-space(@class)," ")," ad-container ")]'

Hides all elements with a class named ad-container.

hide-if-matches-xpath '//*[@id="Ad"]' '' complete

Waits until the document state is complete before hiding elements with the id of Ad.

Observations

Always use double-quotes instead of single-quotes inside selectors. While both are valid, eyeo uses single-quotes for enclosing a selector as part of the filter syntax.

Other resources

Getting started with XPath filters
CSS to XPath converter
DevHints XPath cheatsheet