【发布时间】:2014-01-17 20:11:39
【问题描述】:
我想在 $window.ready 事件之前从 chrome 扩展执行代码。
显然 "runs_at": "document_start" 应该可以工作,according to Google:
在“document_start”的情况下,文件是在任何来自 css 的文件之后注入的,但在构造任何其他 DOM 或运行任何其他脚本之前。
但是,它似乎不起作用。以下代码:
manifest.json:
{
"name": "Testextension Extension",
"manifest_version": 2,
"version": "0.1",
"content_scripts": [{
"matches": [
"file:///C:/test.html"
],
"js": ["test.js"],
"runs_at": "document_start"
}]
}
test.js:
console.log("the extension content script is happening");
test.html:
<html>
<head>
<script src="jquery.min.js"></script>
<script type="application/javascript">
console.log ("script is happening in page");
$(window).ready(function () {console.log("window.ready is happening");});
$(document).ready(function () {console.log("document.ready is happening");});
</script>
</head>
<body>
</body>
</html>
提供以下控制台输出:
script is happening in page
window.ready is happening
document.ready is happening
the extension content script is happening
我不拥有我的扩展程序应该运行的页面,因此我无法修改它以在我的 Chrome 扩展程序之后执行。
是我做错了什么,还是 Chrome 有问题?
我能做什么?
编辑:这是关于我使用“runs_at”而不是“run_at”吗?
edit2:抱歉,好像是这样。
【问题讨论】:
-
如何标记为已解决?
-
谢谢,但我将不得不等待。 “声望低于 10 的用户在提问后 8 小时内无法回答自己的问题。您可以在 2013 年 12 月 31 日上午 5:44:14 回答。在此之前请使用 cmets,或改为编辑您的问题。”跨度>
-
请明天发表您的答案,并在新的一年接受它。谢谢:)
标签: javascript jquery google-chrome-extension