Hybrid extension/ bootstrapped & WebExtensions

Hi:-)

I am currently using a bootstrapped extension, which lazy loads a bunch of modules. I want to experiment and write a WebExtension version, but I have some questions.

  1. How am I going to bootstrap the extension? Right now there’s a bootstrap.js file. If I want to move to WebExtensions, I need to create a manifest.json. UPDATE: Wladimir created a nice post https://palant.de/2015/10/15/using-webextensions-apis-in-a-classic-extension, which I guess is the answer to my question.

  2. How am I going to lazy load multiple background files? In the bootstrapped version I use XPCOMUtils.defineLazyModuleGetter to lazy load different jsm modules, so I’m trying to find a similar way for WebExtensions. Easiest way I found is adding all scripts in the background section of manifest.json. But this loads them all at once. Do you have any suggestions?

  3. What’s the chrome:// URL format for the different files? With bootstrapped extensions, there’s a chrome manifest, thus I can use chrome://MY_EXTENSION/content/FILE. What’s the equivalent format for WebExtensions?

These are some first questions that came to my mind.

Related to this post:

So, based on this, new question is born:-) What are the options for bootstrapped extensions? Switch to Add-on SDK? If that’s the option, how easy it is to switch from bootstrap extension to Add-on SDK?

Thanks,
Panagiota

Here is an awesome article showing how to use WebExt in classic bootstrap:

If you want to use SDK stuff in classic bootstrap you can see the page here:

That’s pretty awesome! I tried to use SDK from classic bootstrap like this, but it didn’t work:

const COMMONJS_URI = 'resource://gre/modules/commonjs';
const { require } = Cu.import(COMMONJS_URI + '/toolkit/require.js', {});
var pageMod = require("sdk/page-mod");

pageMod.PageMod({
  include: "*.mozilla.org",
  contentScript: 'window.alert("Page matches ruleset");'
});

I navigate to mozilla.org, but I don’t get the alert. What am I doing wrong?

That’s weird it looks like it should work. Does the console give any error messages?