Chrome扩展程序 - 通知只适用于apache

时间:2015-01-25 00:23:50

标签: google-chrome-extension notifications

我已将Chrome扩展程序配置为发送通知,如下所示:

enter image description here

我有一个按钮,其中有一个调用createNotification的事件。但是如果我在apache上运行扩展程序,按钮就会发送通知。

我做错了什么?

等于示例http://jsbin.com/ziwod/1/edit?html,js,output 对我来说,这个例子只是在我点击"用JS运行"。

时工作

这是我的清单

    {
  "name": "EXTENSION EXAMPLE",
  "version": "0.0.1",
  "manifest_version": 2,
  "description" : "This extension is...",
  "icons": { "16": "icons/16x16.png", "48": "icons/48x48.png", "128": "icons/128x128.png" },

  "omnibox": { "keyword" : "example" },

  "browser_action": {
    "default_icon": {
      "19": "icons/19x19.png",
      "38": "icons/38x38.png"
    },
    "default_title": "Launcher",
    "default_popup": "browseraction/popup.html"
  },

  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "permissions" : ["notifications"],
  "options_page" : "notification.html",
  "chrome_url_overrides" : {
   "newtab": "newtab/newtab.html"
  },

  "devtools_page": "devtools/devtools.html"
}

这是我的 notification.html http://codepen.io/anon/pen/VYWQwB

1 个答案:

答案 0 :(得分:1)

从您的html文件和"manifest_version": 2的清单文件中默认启用Content Security Policy。 Chrome开发人员选择严格控制并始终禁止使用内联JavaScript代码 - 只允许执行放置在外部JavaScript文件中的代码(以防止扩展中的跨站点脚本漏洞)。因此,您的html文件中不允许<button onclick="notifyMe()">onclick属性是内联脚本。您应该改为指定ID属性:<button id="button">