【发布时间】:2017-06-08 14:28:30
【问题描述】:
我使用的是开发者版本的 Firefox(版本 54.0a2,但也尝试了版本 51 的普通 Firefox),我想在我的网络扩展中包含通知。
browser["notifications"] 不存在。
由于它在我的扩展程序中不起作用,并且我认为可能存在冲突,我创建了这个非常基本的网络扩展程序。
manifest.json:
{
"manifest_version": 2,
"name": "Extension",
"version": "1.0",
"description": "...",
"icons": {
"48": "icons/icon-48.png"
},
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*"
],
"js": ["test.js"]
}
],
"permissions": ["notifications", "storage"]
}
test.js(顺便说一句,存储工作得很好。)
if (browser["notifications"]) {
console.log('Notifications exist!');
browser.notifications.create({
"type": "basic",
"iconUrl": browser.extension.getURL("icons/icon-48.png"),
"title": "test",
"message": "test"
});
}
else {
//it always executes this part :/
console.log('notifications do not exist');
console.log(browser);
}
调试插件也不会显示任何错误。
【问题讨论】:
-
我认为您需要在后台脚本中创建通知。这里有一个简单的例子:github.com/mdn/webextensions-examples/tree/master/…
-
谢谢,现在可以使用了!
标签: javascript firefox notifications firefox-addon-webextensions