[GH-ISSUE #885] [Scripting] Possible to parse a URL? #880

Open
opened 2026-03-03 19:22:40 +03:00 by kerem · 7 comments
Owner

Originally created by @jsorge on GitHub (May 11, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/885

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version? (Ex. Proxyman 1.4.3)

2.25.0

macOS Version? (Ex. mac 10.14)

11.3.1

In Scripting, is it possible to use the url module (I'm not sure what it's called in JS) to parse a URL? I've got this code in a CodeRunner window using Node and it works:

var URL = require('url').URL;
var myURL = new URL('http://www.example.com/foo?bar=1#main');
console.log(myURL.host); // prints 'www.example.com'

However when I try to do this in the Scripting window I get this error:

❌Error: Could not import 3rd scripts at url. Only support @users, @addons and @libs
❌Error: TypeError: undefined is not an object (evaluating 'require('url').URL') 

I'm hoping there's a way to do what I'm after. Thanks for a great app; Proxyman is fantastic!

Originally created by @jsorge on GitHub (May 11, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/885 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version? (Ex. Proxyman 1.4.3) 2.25.0 ### macOS Version? (Ex. mac 10.14) 11.3.1 In Scripting, is it possible to use the `url` module (I'm not sure what it's called in JS) to parse a URL? I've got this code in a CodeRunner window using Node and it works: ```nodejs var URL = require('url').URL; var myURL = new URL('http://www.example.com/foo?bar=1#main'); console.log(myURL.host); // prints 'www.example.com' ``` However when I try to do this in the Scripting window I get this error: ``` ❌Error: Could not import 3rd scripts at url. Only support @users, @addons and @libs ❌Error: TypeError: undefined is not an object (evaluating 'require('url').URL') ``` I'm hoping there's a way to do what I'm after. Thanks for a great app; Proxyman is fantastic!
Author
Owner

@NghiaTranUIT commented on GitHub (May 12, 2021):

Hi @jsorge Unfortunately, the scripting could not use NodeJS modules because the scripting is built on top of JavascriptCore, which is a pure JS framework.

JavascriptCore doesn't support this URL too

Just wondering: How often do you use URL for the scripting? If it's an important class, I might find a solution to support it 👍

<!-- gh-comment-id:839385875 --> @NghiaTranUIT commented on GitHub (May 12, 2021): Hi @jsorge Unfortunately, the scripting could not use NodeJS modules because the scripting is built on top of [JavascriptCore](https://developer.apple.com/documentation/javascriptcore), which is a pure JS framework. JavascriptCore doesn't support this [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) too Just wondering: How often do you use URL for the scripting? If it's an important class, I might find a solution to support it 👍
Author
Owner

@jsorge commented on GitHub (May 12, 2021):

Ah yeah that makes sense @NghiaTranUIT, thanks for the explanation!

It's not something I'm doing a bunch (today was the first time) but I do have to find an alternate solution. I really only need the value of a path parameter so maybe it's time to turn to a regex.

<!-- gh-comment-id:839387381 --> @jsorge commented on GitHub (May 12, 2021): Ah yeah that makes sense @NghiaTranUIT, thanks for the explanation! It's not something I'm doing a bunch (today was the first time) but I do have to find an alternate solution. I really only need the value of a path parameter so maybe it's time to turn to a regex.
Author
Owner

@NghiaTranUIT commented on GitHub (May 12, 2021):

You can easily get a path of the URL by using

const path = request.path;

Ref: https://docs.proxyman.io/scripting/script#onrequest-object-format

<!-- gh-comment-id:839388628 --> @NghiaTranUIT commented on GitHub (May 12, 2021): You can easily get a path of the URL by using ```js const path = request.path; ``` Ref: https://docs.proxyman.io/scripting/script#onrequest-object-format
Author
Owner

@jsorge commented on GitHub (May 12, 2021):

Ah yeah this is a bit different. We route to new places in our app through protocol URIs that come in the payload as strings. I need to parse one of those 😊

<!-- gh-comment-id:839389050 --> @jsorge commented on GitHub (May 12, 2021): Ah yeah this is a bit different. We route to new places in our app through protocol URIs that come in the payload as strings. I need to parse one of those 😊
Author
Owner

@NghiaTranUIT commented on GitHub (May 12, 2021):

Thanks. I will find a way to support native URL if it's possible 👍

<!-- gh-comment-id:839397292 --> @NghiaTranUIT commented on GitHub (May 12, 2021): Thanks. I will find a way to support native URL if it's possible 👍
Author
Owner

@Zirro commented on GitHub (Dec 1, 2021):

https://github.com/zloirock/core-js has well-designed implementations of URL and URLSearchParams (among many others) which are designed to work in buggy or unusual environments that don't support them natively. You could probably inject them as globals into JavaScriptCore and have them work as if they were a native implementation.

<!-- gh-comment-id:983998657 --> @Zirro commented on GitHub (Dec 1, 2021): https://github.com/zloirock/core-js has well-designed implementations of `URL` and `URLSearchParams` (among many others) which are designed to work in buggy or unusual environments that don't support them natively. You could probably inject them as globals into JavaScriptCore and have them work as if they were a native implementation.
Author
Owner

@NghiaTranUIT commented on GitHub (Dec 2, 2021):

Thanks for your suggestion @Zirro Let me play around and try to integrate it 👍

<!-- gh-comment-id:984261229 --> @NghiaTranUIT commented on GitHub (Dec 2, 2021): Thanks for your suggestion @Zirro Let me play around and try to integrate it 👍
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#880
No description provided.