Ivan
Ivan

Reputation: 6013

Can Firefoxe's web-ext utility be made to open an extension page on start with -u?

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?

Upvotes: 5

Views: 653

Answers (1)

Ivan
Ivan

Reputation: 6013

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:

  1. With firefox --manageProfiles, create a separate profile to test my extension

  2. Proceed to set and save the extensions.webextensions.keepUuidOnUninstall about:config flag (do this without web-ext or with --keep-profile-changes otherwise)

  3. In manifest.json add an id for the extension:

    "applications": {
      "gecko": {
        "id": "[email protected]"
      }
    }
    
  4. 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.

Upvotes: 4

Related Questions