我正在尝试进入 Chrome 扩展的神奇世界。现在我已经建立了我的清单,试图加载 jquery。
{
    "name": "Test Extension",
    "version": "0.1",
    "manifest_version": 2,
    "description": "First try",
    "options_page": "options.html",
    "content_scripts": [{
        "matches": ["chrome-extension://*/*"],
        "js": ["jquery.js", "popup.js"],
        "run_at": "document_end"
    }],
    "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html",
        "default_title": "Click me!"
    }
}
实际上试图重新加载扩展告诉我“匹配”不匹配有效的模式。
但这还不是全部。为了克服它,我尝试将“匹配”值更改为*://*/*并重新加载。好吧,扩展似乎加载正确,但似乎 jquery 没有加载,因为我可以从 popup.js 得到的错误告诉我
未捕获的 ReferenceError:$ 未定义
实际上HTML只是:
<!doctype html>
<html>
<head>
    <title>Test Extension</title>
    <link rel="stylesheet" style="text/css" src="style.css">
</head>
<body>
    <div id="test"></div>
</body>
</html>
<script type="text/javascript" src="popup.js"></script>
popup.js 代码就是这样做的:
$("#test").html("Foo!");