[英]SimpleStorage with Firefox Addon SDK
I'm working on an extension for Firefox v.42.0. 我正在为Firefox v.42.0扩展。 In it, I have the Addon and on detecting a certain page, the addon injects some code into the page DOM.
在其中,我具有插件,并且在检测到某个页面时,插件将一些代码注入页面DOM中。 I am trying to use
var simpleStorage = require("sdk/simple-storage");
我正在尝试使用
var simpleStorage = require("sdk/simple-storage");
to include simpleStorage. 包括simpleStorage。 I save the variable as follows
我将变量保存如下
simpleStorage.storage.token = $value;
and then trying to access the simpleStorage in the injected code as follows 然后尝试按如下所示访问注入代码中的simpleStorage
if (private_self_options === undefined)
var private_self_options = self.options;
var token = private_self_options.simpleStorage.storage.token;
However, this always returns an empty string. 但是,这总是返回一个空字符串。 Could someone please point out my mistake?
有人可以指出我的错误吗?
You can get the contents of simpleStorage.storage.token
into token
with simply 您可以简单地将
simpleStorage.storage.token
的内容放入token
var token = simpleStorage.storage.token
self.options
is for use on the content script side, as shown here . self.options
是在内容脚本端使用,如图所示这里 。 Using it to pass information from simple-storage might be done thus: 因此,可以使用它来传递来自简单存储的信息:
tab.attach({
contentScriptFile: "./content-script.js",
contentScriptOptions: {
token: simpleStorage.storage.token
}
});
In that case, your assignment statement in ./content-script.js
would be 在这种情况下,您在
./content-script.js
的赋值语句将是
var token = self.options.token;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.