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. If the value starts with |
Yes |
n.a. |
|
replacement |
Everything that matches the regex will be replaced with this. In JSONPath mode it is interpreted as a typed value instead of literal text. |
No |
empty string |
|
needle |
Replacement only happens if needle text is present in the response. Enclose in |
No |
empty string |
JSONPath mode
When search starts with jsonpath(, the response is parsed as JSON, the query is evaluated against it, every matching property is replaced, and the result is re-serialised. Use this when the value to change is a structured field rather than a text pattern — it avoids regex-matching a serialised payload, and lets you inject a real boolean or empty array instead of a string.
If the response is not valid JSON, or the query fails to evaluate, the rule is skipped and the response is left unchanged.
-
For the supported query syntax, see JSONPath evaluator.
-
For the values
replacementaccepts in this mode, see the value table on override-property-read.
Filter examples
|
Filter |
Result |
|---|---|
|
|
Removes anything like |
|
|
Replaces the string in the response body. |
|
|
Replaces only if the response contains "example.com". |
|
|
JSONPath mode. Sets |
|
|
Sets every |
|
|
Replaces the |
Debugging
|
Message |
When |
Definition |
|---|---|---|
|
|
After wrapping XMLHttpRequest |
XHR calls are intercepted. |
|
|
Matching needle found |
We will look for the search parameter next. |
|
|
Needle not found |
Response will not be modified. |
|
|
After replacement |
The response was successfully replaced. |
|
|
Right after the snippet fires |
The query could not be compiled, so the rule is not registered. |
|
|
JSONPath mode, per matched property |
A property matched the query and was replaced. One message per match. |
|
|
Response could not be handled |
The response was not valid JSON, or the query threw. The response is left untouched. |