Custom scripts
Trace includes a JavaScript-based scripting engine to modify requests and responses on the fly.
What scripts can do
- Rewrite URLs or headers
- Transform request or response bodies
- Mock dynamic responses
- Apply logic that is hard to express with simple rules
Script types
- Request scripts: run before the request is sent
- Response scripts: run after the response is received
- Both: run on both phases
Execution model
- Scripts run inside Trace on-device.
- A script can inspect or modify headers, bodies, and metadata.
- If a script fails, Trace logs the error and continues with the original request.
When to use scripts
- You need conditional logic (if/else) instead of static rules
- You need to compute a response body dynamically
- You want to prototype backend changes without deploying
Tips
- Keep scripts small and focused for easier debugging.
- Prefer rewrite rules for simple header or URL changes.
- Export scripts to share them with teammates.
Debugging scripts
- Start with a narrow filter so you see only the requests your script touches.
- Add temporary logging in the script to validate inputs and outputs.
- Disable scripts one by one if you see unexpected behavior.