[GH-ISSUE #998] [Bug] Scripting - if a script has Use as Mock API enabled do not pass through response if script is in Editing Mode #992

Open
opened 2026-03-03 19:23:36 +03:00 by kerem · 3 comments
Owner

Originally created by @crankygeek on GitHub (Sep 17, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/998

Originally assigned to: @NghiaTranUIT on GitHub.

I have been using the "Use as Mock API" function with my scripts to run tests that would normally be destructive, allowing me to perform multiple tests without having to setup data on the server for each pass.

Today, I accidentally left a script in Editing Mode and when I made the call to the specified endpoint, the script was bypassed which sent the request onto the server which deleted the data that I needed to complete additional tests. I had to stop my testing to setup the data again before I could continue.

I think if Use as Mock API is enabled, no requests should pass through to the server, regardless of Script Editing state. I would argue that this should happen any time the script is Editing Mode since it's easy to leave it in this state accidentally. But modifying the Mock API setting behavior would take care of my use case.

Proxyman version? (Ex. Proxyman 1.4.3)

Version 2.32.1 (23210)

macOS Version? (Ex. mac 10.14)

MacBook Pro (16-inch, 2019) macOS 11.6

Steps to reproduce

  1. Add a new scripting rule that matches example.com for any method
  2. Enable Use as Mock API for the script (Click More > Use onResponse() as Mock API)
  3. Make a change to the script to put it into Editing Mode
  4. On device that is configured to proxy through Proxyman, open example.com
  5. Observe the Scripting console reports "Skip executing the script because it is on Editing Mode." and that the request is sent to the server and the page loads normally in the browser

Expected behavior

I'm not sure what the Proxyman UI experience should be here, but my expectations when the Mock API setting is enabled is that the request will never been passed through to the server.

Perhaps a different console warning could be displayed explaining that the script was not executed, but the request was also blocked due to Mock API being enabled?

Originally created by @crankygeek on GitHub (Sep 17, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/998 Originally assigned to: @NghiaTranUIT on GitHub. I have been using the "Use as Mock API" function with my scripts to run tests that would normally be destructive, allowing me to perform multiple tests without having to setup data on the server for each pass. Today, I accidentally left a script in Editing Mode and when I made the call to the specified endpoint, the script was bypassed which sent the request onto the server which deleted the data that I needed to complete additional tests. I had to stop my testing to setup the data again before I could continue. I think if Use as Mock API is enabled, no requests should pass through to the server, regardless of Script Editing state. I would argue that this should happen any time the script is Editing Mode since it's easy to leave it in this state accidentally. But modifying the Mock API setting behavior would take care of my use case. ### Proxyman version? (Ex. Proxyman 1.4.3) Version 2.32.1 (23210) ### macOS Version? (Ex. mac 10.14) MacBook Pro (16-inch, 2019) macOS 11.6 ### Steps to reproduce 1. Add a new scripting rule that matches `example.com` for any method 2. Enable **Use as Mock API** for the script (Click **More** > **Use onResponse() as Mock API**) 3. Make a change to the script to put it into Editing Mode 4. On device that is configured to proxy through Proxyman, open `example.com` 5. Observe the Scripting console reports "Skip executing the script because it is on Editing Mode." and that the request is sent to the server and the page loads normally in the browser ### Expected behavior I'm not sure what the Proxyman UI experience should be here, but my expectations when the Mock API setting is enabled is that the request will never been passed through to the server. Perhaps a different console warning could be displayed explaining that the script was not executed, but the request was also blocked due to Mock API being enabled?
Author
Owner

@NghiaTranUIT commented on GitHub (Sep 17, 2021):

my expectations when the Mock API setting is enabled is that the request will never been passed through to the server.

It's a reasonable point 👍

I fixed it. If you don't mind, please try this beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.32.1_Improve_Mock_API_Scripting.dmg

Thanks again for opening a detailed ticket. I love it 😄

<!-- gh-comment-id:921473150 --> @NghiaTranUIT commented on GitHub (Sep 17, 2021): > my expectations when the Mock API setting is enabled is that the request will never been passed through to the server. It's a reasonable point 👍 I fixed it. If you don't mind, please try this beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.32.1_Improve_Mock_API_Scripting.dmg Thanks again for opening a detailed ticket. I love it 😄
Author
Owner

@crankygeek commented on GitHub (Sep 17, 2021):

I'm seeing a slight difference in the response bodies when the script run vs when it's in editing mode. Maybe this is expected?

Also the raw output displayed in the browser is different (no newlines/pretty layout when script is active, array order is different).

Besides that, it looks like the requests are not passing through when Mock API is enabled. 🏆

Thanks!

<!-- gh-comment-id:921889135 --> @crankygeek commented on GitHub (Sep 17, 2021): I'm seeing a slight difference in the response bodies when the script run vs when it's in editing mode. Maybe this is expected? Also the raw output displayed in the browser is different (no newlines/pretty layout when script is active, array order is different). Besides that, it looks like the requests are not passing through when Mock API is enabled. 🏆 Thanks!
Author
Owner

@NghiaTranUIT commented on GitHub (Sep 18, 2021):

I'm seeing a slight difference in the response bodies when the script run vs when it's in editing mode. Maybe this is expected?

When it's in the editing mode, it will return the template mocking response, which is:

{
    "description": "It's a Mock API Response template. You can modify the Response data on onResponse() function.",
    "scriptName": "\(scriptEntry.name)"
}

Also the raw output displayed in the browser is different (no newlines/pretty layout when script is active, array order is different).

Can you share with me the screenshot of "(no newlines/pretty layout when script is active" because I haven't changed this behavior.

array order is different

If you mean that the Key order of a Dictionary, It's a limitation when casting Object from JavascriptCore to Swift. In swift, Dictionary doesn't have order, so the order might be changed

<!-- gh-comment-id:922159386 --> @NghiaTranUIT commented on GitHub (Sep 18, 2021): > I'm seeing a slight difference in the response bodies when the script run vs when it's in editing mode. Maybe this is expected? When it's in the editing mode, it will return the template mocking response, which is: ```js { "description": "It's a Mock API Response template. You can modify the Response data on onResponse() function.", "scriptName": "\(scriptEntry.name)" } ``` > Also the raw output displayed in the browser is different (no newlines/pretty layout when script is active, array order is different). Can you share with me the screenshot of "(no newlines/pretty layout when script is active" because I haven't changed this behavior. > array order is different If you mean that the Key order of a Dictionary, It's a limitation when casting Object from JavascriptCore to Swift. In swift, Dictionary doesn't have order, so the order might be changed
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#992
No description provided.