使用firefox扩展存储

时间:2016-05-05 12:32:21

标签: firefox-addon firefox-webextensions

我能以某种方式运行此扩展程序:

https://github.com/mdn/webextensions-examples/tree/master/beastify

点击浏览器图标时调用popup/choose_beast.js

有人可以告诉我为什么这段代码(放在popup/choose_beast.js的顶部)会产生异常:

try{
var ss = require("sdk/simple-storage");
ss.storage.myArray = [1, 1, 2, 3, 5, 8, 13];
}catch(e){
    alert('exception');
    console.log(e);
}

以下是manifest.json中的相关条目:

 "browser_action": {
    "default_icon": "icons/beasts-32.png",
    "default_title": "Beastify",
    "default_popup": "popup/choose_beast.html"
}

我可以在此弹出式html中存储数据的方式是什么,以便我可以随时在内容脚本中检索?

此页面还在哪个上下文中select_beast.html正在运行?背景,页面脚本或内容脚本?

1 个答案:

答案 0 :(得分:2)

网络扩展程序应该使用storage API来实现此目的。

Here是一个示例用法。