replace-xhr-response

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

search

String or regex pattern run against the stringified XHR response.

Yes

n.a.

replacement

Everything that matches the regex will be replaced with this.

No

empty string

needle

Replacement only happens if needle text is present in the response. Enclose in / for regex.

No

empty string

Filter examples

Filter

Result

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

Removes anything like ads:[any-string] from every response body.

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

Replaces the string in the response body.

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

Replaces only if the response contains "example.com".

Debugging

Message

When

Definition

XMLHttpRequest proxied

After wrapping XMLHttpRequest

XHR calls are intercepted.

Needle found in XHR response

Matching needle found

We will look for the search parameter next.

Needle not found in XHR response

Needle not found

Response will not be modified.

Search * replaced with replacement in XHR response

After replacement

The response was successfully replaced.