iOS Packet-Capture Scripts for Request and Response Automation
When a simple rewrite is not enough, NetPeek scripts can run JavaScript before requests, after responses, or on a schedule, while constants keep reusable environment URLs, tokens, and other values in one place.
5Scripts
When rules aren't enough, use JavaScript to handle matched requests more flexibly: read/rewrite request & response, gunzip bodies, compute values conditionally. Scripts are scoped by host and run in the tunnel, like rules.
- Tap + in the script list, set a name and scope (host).
- Write your logic in the editor (helpers like
$utilsprovide gzip/gunzip etc.). - Save & enable, then re-send the request to see the effect.
7Constants
Store frequently-used values (a mock JSON, a token, a test URL) as constants and reference them in rules with ${constantId} — change one place, update everywhere.
FAQ
When should I use a script?
Use scripts for branching, combined transformations, or scheduled automation. Prefer rewrite rules for straightforward header, body, or mock changes.
Do scripts run automatically?
A script runs only when that script is enabled and the global Scripts gate is on.
What are constants for?
Constants centralize reusable values such as API endpoints or tokens so rules and scripts can share them.