javascript - 将 Dropbox API 脚本加载到 Chrome 扩展程序时出错

标签 javascript google-chrome-extension dropbox-api

我正在尝试在 chrome 扩展中使用 dropbox api,但控制台显示

Refused to load the script 'https://www.dropbox.com/static/api/1/dropins.js' because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:"

如何解决这个问题?

我把 “权限”:[ “https://www.dropbox.com” ]

但是还是不行

最佳答案

如果您需要从外部域加载脚本,您的扩展程序必须

  1. 在权限中包含外部脚本的域
  2. 它必须是 https 资源

我发现您已经加载了 https:,因此只需将 https://www.dropbox.com 添加到您的权限中就可以解决此问题。

权限应如下所示:

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

Content Security Policy Documentation阅读此内容

If you have a need for some external JavaScript or object resources, you can relax the policy to a limited extent by whitelisting secure origins from which scripts should be accepted. We want to ensure that executable resources loaded with an extension's elevated permissions are exactly the resources you expect, and haven't been replaced by an active network attacker

关于javascript - 将 Dropbox API 脚本加载到 Chrome 扩展程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20416198/

相关文章:

android - Dropbox Sync API - 不满意的链接错误

ios - iOS 上的 Dropbox API 无法链接

google-chrome-extension - 使用 Chrome 扩展跟踪用户事件

javascript - 将图像叠加在图像之上

javascript - emberJS 挤压 nwJS require() 方法

javascript - Webpack dev-server - 如何提供带有更新 Assets 的静态文件?

google-chrome-extension - Chrome 扩展程序在 "Publishing in progress"中停止

javascript - chrome.storage.local.set 不会在本地保存数据

ios - 如何在 Swift 中获取与 dropbox api 的共享链接?

javascript - 使用 Prototype 将窗口滚动到沿 y 轴居中?