1
<!--
You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>
      Google Visualization API Sample
    </title>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {packages: ['corechart']});
    </script>
    <script type="text/javascript">
      function drawVisualization() {
        // Create and populate the data table.
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work', 11],
          ['Eat', 2],
          ['Commute', 2],
          ['Watch TV', 2],
          ['Sleep', 7]
        ]);

        // Create and draw the visualization.
        new google.visualization.PieChart(document.getElementById('visualization')).
            draw(data, {title:"So, how was your day?"});
      }


      google.setOnLoadCallback(drawVisualization);
    </script>
  </head>
  <body style="font-family: Arial;border: 0 none;">
    <div id="visualization" style="width: 600px; height: 400px;"></div>
  </body>
</html>

上面的代码在一个 html 文件中为我们生成了一个饼图。当我在浏览器中打开它时它可以工作。让我们调用文件popup.html

然后我想用以下清单文件使它成为一个 Chrome 扩展:

{
  "name": "History Visualizer",
  "version": "1.0",
  "manifest_version": 2,
  "description": "Helps us analyze history stats in a visual way",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  }
}

但是当我点击图标按钮时,饼图将无法加载。有人帮我吗?

编辑:检查弹出窗口后的错误消息如下。

由于 Content-Security-Policy,拒绝从“http://www.google.com/jsapi”加载脚本。由于 Content-Security-Policy 拒绝执行内联脚本。

​</p>

4

1 回答 1

1

您需要为您的扩展程序指定权限manifest.json才能使用以下资源google.com

"permissions": [
  "http://*.google.com/"
],

或者,如果这不起作用,请尝试允许您的扩展程序访问所有URL:

"permissions": [
  "<all_urls>"
],

在此处阅读有关权限的更多信息。

于 2012-05-29T12:57:57.620 回答