[GH-ISSUE #882] sharedState should be global and share between scripts #876

Open
opened 2026-03-03 19:22:38 +03:00 by kerem · 1 comment
Owner

Originally created by @NghiaTranUIT on GitHub (May 8, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/882

Originally assigned to: @NghiaTranUIT on GitHub.

Description

At the moment, we can use sharedState to share data from Request and Response in the same script. The data will be wiped out when we run again.

To make it's easier, we should make sharedState becomes a global object and share between scripts.

Acceptance Criteria

  • sharedState is remaining the value from different scripts
  • Update doc
Originally created by @NghiaTranUIT on GitHub (May 8, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/882 Originally assigned to: @NghiaTranUIT on GitHub. ### Description At the moment, we can use `sharedState` to share data from Request and Response in the same script. The data will be wiped out when we run again. To make it's easier, we should make `sharedState` becomes a global object and share between scripts. ### Acceptance Criteria - `sharedState` is remaining the value from different scripts - Update doc
Author
Owner

@NghiaTranUIT commented on GitHub (May 8, 2021):

Done: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.24.0_Global_ShareState_Scripting.dmg

function onRequest(context, url, request) {
  // console.log(request);
  console.log(url);

  // Save all query
  sharedState.queries = request.queries;


  var count = sharedState.count ?? 0;
  count += 1;
  sharedState.count = count;

  // Done
  return request;
}

function onResponse(context, url, request, response) {
  // console.log(response);

  console.log("sharedState.count = " + sharedState.count);

  // Done
  return response;
}

It will increase the counter as soon as we run a script.

<!-- gh-comment-id:835036881 --> @NghiaTranUIT commented on GitHub (May 8, 2021): Done: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.24.0_Global_ShareState_Scripting.dmg ```js function onRequest(context, url, request) { // console.log(request); console.log(url); // Save all query sharedState.queries = request.queries; var count = sharedState.count ?? 0; count += 1; sharedState.count = count; // Done return request; } function onResponse(context, url, request, response) { // console.log(response); console.log("sharedState.count = " + sharedState.count); // Done return response; } ``` It will increase the counter as soon as we run a script.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#876
No description provided.