I’ve written a library to mimic Chrome’s request/response API for my Firefox add-on. Obviously I need to use this code in both my background process (main.js) and my content script. Surely there must be a better way than stringifying the imported module.
I’ve written a library to mimic Chrome’s request/response API for my Firefox add-on. Obviously
Share
There is a semi-documented way of getting the URLs of the SDK code modules. This involves low-level modules which aren’t guaranteed to stay stable. In fact, it is very likely that this part of the SDK will change and this solution won’t work any more (like the solution originally presented here).
That said, the SDK allows you to access the
loadermodule. So first you need to construct a loader with the same options as the one used by the SDK. Then you need to use theresolveURIutility function to resolve the module name using the mapping of this loader:The code above generates the URL for the module
foo. Note that you need to use the modulefoosomewhere, otherwise it won’t be included in your extension. If you don’t use it yet then a dummy function will be sufficient:Using the resulting URL as content script works just fine: