Firefox Add-on dev,如何在Addon Builder中使用MDN中的示例代码

时间:2021-02-20 07:16:14

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

我正在使用添加构建器来构建扩展,当我搜索MDN时,我找不到如何在在线插件构建器中调用它们的接口

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

不构建并导致XPI错误

1 个解决方案

#1


3  

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.

而不是Components.classes尝试使用Cc,而不是Components.interfaces尝试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.

这应该工作,如果没有,将链接放到您的公共插件或代码示例并链接到文档站点。

#1


3  

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.

而不是Components.classes尝试使用Cc,而不是Components.interfaces尝试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.

这应该工作,如果没有,将链接放到您的公共插件或代码示例并链接到文档站点。