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

replace-xhr-response

The replace-xhr-response snippet replaces the response of a XHR request if the response text matches a given regular expression pattern.

Parameters

Name
Description
Mandatory
Default value

search

String or regex pattern that will be run against the stringified XHR response. Everything that matches the regex will be replaced with the replacement value.

Yes

n.a.

replacement

Everything that matches the regex will be replaced with the replacement value. By default this will be an empty string, so everything that matches the regex will be removed from the XHR response.

No

empty string

needle

The replacement will only happen if the needle text is present in the response. By default this is an empty string. If the string begins and ends with a slash ( / ), the text in between is treated as a regular expression.

No

empty string

Filter examples

Filter
Result

replace-xhr-response '/ads:\\[(.*?)\\]/'

Will remove anything that looks like ads:[any-string] from every response body.

replace-xhr-response 'serve-ads:true' 'serve-ads:false'

Will replace the string serve-ads:true to serve-ads:false in the response body.

replace-xhr-response 'serve-ads:true' 'serve-ads:false' example.com

Will replace the string serve-ads:true to serve-ads:false in the response body only if the response contains "http://example.com"

Debugging

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

Message
When the message occurs
Definition

XMLHttpRequest proxied

After we have wrapped the XMLHttpRequest object.

From this moment on XMLHttpRequests are intercepted by us.

Needle found in XHR response [original XHR response body]

A matching needle has been found in the response.

Needle found, we will look for the search parameter next.

Needle not found in XHR response [original XHR response body]

Needle not found in the response.

We will not modify this response.

Search * replaced with replacement in XHR response FILTER: replace-xhr-response param [replaced XHR response body]

The search parameter has been found and the response has been replaced with the replacement string.

This is a group of logs containing the filter that successfully replaced the XHR response (the parameters will be individually wrapped in single quotes) and the replaced response.

Last updated 2 months ago

Was this helpful?