Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using add on builder to build extensions when searching MDN I find interfaces that I can't figure how to call them in online addon builder

for example this code

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

doesn't build and results in XPI error

like image 256
capadleman Avatar asked Oct 21 '22 15:10

capadleman


1 Answers

On the top of your document put line:

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

and instead of Components.classes try using Cc, instead of Components.interfaces try Ci.

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

This should work, if not, put link to your public addon or sample of code and link to documentation site.

like image 102
Tomasz Dzięcielewski Avatar answered Oct 27 '22 11:10

Tomasz Dzięcielewski