Environment Variables

1. Shared State

This feature is only available on macOS 10.15+. Prior to macOS 10.15, it might be crashed.
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 receiving it on the onResponse() or from different script.
The following code demonstrates:
  • Get the global counter and increase it as soon as the script is executed
  • Share data between Request and Response
1
function onRequest(context, url, request) {
2
3
// Save some state to sharedState
4
sharedState.url = url;
5
sharedState.data = "custom";
6
sharedState.info = {"username": "Proxyman"};
7
8
// Increase the global counter
9
var count = sharedState.count ?? 0;
10
count += 1;
11
sharedState.count = count;
12
13
// Log
14
console.log(sharedState);
15
return request;
16
}
17
18
function onResponse(context, url, request, response) {
19
20
// Receive it
21
console.log("Custom data = " + sharedState.dataa);
22
console.log("sharedState.count = " + sharedState.count);
23
24
// Done
25
return response;
26
}
Copied!
From Proxyman 2.25.0+, the sharedState is available across different scripts. It is only released when quitting Proxyman app or using `clearSharedState()` function.
Prior to Proxyman 2.24.0, the sharedState is only alive on the current flow that executes the script and it's released when the script is run over.
To clear all data, please consider using `clearSharedState` function.
1
// Clear all data from sharedState object
2
clearSharedState();
Copied!

2. Environment Variables

Plan to support soon.
Last modified 6mo ago