[GH-ISSUE #1950] Trouble triggering scripts from iOS simulator #1942

Closed
opened 2026-03-03 19:55:38 +03:00 by kerem · 9 comments
Owner

Originally created by @ben-codes-five on GitHub (Feb 27, 2024).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1950

Originally assigned to: @NghiaTranUIT on GitHub.

Description

I am doing iOS development and monitoring network traffic using Proxyman.
I can see the network calls in Proxyman, suggesting I have the certificates set up correctly, however, I am trying to modify the response for an endpoint using scripts but the scripts aren't being triggered.

For context, the endpoint is a graphql endpoint and below is my script:

const file = require("mockdata.json");

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

  // 1. Extract the queryName from the request
  var queryName = request.body.query.match(/\S+/gi)[1].split('(').shift();

  // 2. Save to sharedState
  sharedState.queryName = queryName

  // Done
  return request;
}

async function onResponse(context, url, request, response) {

  // 3. Check if it's the request we need to map
  if (sharedState.queryName == "myQuery") {

    // 4. Import the local file by Action Button -> Import
    // Get the local JSON file and set it as a body (like Map Local)
    response.headers["Content-Type"] = "application/json";
    response.body = file;
  }

  // Done
  return response;
}

I can confirm the script works because I am able to trigger the script by rerunning the request within Proxyman, however, I am unable to trigger the script from sending a request from my iOS app.

Any idea what the issue is? Smells like either an internal bug or a configuration issue.

Environment

  • App version: Proxyman 5.0.0
  • macOS version: macOS Sonoma 14.3.1
  • Xcode version: Xcode 15.1
  • Simulator version: Simulator 15.1
Originally created by @ben-codes-five on GitHub (Feb 27, 2024). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1950 Originally assigned to: @NghiaTranUIT on GitHub. ## Description I am doing iOS development and monitoring network traffic using Proxyman. I can see the network calls in Proxyman, suggesting I have the certificates set up correctly, however, I am trying to modify the response for an endpoint using scripts but the scripts aren't being triggered. For context, the endpoint is a graphql endpoint and below is my script: ```javascript const file = require("mockdata.json"); async function onRequest(context, url, request) { // console.log(request); console.log(url); // 1. Extract the queryName from the request var queryName = request.body.query.match(/\S+/gi)[1].split('(').shift(); // 2. Save to sharedState sharedState.queryName = queryName // Done return request; } async function onResponse(context, url, request, response) { // 3. Check if it's the request we need to map if (sharedState.queryName == "myQuery") { // 4. Import the local file by Action Button -> Import // Get the local JSON file and set it as a body (like Map Local) response.headers["Content-Type"] = "application/json"; response.body = file; } // Done return response; } ``` I can confirm the script works because I am able to trigger the script by rerunning the request within Proxyman, however, I am unable to trigger the script from sending a request from my iOS app. Any idea what the issue is? Smells like either an internal bug or a configuration issue. ## Environment - App version: Proxyman 5.0.0 - macOS version: macOS Sonoma 14.3.1 - Xcode version: Xcode 15.1 - Simulator version: Simulator 15.1
kerem 2026-03-03 19:55:38 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@NghiaTranUIT commented on GitHub (Feb 28, 2024):

however, I am trying to modify the response for an endpoint using scripts but the scripts aren't being triggered.

If you don't see any log, it means the Script URL doesn't match your URL.

Can you show me the script URL Rule you're using?


Your script is an old way to match with a GraphQL Query Name. If you're using v5.0.0, there is an easier way:

  1. Call your GraphQL on iPhone -> Make sure you can see the traffic on Proxyman macOS
  2. Right Click on this request -> Tools -> Scripting
  3. Proxyman automatically creates a matched rule with a given GraphQL QueryName.
  4. Use your new script
const file = require("mockdata.json");

async function onResponse(context, url, request, response) {

response.headers["Content-Type"] = "application/json";
    response.body = file;

  // Done
  return response;
}

Screenshot 2024-02-28 at 08 29 53

<!-- gh-comment-id:1968025166 --> @NghiaTranUIT commented on GitHub (Feb 28, 2024): > however, I am trying to modify the response for an endpoint using scripts but the scripts aren't being triggered. If you don't see any log, it means the Script URL doesn't match your URL. Can you show me the script URL Rule you're using? ---------- Your script is an old way to match with a GraphQL Query Name. If you're using v5.0.0, there is an easier way: 1. Call your GraphQL on iPhone -> Make sure you can see the traffic on Proxyman macOS 2. Right Click on this request -> Tools -> Scripting 3. ✅ Proxyman automatically creates a matched rule with a given GraphQL QueryName. 4. Use your new script ```js const file = require("mockdata.json"); async function onResponse(context, url, request, response) { response.headers["Content-Type"] = "application/json"; response.body = file; // Done return response; } ``` ![Screenshot 2024-02-28 at 08 29 53](https://github.com/ProxymanApp/Proxyman/assets/5878421/3cc97d2d-d5ee-40b5-9178-4130dbd937a0)
Author
Owner

@NghiaTranUIT commented on GitHub (Feb 28, 2024):

Or you can map to a local file directly:

async function onResponse(context, url, request, response) {
  // console.log(response);
  response.headers["Content-Type"] = "application/json";
  response.bodyFilePath = "~/Desktop/my_response.json"
  
  // Done
  return response;
}
<!-- gh-comment-id:1968026122 --> @NghiaTranUIT commented on GitHub (Feb 28, 2024): Or you can map to a local file directly: ```js async function onResponse(context, url, request, response) { // console.log(response); response.headers["Content-Type"] = "application/json"; response.bodyFilePath = "~/Desktop/my_response.json" // Done return response; } ```
Author
Owner

@ben-codes-five commented on GitHub (Feb 28, 2024):

I was able to get it to work! However, not by importing my json file. I had to map the local file directly.
Thanks for your help!

<!-- gh-comment-id:1969453788 --> @ben-codes-five commented on GitHub (Feb 28, 2024): I was able to get it to work! However, not by importing my json file. I had to map the local file directly. Thanks for your help!
Author
Owner

@NghiaTranUIT commented on GitHub (Feb 29, 2024):

@ben-codes-five Glad to know you made it. The Map Local Tool works fine too 👍

<!-- gh-comment-id:1970150793 --> @NghiaTranUIT commented on GitHub (Feb 29, 2024): @ben-codes-five Glad to know you made it. The Map Local Tool works fine too 👍
Author
Owner

@ben-codes-five commented on GitHub (Feb 29, 2024):

Reopening because a colleague of mine is having the same issue but can't seem to figure out what the issue is.

<!-- gh-comment-id:1971598508 --> @ben-codes-five commented on GitHub (Feb 29, 2024): Reopening because a colleague of mine is having the same issue but can't seem to figure out what the issue is.
Author
Owner

@jmittelstaedt12 commented on GitHub (Feb 29, 2024):

Similar to @ben-codes-five I'm unable to execute my script through requests made from simulator. Only on repeat requests through the proxyman window can I get the script to run. Heres my match:

image

<!-- gh-comment-id:1971621046 --> @jmittelstaedt12 commented on GitHub (Feb 29, 2024): Similar to @ben-codes-five I'm unable to execute my script through requests made from simulator. Only on repeat requests through the proxyman window can I get the script to run. Heres my match: ![image](https://github.com/ProxymanApp/Proxyman/assets/20647665/f68a7c4f-b093-4f1a-ac8c-352c926f4f09)
Author
Owner

@NghiaTranUIT commented on GitHub (Mar 1, 2024):

@jmittelstaedt12 can you follow this steps:

  1. Make a HTTP Request first on your iOS Simulator -> Verify you can see the request on Proxyman first
  2. Right Click on this request -> Tools -> Scripting (No need to change any thing, it already works)
  3. Re-sent your request again -> Check if you can see the console.log() from the Scripting ?

May I ask: Is your iOS app a native iOS app or React-Native ?

<!-- gh-comment-id:1972276304 --> @NghiaTranUIT commented on GitHub (Mar 1, 2024): @jmittelstaedt12 can you follow this steps: 1. Make a HTTP Request first on your iOS Simulator -> Verify you can see the request on Proxyman first 2. Right Click on this request -> Tools -> Scripting (No need to change any thing, it already works) 3. Re-sent your request again -> Check if you can see the `console.log()` from the Scripting ? --------- May I ask: Is your iOS app a native iOS app or React-Native ?
Author
Owner

@NghiaTranUIT commented on GitHub (Mar 1, 2024):

Here is the video: It works fine.

https://github.com/ProxymanApp/Proxyman/assets/5878421/93e79918-4189-4815-b846-56797721f4b8

<!-- gh-comment-id:1972289924 --> @NghiaTranUIT commented on GitHub (Mar 1, 2024): Here is the video: It works fine. https://github.com/ProxymanApp/Proxyman/assets/5878421/93e79918-4189-4815-b846-56797721f4b8
Author
Owner

@jmittelstaedt12 commented on GitHub (Mar 1, 2024):

@NghiaTranUIT resolved the issue. My problem seemed to be that I had my VPN on, as its now working with it turned off

<!-- gh-comment-id:1973984784 --> @jmittelstaedt12 commented on GitHub (Mar 1, 2024): @NghiaTranUIT resolved the issue. My problem seemed to be that I had my VPN on, as its now working with it turned off
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#1942
No description provided.