从本地HTML访问chrome。* API

时间:2014-01-17 23:37:32

标签: google-chrome google-chrome-extension

我正在开发Chrome扩展程序。这就是我的扩展程序的结构:

我定义了一个浏览器操作,点击它会加载本地HTML文件 default.html 。这是我的清单文件:

{
    "name": "Example Extension",
    "version": "0.1",
    "manifest_version": 2,
    "browser_action": {
        "default_title": "Does nothing.",
        "default_icon": "icon.png"
    },
    "background": {
        "scripts": ["extension.js"]
    },
    "permissions": ["tabs"]
}

这是我的 extension.js

chrome.browserAction.onClicked.addListener(function(tab) {
    var newURL = chrome.extension.getURL('default.html');
    chrome.tabs.create({ url: newURL });
});

这是我的 default.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" href="jquery-1.10.2.min.js"></script>
    <script type="text/javascript" href="donothing.js"></script>
</head>
<body>
    <b>It works!</b>
</body>
</html>

我想在 donothing.js 中访问chrome当前打开的标签页,并在default.html中显示一些统计信息。我了解到我无法在 donothing.js 中访问chrome。* API。如果我正确理解了文档,我应该声明并定义content script并将消息传递为 donothing.js - &gt; contentscript.js - &gt; extension.js ,反之亦然,实现我想要的。有更简单的方法吗?有人可以在这里解释对内容脚本的需求吗?

谢谢,

0 个答案:

没有答案