Chrome扩展程序上的桌面通知无法正常运行

时间:2019-04-01 11:02:19

标签: javascript json google-chrome-extension manifest.json

查找信息后,我无法使它正常工作,我使用的最后一个示例是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);
});

我希望每次页面外观发生变化时都会收到桌面通知

0 个答案:

没有答案