[GH-ISSUE #1839] Can Proxyman support dynamic environment variables? #1832

Closed
opened 2026-03-03 19:54:47 +03:00 by kerem · 9 comments
Owner

Originally created by @Seayon on GitHub (Nov 5, 2023).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1839

Originally assigned to: @NghiaTranUIT on GitHub.

Description

In my case, I have some variables with fixed keys, but their values change frequently. Previously, I manually opened the script and wrote the new values, but it became tedious. So, I tried writing the variables to the ~/.zshrc file and changed the ENV in ~/.zshrc quickly. However, I found that Proxyman couldn't read the latest variables.

Is it possible to provide a hook for Proxyman to get the latest environment variables? Or, can Proxyman support a feature to save simple variables and let me choose one from the menu bar quickly?

Thank you!

Why this feature/change is important?

Proxyman is a very professional and easy-to-use tool. Adding such a feature doesn't feel very complicated, but it would provide higher customization options for professional users.

Originally created by @Seayon on GitHub (Nov 5, 2023). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1839 Originally assigned to: @NghiaTranUIT on GitHub. ## Description In my case, I have some variables with fixed keys, but their values change frequently. Previously, I manually opened the script and wrote the new values, but it became tedious. So, I tried writing the variables to the ~/.zshrc file and changed the ENV in ~/.zshrc quickly. However, I found that Proxyman couldn't read the latest variables. Is it possible to provide a hook for Proxyman to get the latest environment variables? Or, can Proxyman support a feature to save simple variables and let me choose one from the menu bar quickly? Thank you! ## Why this feature/change is important? Proxyman is a very professional and easy-to-use tool. Adding such a feature doesn't feel very complicated, but it would provide higher customization options for professional users.
kerem 2026-03-03 19:54:47 +03:00
Author
Owner

@NghiaTranUIT commented on GitHub (Nov 5, 2023):

Proxyman Scripting can read your ENV from ~/.zshrc (docs).

Here is the example:

async function onResponse(context, url, request, response) {
  console.log($PATH);
  console.log($ACCESS_TOKEN);
  console.log($PROXYMAN_PATH);
 
  // Done
  return response;
}
<!-- gh-comment-id:1793681274 --> @NghiaTranUIT commented on GitHub (Nov 5, 2023): Proxyman Scripting can read your ENV from `~/.zshrc` ([docs](https://docs.proxyman.io/scripting/environment-variables#2.-environment-variables)). Here is the example: ```js async function onResponse(context, url, request, response) { console.log($PATH); console.log($ACCESS_TOKEN); console.log($PROXYMAN_PATH); // Done return response; } ```
Author
Owner

@Seayon commented on GitHub (Nov 5, 2023):

Proxyman Scripting can read your ENV from ~/.zshrc (docs).

Here is the example:

async function onResponse(context, url, request, response) {
  console.log($PATH);
  console.log($ACCESS_TOKEN);
  console.log($PROXYMAN_PATH);
 
  // Done
  return response;
}

Thank you for your reply!

I am able to use the ENV from ~/.zshrc, and I find that the Proxyman documentation is very comprehensive. However, my problem is whether Proxyman can automatically read the updated from ~/.zshrc ?

<!-- gh-comment-id:1793682075 --> @Seayon commented on GitHub (Nov 5, 2023): > Proxyman Scripting can read your ENV from `~/.zshrc` ([docs](https://docs.proxyman.io/scripting/environment-variables#2.-environment-variables)). > > Here is the example: > > ```js > async function onResponse(context, url, request, response) { > console.log($PATH); > console.log($ACCESS_TOKEN); > console.log($PROXYMAN_PATH); > > // Done > return response; > } > ``` Thank you for your reply! I am able to use the ENV from ~/.zshrc, and I find that the Proxyman documentation is very comprehensive. However, my problem is whether Proxyman can automatically read the updated from ~/.zshrc ?
Author
Owner

@NghiaTranUIT commented on GitHub (Nov 5, 2023):

It's not automatically load the env yet because it's an expensive operation. That's the reason why I introduced the "Reload env" button.

How often your ENV is changed that you need to reload the ENV automatically?

<!-- gh-comment-id:1793685179 --> @NghiaTranUIT commented on GitHub (Nov 5, 2023): It's not automatically load the env yet because it's an expensive operation. That's the reason why I introduced the "Reload env" button. How often your ENV is changed that you need to reload the ENV automatically?
Author
Owner

@Seayon commented on GitHub (Nov 5, 2023):

It's not automatically load the env yet because it's an expensive operation. That's the reason why I introduced the "Reload env" button.

How often your ENV is changed that you need to reload the ENV automatically?

Actually, The frequency of changes actually depends on how busy I am at the moment. I am working on multiple projects simultaneously, and each project has a fixed key. However, the value that determines the flow direction for each project is different. That's why I want to have a 'Quick Switch and Reload' feature. I usually do it manually,which is why I would like to have a hook to inform Proxyman to reload the ENV ?

<!-- gh-comment-id:1793695020 --> @Seayon commented on GitHub (Nov 5, 2023): > It's not automatically load the env yet because it's an expensive operation. That's the reason why I introduced the "Reload env" button. > > How often your ENV is changed that you need to reload the ENV automatically? Actually, The frequency of changes actually depends on how busy I am at the moment. I am working on multiple projects simultaneously, and each project has a fixed key. However, the value that determines the flow direction for each project is different. That's why I want to have a 'Quick Switch and Reload' feature. I usually do it manually,which is why I would like to have a hook to inform Proxyman to reload the ENV ?
Author
Owner

@Seayon commented on GitHub (Nov 5, 2023):

By the way, I fully understand that automatically loading environment variables is also an expensive operation. Therefore, I'm wondering if it's possible to provide a hook or API for me to call?

<!-- gh-comment-id:1793695470 --> @Seayon commented on GitHub (Nov 5, 2023): By the way, I fully understand that automatically loading environment variables is also an expensive operation. Therefore, I'm wondering if it's possible to provide a hook or API for me to call?
Author
Owner

@NghiaTranUIT commented on GitHub (Nov 6, 2023):

I guess I can introduce a helper func, like:

_reloadENV();

It runs synchronously and you can run it directly in your Scripts. How do you feel?

<!-- gh-comment-id:1793908893 --> @NghiaTranUIT commented on GitHub (Nov 6, 2023): I guess I can introduce a helper func, like: ```js _reloadENV(); ``` It runs synchronously and you can run it directly in your Scripts. How do you feel?
Author
Owner

@Seayon commented on GitHub (Nov 6, 2023):

I guess I can introduce a helper func, like:

_reloadENV();

It runs synchronously and you can run it directly in your Scripts. How do you feel?

Does this mean I have to call it within a script in Proxyman? Can I have my own program call it instead? Some external applications or shell scripts that I developed myself. If this is very difficult, then calling it within a Proxyman script is also good, at least I can use it.

<!-- gh-comment-id:1794034383 --> @Seayon commented on GitHub (Nov 6, 2023): > I guess I can introduce a helper func, like: > > ```js > _reloadENV(); > ``` > > It runs synchronously and you can run it directly in your Scripts. How do you feel? Does this mean I have to call it within a script in Proxyman? Can I have my own program call it instead? Some external applications or shell scripts that I developed myself. If this is very difficult, then calling it within a Proxyman script is also good, at least I can use it.
Author
Owner

@NghiaTranUIT commented on GitHub (Nov 8, 2023):

@Seayon you can try this Beta build: https://download.proxyman.io/beta/Proxyman_4.14.0_Scripting:_Reload_Env_by_scripts.dmg

async function onRequest(context, url, request) {
  // manually reload to get the latest changes
  _reloadEnv();
  
  // get env
  console.log($PROXYMAN_ID)
  
  // Done
  return request;
}

<!-- gh-comment-id:1800935933 --> @NghiaTranUIT commented on GitHub (Nov 8, 2023): @Seayon you can try this Beta build: https://download.proxyman.io/beta/Proxyman_4.14.0_Scripting:_Reload_Env_by_scripts.dmg - Docs: https://docs.proxyman.io/scripting/environment-variables#3.-additions - Sample code: ```js async function onRequest(context, url, request) { // manually reload to get the latest changes _reloadEnv(); // get env console.log($PROXYMAN_ID) // Done return request; } ```
Author
Owner

@Seayon commented on GitHub (Nov 9, 2023):

 // manually reload to get the latest changes
  _reloadEnv();

Thanks ! That's definely helpful !

<!-- gh-comment-id:1803193620 --> @Seayon commented on GitHub (Nov 9, 2023): > ```js > // manually reload to get the latest changes > _reloadEnv(); > ``` Thanks ! That's definely helpful !
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#1832
No description provided.