Javascript 内容脚本通知
我遇到了麻烦,在这里没有找到任何其他答案:/ 舱单:Javascript 内容脚本通知,javascript,html,google-chrome,google-chrome-extension,Javascript,Html,Google Chrome,Google Chrome Extension,我遇到了麻烦,在这里没有找到任何其他答案:/ 舱单: { "name": "Item Sniper", "version": "1.0", "description": "Sniper", "browser_action": { "default_icon": "face.png", "default_title": "Sniper" }, "background": { "scripts": ["background.js"]
{
"name": "Item Sniper",
"version": "1.0",
"description": "Sniper",
"browser_action": {
"default_icon": "face.png",
"default_title": "Sniper"
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"tabs",
"notifications",
"http://*/*"
]
}
Background.js:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null,{file: "buy.js"});
}
);
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
var notify = webkitNotifications.createNotification(
'face.png', // icon url - can be relative
'Hello!', // notification title
'Oh hellow!' // notification body text
);
});
Buy.js[还有更多内容,但这是通知部分]:
chrome.extension.sendRequest({msg: "Sup?"}, function(response) { // optional callback - gets response
console.log(response.returnMsg);
});
我基本上希望内容脚本创建一个通知,但我不知道在坚持使用js脚本作为背景时是否可能:/
谢谢你的帮助,
Alex仅适用于使用的清单。如果您想支持此功能,您需要将清单更新为以下内容:
{
姓名:项目狙击手,
版本:1.0,
描述:狙击手,
清单版本:2,
最低版本:18,
浏览器操作:{
默认图标:face.png,
默认标题:狙击手
},
背景:{
脚本:[background.js]
},
权限:[
标签,
通知,
http://*/*
]
}
请注意,我还将minimum_chrome_version属性设置为18,因为清单版本2只能在针对此版本的chrome或更新版本时使用。我认为您错过了调用notify.show;在您的background.js中
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
var notify = webkitNotifications.createNotification(
'face.png', // icon url - can be relative
'Hello!', // notification title
'Oh hellow!' // notification body text
);
notify.show();
});
但我不知道在坚持使用js脚本作为背景的情况下是否可行,为什么它不能工作?你测试过了吗?