Scripts execute JavaScript in the same tunnel as rewrite rules, scoped by host. Use them for branching, combined transformations, or scheduled work. Prefer rewrite rules for a single header, body, or mock change.
Create a script
- Open Scripts and tap +. Set a name and host scope.
- Choose Before Request, After Response, or a scheduled trigger.
- Write the logic. Helpers such as
$utilsprovide gzip/gunzip. - Save, enable the script, and turn on the global Scripts gate. Resend traffic to verify.
Constants
Store a mock JSON, token, or test URL as a constant and reference it from expert-mode rules with ${constantId}. Changing the constant updates every reference. Simple-mode Mock already assembles the response, so constants matter most when several expert rules share a value.