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
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
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:
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
Was this helpful?