Scripting

When a rule can't express what you need, a script can. elcapture runs JavaScript, Python or Rhai on a matching request, response or WebSocket message. The runtimes are built in; there is nothing to install.

Languages

Hooks

Define the hook for the stage you want; return the (modified) object to continue.

HookReceives & returns
on_request(req){method, url, headers, body}. Return it changed, or return {response: {status, headers, body}} to answer locally without hitting the server.
on_response(res){status, headers, body}. Return it changed.
on_message(msg)A WebSocket frame: {url, outgoing, text or binary}. Return it changed, or {drop: true} to discard it.

Helpers

Available in every language:

HelperDoes
env(name)Read a script environment variable (set in Network → Scripts).
state_get(key) / state_set(key, value)Persist a value between calls.
log(msg)Write to the elcapture log.
http_get(url)Fetch a URL directly (no proxy, 10s).
base64_encode / base64_decodeBase64.
sha256(s), uuid(), now_ms()Hash, a v4 UUID, the current time.
jwt_decode(token)Decode a JWT payload (no signature check).

When it runs

Attach a script to a Script rule and it runs on every request, response or WebSocket frame the rule matches, in order with your other rules — so you can combine a script with a header change or a map in one flow.

For a one-off edit you don't need a script: set a breakpoint and change the request by hand.