我正在尝试将 google+ API 与我的 google chrome 扩展程序集成。我的集成基于这里介绍的这个快速入门示例: https://developers.google.com/+/quickstart/javascript
我已将所有内联 javascript 代码迁移到单独的文件,在我的 manifest.json 文件中添加了 content_security_policy 行:
"content_security_policy": "script-src 'self' https://www.googleapis.com/ https://plus.google.com/ https://apis.google.com/ https://accounts.google.com/ https://ssl.gstatic.com https://csi.gstatic.com https://developers.google.com; object-src 'self'"
问题如下。当我点击 Google+ 按钮时,我收到以下错误消息:
Refused to execute JavaScript URL because it violates the following Content Security Policy directive:
"script-src 'self' https://www.googleapis.com/ https://plus.google.com/ https://apis.google.com/ https://accounts.google.com/ https://ssl.gstatic.com https://csi.gstatic.com https://developers.google.com"
.
这显然对 content_security_policy 不满意。它在这个文件的第 468 行抛出这个异常:
它似乎试图嵌入内联脚本并在之后执行它,这违反了内容安全策略。 当我在弹出窗口中单击“接受”按钮时,会出现相同的异常。结果弹出窗口挂起而没有响应。
你有这方面的经验吗?
最佳答案
在您的 manifest.json
中试试这个:
"content_security_policy": "script-src 'self' 'unsafe-eval' https://apis.google.com/; object-src 'self'"
关于google-chrome-extension - Google+ 集成 Chrome 扩展问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18194659/