ProxymanApp / proxyman-windows-linux

Public tracker for Proxyman Windows/Linux
https://proxyman.io/
MIT License
98 stars 4 forks source link

[Scripting] #1 Script List + Script Editor #335

Open NghiaTranUIT opened 9 months ago

NghiaTranUIT commented 9 months ago

Description

It's time to implement the Scripting feature. We're going to break it down into small feasible tickets.

Acceptance Criteria

1. Script List Requirement

1

Screenshot 2023-11-21 at 08 58 57

Menu Action Requirement

NghiaTranUIT commented 9 months ago

2. Scripting Models

/// This func is called if the Request Checkbox is Enabled. You can modify the Request Data here before the request hits to the server
/// e.g. Add/Update/Remove: host, scheme, port, path, headers, queries, comment, color and body (json, form, plain-text, base64 encoded string)
///
/// Use global object `sharedState` to share data between Requests/Response from different scripts (e.g. sharedState.data = "My-Data")
///
async function onRequest(context, url, request) {
  // console.log(request);
  console.log(url);

  // Update or Add new headers
  // request.headers["X-New-Headers"] = "My-Value";

  // Update or Add new queries
  // request.queries["name"] = "Proxyman";

  // Body
  // var body = request.body;
  // body["new-key"] = "new-value"
  // request.body = body;

  // Done
  return request;
}

/// This func is called if the Response Checkbox is Enabled. You can modify the Response Data here before it goes to the client
/// e.g. Add/Update/Remove: headers, statusCode, comment, color and body (json, plain-text, base64 encoded string)
///
async function onResponse(context, url, request, response) {
  // console.log(response);

  // Update or Add new headers
  // response.headers["Content-Type"] = "application/json";

  // Update status Code
  // response.statusCode = 500;

  // Update Body
  // var body = response.body;
  // body["new-key"] = "Proxyman";
  // response.body = body;

  // Or map a local file as a body
  // response.bodyFilePath = "~/Desktop/myfile.json"

  // Done
  return response;
}
NghiaTranUIT commented 9 months ago

3. Script Editor

CleanShot 2023-11-21 at 09 18 54@2x

Behavior

4. Monaco Editor

5. Menu Context

Screenshot 2023-11-21 at 09 21 29

6. Console Log panel