[GH-ISSUE #557] Scripting Feature #555

Open
opened 2026-03-03 19:19:48 +03:00 by kerem · 5 comments
Owner

Originally created by @NghiaTranUIT on GitHub (Jul 19, 2020).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/557

Originally assigned to: @NghiaTranUIT on GitHub.

Description

It's time to implement the Scripting feature on Proxyman, which allows Proxyam-ers to write JS Scripting code to inject to Proxyman and manipulate the Request and Response on the fly.

It's designed to replace the UI Rewrite tools from Charles Proxy since the UI is complicated and hard to use.

There are three hooks to write JS:

  • Matching
/// Determine if the flow is matched
/// The matched requested will trigger the `onRequest()` or `onResponse()` function 
function isMatching(request) {

    // You can use Regex or simple if statement
    // requests contains host, header and body
    if (request.url.host == "proxyman.io") {
        return true;
    }
    return false
}
  • On Request
/// Return true will trigger the OnRequest()
function isHookRequest(request) {
     return false;
}

/// This func is called if isHookRequest returns true
/// You can manipulate the request's header, body, query or host, path here 
function onRequest(request) {
    // add new header
    request.headers["New-Header"] = "New-Value";

    // Change Query param
    request.query["name"] = nghia;

    // Done
    return request;
}
  • On Response
/// Return true will trigger the onResponse()
function isHookResponse(response) {
     return false;
}

/// This func is called if isHookRequest returns true
/// You can manipulate the request's header, body, query or host, path here 
function onResponse(response) {
    // Update new content-type
    request.headers["Content-Type"] = "application/json";
    // Done
    return request;
}

Acceptance Criteria

  • Allow creating Scripting Rule
  • Support Scripting UI, has the Rule panel, Rule List and the Editor (Like Map Local)
  • Able to run JS
  • Able to hook into the Proxyman's core
  • Save scripting locally
  • ...
Originally created by @NghiaTranUIT on GitHub (Jul 19, 2020). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/557 Originally assigned to: @NghiaTranUIT on GitHub. ### Description It's time to implement the Scripting feature on Proxyman, which allows Proxyam-ers to write JS Scripting code to inject to Proxyman and manipulate the Request and Response on the fly. It's designed to replace the UI Rewrite tools from Charles Proxy since the UI is complicated and hard to use. There are three hooks to write JS: - Matching ```js /// Determine if the flow is matched /// The matched requested will trigger the `onRequest()` or `onResponse()` function function isMatching(request) { // You can use Regex or simple if statement // requests contains host, header and body if (request.url.host == "proxyman.io") { return true; } return false } ``` - On Request ```js /// Return true will trigger the OnRequest() function isHookRequest(request) { return false; } /// This func is called if isHookRequest returns true /// You can manipulate the request's header, body, query or host, path here function onRequest(request) { // add new header request.headers["New-Header"] = "New-Value"; // Change Query param request.query["name"] = nghia; // Done return request; } ``` - On Response ```js /// Return true will trigger the onResponse() function isHookResponse(response) { return false; } /// This func is called if isHookRequest returns true /// You can manipulate the request's header, body, query or host, path here function onResponse(response) { // Update new content-type request.headers["Content-Type"] = "application/json"; // Done return request; } ``` ### Acceptance Criteria - Allow creating Scripting Rule - Support Scripting UI, has the Rule panel, Rule List and the Editor (Like Map Local) - Able to run JS - Able to hook into the Proxyman's core - Save scripting locally - ...
Author
Owner

@RenderCoder commented on GitHub (Aug 16, 2020):

Hope has a nice way to debug script code, or just able to print log (maybe this is enough)

<!-- gh-comment-id:674533715 --> @RenderCoder commented on GitHub (Aug 16, 2020): Hope has a nice way to debug script code, or just able to print log (maybe this is enough)
Author
Owner

@edba commented on GitHub (Aug 22, 2020):

@NghiaTranUIT Are you planing to add some way to share some state between the request and response hook?

<!-- gh-comment-id:678571819 --> @edba commented on GitHub (Aug 22, 2020): @NghiaTranUIT Are you planing to add some way to share some state between the request and response hook?
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 22, 2020):

Yes, it's possible @edba because it's just a JS file with two request and response func. You can define a shared variable and use it.

Screen_Shot_2020-08-22_at_08_52_32
<!-- gh-comment-id:678578114 --> @NghiaTranUIT commented on GitHub (Aug 22, 2020): Yes, it's possible @edba because it's just a JS file with two request and response func. You can define a shared variable and use it. <img width="2032" alt="Screen_Shot_2020-08-22_at_08_52_32" src="https://user-images.githubusercontent.com/5878421/90946221-01b1bd00-e455-11ea-9c9d-a73bd0625540.png">
Author
Owner

@edba commented on GitHub (Aug 22, 2020):

Oh, awesome! 👍

<!-- gh-comment-id:678584125 --> @edba commented on GitHub (Aug 22, 2020): Oh, awesome! 👍
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 27, 2020):

@edba @Bijiabo @mudox The Scripting feature is released on Proxyman 2.5.1 https://github.com/ProxymanApp/Proxyman/releases/tag/2.5.0

Let update to the latest build and checkout the Doc https://docs.proxyman.io/scripting/script. Thank you guys 🙌

<!-- gh-comment-id:682007950 --> @NghiaTranUIT commented on GitHub (Aug 27, 2020): @edba @Bijiabo @mudox The Scripting feature is released on Proxyman 2.5.1 https://github.com/ProxymanApp/Proxyman/releases/tag/2.5.0 Let update to the latest build and checkout the Doc https://docs.proxyman.io/scripting/script. Thank you guys 🙌
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#555
No description provided.