Chrome 扩展程序弹出窗口中的 Google 图表?

Zha*_*for 4 javascript google-chrome google-visualization google-chrome-extension

我想让我的 Chrome 扩展程序的弹出页面显示一个 Google 图表,显示有关用户新闻阅读习惯的信息。我注意到(特别是在这里:Chrome 扩展程序不起作用),这个问题是 Chrome 扩展程序不允许内联脚本,这使得包含使用 Google Chart 所需的 API 文件变得复杂。有没有解决的办法?是否有地方可以下载整个 API 以简单地包含在我的扩展中?

Xan*_*Xan 5

原则上,扩展可以使用违反 CSP 的库。然而,这需要一个额外的框架来跳跃:沙盒

  "sandbox": {
    "pages": [
      "sandbox.html"
    ]
    "content_security_policy":
        "sandbox allow-scripts; script-src 'self' 'unsafe-eval' https://www.google.com/jsapi"
  ],
Run Code Online (Sandbox Code Playgroud)

它是专门为了解决这个问题而创建的。请参阅“在 Chrome 扩展中安全地使用 eval”。实施细节指南。

您需要在普通脚本和沙箱之间传达结果,因为沙箱页面没有 Chrome API 访问权限。