javascript - Chrome 扩展 "Refused to load the script because it violates the following Content Security Policy directive"

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

我正在尝试创建一个 Chrome 扩展,但我的 JS 都不起作用。控制台显示此错误:

Refused to load the script 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js' because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".

为什么它会阻止我的 jQuery 运行?

最佳答案

正如在 Chome 上解释的那样 website , 有一个内容安全策略阻止您的脚本加载远程脚本:

A relaxed policy definition which allows script resources to be loaded from example.com over HTTPS might look like:

"content_security_policy": "script-src 'self' https://example.com; object-src 'self'"

所以在你的情况下,manifest.json 应该包含:

 {
  "name": "My Extension",
  "manifest_version": 2,
  "background":{
     "scripts": [...]
  },
  "content_security_policy": "script-src 'self' https://example.com; object-src 'self'",
 }

关于javascript - Chrome 扩展 "Refused to load the script because it violates the following Content Security Policy directive",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34950009/

相关文章:

javascript - 在网站上提前加载数据?

javascript - 如何在JS中剪切音频mp3 Blob

javascript - html - 如何在 Firefox、Opera、Safari 下增加单选按钮的大小

javascript - 突出显示 DOM 范围元素的文本,

javascript - 使用 jQuery 将 html 添加到 DOM

html - 外部文件加载主页 CSS 文件

html - 如何使 iframe 静音?

javascript - SendGrid 客户端 TypeScript 错误 : HttpMethod

javascript - jQuery 是否有等效的 Request.IsMvcAjaxRequest()?

javascript - 再次单击头部时关闭 Accordion