Environment Variables
Share data between Proxyman request and response scripts with sharedState and manage its lifetime across scripts.
1. Shared State
It's possible to share states from the onRequest() and the onResponse() from different scripts when the script is executed with the global object: sharedState
The sharedState is a JS Object (Dictionary), so you can assign any keys and values from onRequest(), then receive the data on the onResponse() or from different scripts.
The following code demonstrates:
Get the global counter and increase it as soon as the script is executed
Share data between Request and Response
function onRequest(context, url, request) {
// Save some state to sharedState
sharedState.url = url;
sharedState.data = "custom";
sharedState.info = {"username": "Proxyman"};
// Increase the global counter
var count = sharedState.count ?? 0;
count += 1;
sharedState.count = count;
// Log
console.log(sharedState);
return request;
}
function onResponse(context, url, request, response) {
// Receive it
console.log("Custom data = " + sharedState.dataa);
console.log("sharedState.count = " + sharedState.count);
// Done
return response;
}To clear all data, please consider using `clearSharedState` function.
2. Environment Variables
Environment Variables feature is introduced from Proxyman 3.8.0 and later.
Scripts can access system env.
Support bash or zsh.
How to use
Define an env in your
~/.zshrcor~/.bashrc
2. Open any scripts -> More button -> Environment Variables -> Allow all scripts to access env.
3. Reload the ENV to get the env update.

4. Access env from your script with a prefix $
3. Additions
Manually Reload the System Env (Available on Proxyman macOS 4.15.0 or later). Make sure we enable the permission first, in the More Button -> Environment Variables -> Allow all scripts to read env.
Last updated
Was this helpful?