guansss / webpack-monkey

A webpack plugin for developing your userscripts with a modern workflow, featuring HMR, meta generation, and more.
MIT License
36 stars 1 forks source link

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

Open Mr-Python-in-China opened 4 months ago

Mr-Python-in-China commented 4 months ago

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 commented 4 months ago

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

You may need to update the dependence?

guansss commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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