Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"match" in meta file didn't support port #4

Open
Mr-Python-in-China opened this issue Jun 3, 2024 · 4 comments · May be fixed by #7
Open

"match" in meta file didn't support port #4

Mr-Python-in-China opened this issue Jun 3, 2024 · 4 comments · May be fixed by #7

Comments

@Mr-Python-in-China
Copy link

I tried:

{
  "name":"test",
  "match": ["*://localhost:54220/"]
}

And got an error in console:

Error matching script "main": TypeError: Invalid pattern: *://localhost:54220/
    at urlMatch (utils.js:23:15)
    at eval (client.js:27:60)
    at Array.some (<anonymous>)
    at matchUserscript (client.js:27:21)
    at Array.filter (<anonymous>)
    at Proxy.eval (client.js:22:13)
    at ./node_modules/.store/webpack-monkey-virtual-b8d7e0e2c3/package/lib/client/client.js (eval at onload (localhost/:78:13), <anonymous>:455:1)
    at __webpack_require__ (eval at onload (localhost/:78:13), <anonymous>:36:32)
    at __webpack_exec__ (eval at onload (localhost/:78:13), <anonymous>:633:48)
    at eval (eval at onload (localhost/:78:13), <anonymous>:634:471)

In utils.js

function urlMatch(pattern, url) {
    const matcher = (0, browser_extension_url_match_1.matchPattern)(pattern);
    if (!matcher.valid) {
        throw new TypeError("Invalid pattern: " + pattern);
    }
    return matcher.match(url);
}

matcher.error is Error: Host "localhost:54220" cannot include a port number. All ports are matched by default..

Then I tried "match": ["*://localhost/"] and visited localhost:54220, but matcher.match(url) return false, so my script didn't work.

@Mr-Python-in-China
Copy link
Author

browser-extension-url-match works good on version 1.0.0

You may need to update the dependence?

@guansss
Copy link
Owner

guansss commented Jun 19, 2024

Did browser-extension-url-match 1.0.0 really work for you? I tried upgrading it to 1.0.0 and even 1.2.0, and it still threw that error.

The matching algorithm it simulates also does not support port matching, so it seems to work as intended.

https://developer.chrome.com/docs/extensions/mv3/match_patterns/
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns

@Mr-Python-in-China
Copy link
Author

image
image

I means, the url "http://localhost/" didn't match "http://localhost:9000/". It's not same as tampermonkey. New version seems work well

@guansss
Copy link
Owner

guansss commented Jun 20, 2024

Ah, I see, you are right. I'll update the version later, thanks for reporting!

Giglium added a commit to Giglium/webpack-monkey that referenced this issue Nov 26, 2024
- Closes guansss#4
- Add test case to unsure compatibility with future releases
Giglium added a commit to Giglium/webpack-monkey that referenced this issue Nov 26, 2024
- Closes guansss#4
- Add test case to unsure compatibility with future releases
@Giglium Giglium linked a pull request Nov 26, 2024 that will close this issue
Giglium added a commit to Giglium/webpack-monkey that referenced this issue Dec 2, 2024
- Closes guansss#4
- Add test case to unsure compatibility with future releases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants