ProxymanApp / Proxyman

Modern. Native. Delightful Web Debugging Proxy for macOS, iOS, and Android ⚡️
https://proxyman.io
5.6k stars 188 forks source link

Get flow info from JS Context in the Scripting #746

Open NghiaTranUIT opened 3 years ago

NghiaTranUIT commented 3 years ago

Description

Currently, we can print out the data of the context object by using console.log(context). For instance,

// context (readonly)
{
    "scriptName": "<String> Your Script Name",
    "matchingRule": "<String> Your Matching Rule",
    "matchingMethod": "<String> Method",
    "isEnableOnRequest": "Bool",
    "isEnableOnResponse": "Bool",
    "filePath": "<String> Script path"
}

However, it lacks the flow data, such as ID, Remote Device IP, Nickname, Client Path, or Client/Remote Address. They're useful if some users need them to write their logic.

For example, change the host if the request comes from a particular remote device.

if (context.remoteDeviceIP == "192.168.0.101") {
   request.host = "localhost"
}

Acceptance Criteria

NghiaTranUIT commented 3 years ago

Done with https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.15.2_Add_More_Info_Scripting_Context.dmg

[onResponse] with Request ID=51
{
"scriptName": "Log Context",
"flow": {
"serverPort": "443",
"serverIpAddress": "104.18.230.83",
"clientIpAddress": "192.168.0.102",
"remoteDeviceName": "iPhone XR",
"remoteDeviceIP": "192.168.0.102",
"id": "51",
"clientPath": null,
"clientPort": "51494",
"clientName": null
},
"isEnableOnResponse": true,
"matchingMethod": "ANY",
"matchingRule": "https://api.producthunt.com/v2/graphql",
"filePath": "/Users/nghiatran/Library/Application Support/com.proxyman.NSProxy/scripts/EA0E187E.js",
"isEnableOnRequest": true
}