MrOtherGuy / fx-autoconfig

Load custom javascript in browser context
Mozilla Public License 2.0
173 stars 11 forks source link

Clarify valid filenames #31

Closed ricewind012 closed 1 year ago

ricewind012 commented 1 year ago

I got the following error for filename _replace-window-title.uc.js, but not replace-window-title.uc.js:

Error: @ _replace-window-title.uc.js:undefined
    tryLoadIntoWindow chrome://userchromejs/content/boot.jsm:154
    onDOMContent chrome://userchromejs/content/boot.jsm:811
    handleEvent chrome://userchromejs/content/boot.jsm:870
Caused by: "Error opening input stream (invalid filename?): chrome://userscripts/content/_replace-window-title.uc.js"
MrOtherGuy commented 1 year ago

Mmm, yeah I should do that, thanks for reporting.

MrOtherGuy commented 1 year ago

This is actually more interesting than I thought it would be.

The loader handles the file just fine. However, it seems there is a restriction with chrome: resolution such that the path must always start with [a-zA-Z0-9] per searchfox

Note that just the top-level path must start with with alpanumeric characters - if your file would be in a sub-folder then starting its name with an underscore works fine. Of course, then the loader won't find it, but the chrome uri resolver doesn't restrict the filename in such case.

Also, since it is about Firefox internal chrome uri resolution this same limitation affects other resources as well. So, if you were to say, create a file _icon.png in the resources directory, then you cannot use with chrome url - so this won't work:

#preferences-button{
  list-style-image: url("chrome://userchrome/content/_icon.png") !important;
}

But if you move the file into a sub-folder then it works fine:

#preferences-button{
  list-style-image: url("chrome://userchrome/content/newdir/_icon.png") !important;
}

I'm not sure how I should handle this. I could just completely ignore all scripts that don't start with [a-zA-Z0-9] or I could potentially just not load them and instead give show a clear error that loading a file with this name won't work. That sounds neat, but then I would give such a warning for every non-matching file - not just those starting with an underscore.

ricewind012 commented 1 year ago

I'm not sure how I should handle this

it already says "invalid filename?", so you could put the name restriction in the readme, or link to this issue

That sounds neat, but then I would give such a warning for every non-matching file - not just those starting with an underscore.

is there an issue with that ?

MrOtherGuy commented 1 year ago

is there an issue with that ?

The only technical issue is that then the loader (boot.sys.mjs) would do work on more files (I mean, you probably shouldn't store other files in the scripts directory, but there's nothing stopping you from doing so).

But I can realistically only warn about script files (and manifests) starting with non-alphanumeric character while the issue still applies to files in resources, and the loader can't possibly warn about those because it doesn't do anything with the itself - the only thing it does is make resources (and scripts) directories accessible via chrome: protocol.

So, I'm leaning towards just adding a section to readme and then make the loader ignore files script files that don't start with an alphanumeric character - right now the loader tries to use such files which leads to an invalid uri error currently.