Firefox Add-on dev, How to use sample code from MDN in Addon Builder

I use add on builder to create extensions when searching for MDN. I find interfaces that I cannot figure out how to call them in the online designer addon builder

for example this code

var bmsvc = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
                      .getService(Components.interfaces.nsINavBookmarksService);

does not create and leads to XPI error

+5
source share
1 answer

At the top of your document, put the line:

const { Cc, Ci, Cu } = require('chrome');

and Components.classestry using Ccinstead of Components.interfacestry Ci.

var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]
                  .getService(Ci.nsINavBookmarksService);

This should work, if not, put a link to your public add-on or sample code and a link to the documentation site.

+3
source

All Articles