WebExtensions porting: embeddeding webextension in XUL addon

Hello,
I’m trying to rewrite my mSK to webextension.
First step would be embedding webextension in my current add-on, so I can import user preferences.

I know that I need to run webExtension.startup(), but is there a way to do it in XUL, non-boostrapped extension?
Does the only option is to rewrite my add-on as bootstrapped and then embed webextension?

Regards,
Pwl

Does the only option is to rewrite my add-on as bootstrapped and then embed webextension?

Generally yes, but I think it should be possible to bootstrap an SDK-style extension from XUL. The bootstrap.js file that is automatically included in SDK-extensions does just that, doesn’t it?

bootstrap.js:

"use strict";

const { utils: Cu } = Components;
const rootURI = __SCRIPT_URI_SPEC__.replace("bootstrap.js", "");
const COMMONJS_URI = "resource://gre/modules/commonjs";
const { require } = Cu.import(COMMONJS_URI + "/toolkit/require.js", {});
const { Bootstrap } = require(COMMONJS_URI + "/sdk/addon/bootstrap.js");
const { startup, shutdown, install, uninstall } = new Bootstrap(rootURI);

Looks pretty straight-forward. You may have to include a .xpi with an appropriate package.json in you (unpacked?) XUL extension.

1 Like

https://github.com/kee-org/KeeFox/tree/master/Firefox%20addon/KeeFox could be a useful example of how to do this.
Especially this module which pulls in the embedded webextension to the jsm in a way that can then be invoked from the rest of the legacy addon.

2 Likes