As far as I understand, each time an extension is reloaded, it gets a new moz-extension:// URL with a new UUID. This makes it impossible to know the extension page URL I want to use with web-ext run -u in advance. This makes web-ext almost worthless for me because I have to (manually) open the page I need to run my tests on. If I knew the URL beforehand I could just pass it to web-ext and do everything completely automatically, and with a headless FF. Is there a way around this?
- 5,803
- 2
- 29
- 46
1 Answers
After some fiddling I finally managed to have web-ext open a page with moz-extension schema on browser start.
The only way (that I found) to open this page with an extension context (and test the page correctly) and not as an ordinary file:// is to use a moz-extension://<internal UUID>/path/to/extension/page/from/extension/root type URI to access it.
The problem is, as a temporary extension, it always has a different UUID that is not preserved between re-installs, so there is no way of telling web-ext to open an extension page via -u while using the defaults.
This is where this helpful documentation page comes in. It mentions the extensions.webextensions.keepUuidOnUninstall option in about:config that does exactly that. So a profile has to be created that has this option set to true, and used with web-ext -p option.
The next problem I had was that the page would silently fail to open. Apparently Firefox was attempting to open the page before the extension was installed. But web-ext has a --pre-install option that makes the extension (and its pages) available at start, so when it is enabled the page does open. Caveat 1 is that using --pre-install requires the extension to have an ID (this one is not the mentioned UUID generated by Firefox) that has to be set in manifest.json. Caveat 2, --pre-install disables extension auto-reloading on file change.
So my final solution was to:
With
firefox --manageProfiles, create a separate profile to test my extensionProceed to set and save the
extensions.webextensions.keepUuidOnUninstallabout:configflag (do this withoutweb-extor with--keep-profile-changesotherwise)In
manifest.jsonadd an id for the extension:"applications": { "gecko": { "id": "addon@example.com" } }Run
web-ext run -p <testing profile name> --pre-install -u moz-extension://<extension UUID>/path/to/extension/page.html
This starts Firefox with a temporary installation of your extension and opens the desired page.
If you know a better solution (e.g. one that does not disable the auto-reloading), your answer is very welcome.
- 5,803
- 2
- 29
- 46