此问题已在此处有答案:
In a Chrome Extension content script, must I wait for document.ready before processing the document?(2个答案)
8天前关闭
我正在开发一个Chrome扩展程序,我有以下文件。
但是当我打开https://example.com/时,h1标题没有更新。
我在开发控制台中没有看到任何错误。我错过了什么?
manifest.json
{
"manifest_version": 3,
"name": "Print Hello",
"version": "1.0",
"icons": {
"48": "images/icon-48.png"
},
"action": {
"default_icon": {
"48": "images/icon-48.png"
},
"default_title": "Print Hello"
},
"content_scripts": [
{
"matches": ["https://example.com/"],
"js": ["./scripts/jquery.min.js", "./scripts/print_hello.js"]
}
],
"host_permissions": [
"https://example.com/"
]
}
print_hello.js
function print_hello() {
document.querySelector("div h1").innerText = "Hello!"
}
$(document).on("load", print_hello)
1条答案
按热度按时间ncgqoxb01#
你能试着在文档准备好的情况下修改你的代码吗?
所以
print_hello.js
将是