【问题标题】:chrome extension permissions not workingchrome扩展权限不起作用
【发布时间】:2016-08-17 08:55:11
【问题描述】:

我的 chrome 扩展的结构是这样的:

background.html
background.js
javascripts/angular...
javascripts/webRTC...

在 background.js 中,我使用的是 firebase 的 datachannel.js 库,它本质上创建了对 firebaseio.com 的远程调用

var socket = new window.Firebase('https://' + 
    (self.firebase || 'webrtc-experiment') + '.firebaseIO.com/' + channel);

chrome 将此错误返回到控制台:

Refused to load the script 'https://webrtc-experiment.firebaseio.com/.lp?start=t&ser=24080204&cb=23&v=5' because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:". (anonymous function) @ firebase.js:168

这里是 manifest.json:

 "manifest_version": 2,
    "background": {
        "page": "background.html"
    },
    "browser_action": {
        "default_popup": "main.html",
        "default_icon": "icon.png",
        "default_title": "title"

    },
    "minimum_chrome_version": "37.0",
    "name": "chromeextensionname",
    "permissions": [
        "<all_urls>",

【问题讨论】:

    标签: javascript html google-chrome google-chrome-extension


    【解决方案1】:

    在 manifest.json 中使用 content-security-policy 解决

    "content_security_policy": "script-src 'self' https://*.firebase.com https://*.firebaseio.com; object-src 'self'",
    

    参考:

    https://developer.chrome.com/extensions/contentSecurityPolicy

    How to set Content Security Policy in Chrome Extension Manifest.json in order for Firebase to work

    【讨论】:

      猜你喜欢
      • 2014-05-25
      • 2014-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      • 2017-05-26
      • 2012-01-22
      • 2012-08-08
      相关资源
      最近更新 更多