[GH-ISSUE #664] Ability to add delay for responses #661

Closed
opened 2026-03-03 19:20:44 +03:00 by kerem · 4 comments
Owner

Originally created by @amorphius on GitHub (Oct 21, 2020).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/664

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version? (Ex. Proxyman 1.4.3)

2.10.0

macOS Version? (Ex. mac 10.14)

mac 10.13

I really need to have ability to delay some responses in scripting. Ideally using Promises. But I was told that's not possible. Maybe there are any workarounds to achieve delays?

Originally created by @amorphius on GitHub (Oct 21, 2020). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/664 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version? (Ex. Proxyman 1.4.3) 2.10.0 ### macOS Version? (Ex. mac 10.14) mac 10.13 I really need to have ability to delay some responses in scripting. Ideally using Promises. But I was told that's not possible. Maybe there are any workarounds to achieve delays?
kerem 2026-03-03 19:20:44 +03:00
Author
Owner

@NghiaTranUIT commented on GitHub (Oct 21, 2020):

It seems that JavaScriptCore from Apple doesn’t officially support Promise.

I will find the way to support fetch api, then you can convert your Promise to fetch and make request asynchronously.

<!-- gh-comment-id:713690485 --> @NghiaTranUIT commented on GitHub (Oct 21, 2020): It seems that JavaScriptCore from Apple doesn’t officially support Promise. I will find the way to support fetch api, then you can convert your Promise to fetch and make request asynchronously.
Author
Owner

@amorphius commented on GitHub (Oct 21, 2020):

It's not only about fetches but implementing simple delay for response when I want to emulate slow connection for particular request.

<!-- gh-comment-id:713718342 --> @amorphius commented on GitHub (Oct 21, 2020): It's not only about fetches but implementing simple delay for response when I want to emulate slow connection for particular request.
Author
Owner

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

Hey @amorphius, let check out this BETA build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.10.0_Add_Sleep_Func.dmg

Basically, you can use sleep() function to make the current thread sleep synchronously. Please beware that sleep() takes milliseconds as a param.

For instance,

function onResponse(context, url, request, response) {
  console.log("Start sleep");
  
  // Sleep 5 seconds
  sleep(5000);
  
  console.log("Done")
  
  // Done
  return response;
}

I tested and it will delay 5 seconds before returning the Response to my client app 🙌

<!-- gh-comment-id:714185110 --> @NghiaTranUIT commented on GitHub (Oct 22, 2020): Hey @amorphius, let check out this BETA build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.10.0_Add_Sleep_Func.dmg Basically, you can use `sleep()` function to make the current thread sleep synchronously. Please beware that `sleep()` takes milliseconds as a param. For instance, ```js function onResponse(context, url, request, response) { console.log("Start sleep"); // Sleep 5 seconds sleep(5000); console.log("Done") // Done return response; } ``` I tested and it will delay 5 seconds before returning the Response to my client app 🙌
Author
Owner

@amorphius commented on GitHub (Oct 22, 2020):

It works, great job! Thank you!

<!-- gh-comment-id:714301901 --> @amorphius commented on GitHub (Oct 22, 2020): It works, great job! Thank you!
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#661
No description provided.