查找信息后,我无法使它正常工作,我使用的最后一个示例是Desktop notifications from content scripts
我有一个background.html
<script src="bg.js" ></script>
bg.js
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
// Create a simple text notification:
var notify = webkitNotifications.createNotification(
'icon.png', // icon url - can be relative
'Hello!', // notification title
request.msg // notification body text
);
notify.show();
setTimeout(function(){ notify.cancel(); },5000);
sendResponse({returnMsg: "All good!"}); // optional response
});
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.sendMessage(tab.id, {});
});
manifest.json
{
"manifest_version": 2,
"name": "Checker",
"description": "Checker",
"version": "1.0",
/* "background":{
"persistent":true,
"page":"background.html"
},
"browser_action": {
"default_icon": "icon.png"
},
*/
"content_scripts": [
{
"matches": ["https://www.google.es/*"],
"js": ["jquery.min.js", "cs.js"],
"run_at": "document_end"
}
],
"permissions": ["notifications","activeTab", "https://www.google.es/*"]
}
最后是我的cs.js(这只是调用通知的代码的一部分,其余的都可以很好地执行。
chrome.extension.sendRequest({msg: "Sup?"}, function(response) { // optional callback - gets response
console.log(response.returnMsg);
});
我希望每次页面外观发生变化时都会收到桌面通知