fregante/content-scripts-register-polyfill

URLs with port

maximmig opened this issue · 2 comments

According to the info from https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns

the path pattern string should not include a port number

so in my case instead of http://localhost:7790/* I have to specify http://localhost/* pattern. But when I try to register a content script for URL http://localhost:7790/foo/bar the polyfill fails to do it because it tests the URL against ^http:[/][/]localhost([/].*)?$. This was introduced in version 1.0.1, the previous 1.0.0 used another regex: ^http:\/\/localhost\/?.+$ and this worked. Firefox handles this case correctly, but the polyfill for Chrome doesn't after your last changes.

Thanks for the report. The new changes are indeed stricter and copy the verification regexes straight from Firefox.

Can you provide your exact contentScript.register configuration object?

What error do you see?

I want to understand if this issue is due to Firefox’ regex or if it's my generated regex that doesn't account for the the port in the host.

Either way PR welcome with a lightweight solution on https://github.com/fregante/webext-patterns

Firefox handles this case correctly

I did some tests and I'm not sure what you mean by this. Neither browser will inject anything if the port is specified either in content_scripts.*.matches or via contentScript.register in Firefox.

Both browsers specify pretty firmly that ports are not part of match patterns: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns

Even if Firefox won't throw an error if you have http://localhost:1234/* in both permissions and content_scripts.*.matches, no code will be injected natively nor via contentScript.register

If contentScript.register can do something in your Firefox that this polyfill can't do in Chrome, please leave a comment and especially attach a repro with manifest.json and background.js