Closed Bug 1621580 Opened 4 years ago Closed 4 years ago

moz-extension:// URLs cannot be imported with ChromeUtils.import() when loaded from an XPI

Categories

(WebExtensions :: Untriaged, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: darktrojan, Unassigned)

References

Details

Attachments

(1 file)

I can call fetch("moz-extension://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/manifest.json") and it will succeed if the extension is unpacked, but fail if the extension is packed. (This isn't actually what I'm trying to do but it's a good enough test case.)

This seems to be the case whether extensions.webextensions.remote is set to true or false.

  1. How does manifest.json look like? In particular, what is inside the web_accessible_resources and permissions keys?
  2. Where are you calling fetch?

At the moment, I'm just doing all this from the devtools toolbox. (In Thunderbird, but the same is true in Firefox.)

I've just done some further investigation and it seems that the presence of an experiment_apis key causes the problem. Remove the key and everything seems to work fine, except then I can't have an experiment, which is what I'm trying to work on in the first place…

Please attach a full test case and exact steps to reproduce the issue.

Attached file ff_exp.xpi

This WebExtension Experiment shows the described behaviour. Reproducable in FireFox Nightly 76.0a1 (2020-03-11). To run Experiments, you have to set

xpinstall.signatures.required = false
extensions.experiments.enabled = true

If this WebExtension gets installed unpacked via add-on debugging, everything works as expected and you will see

Loading myModule.jsm
WebExtensions: Hello world! <1>

in the main console. If it gets installed as a packed xpi directly, you will see

Error: An unexpected error occurred background.js:3:23

in the console of the add-on itself. If the import of myModule.jsm is removed (and all references to myModule), it runs thru without error.

I don't know enough about the guts of the module loader and the moz-extension handler to know why this doesn't work, but if you switch the getURL() call to something like context.extension.rootURI.resolve("./modules/myModule.jsm") that should give you a file: or jar: url (depending on whether the extensions is packed or not) that works with the module loader.

Summary: moz-extension:// URLs cannot be fetched when loaded from a XPI → moz-extension:// URLs cannot be imported with ChromeUtils.import() when loaded from an XPI

Loading custom modules from extension experiments isn't a thing we want to support. Andrew gave you some workarounds, or if that doesn't work, you might need to setup an URI substitution and map it to a resource:// URI before loading a JSM.

Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → WONTFIX

Thanks for your help!

Using context.extension.rootURI.resolve() fixes this for us. Just to have a second tool available: How do I setup a URI substitution to map it to a resource:/ URI ?

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: