私はcontent scripts
を使用しています。ウェブページにボタンを挿入したいと思います。Chrome拡張機能を使用してウェブページにボタンを挿入する方法
これは私のmanifest.json
次のとおりです。
{
"manifest_version": 2,
"name": "my extension",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"activeTab"
],
"content_scripts": [
{
"matches": ["http://127.0.0.1:8000/*"],
"js": ["script.js"],
"run_at": "document_end"
}
]
}
これはpopup.html
次のとおりです。
<html>
<body>
<input type="button" id="button" style="display:none;">
</body>
</html>
そしてscript.js
:
document.body.style.backgroundColor = "yellow";
var button = document.getElementById("button");
button.style.visibility = "visible";
http://127.0.0.1:8000
に行くとき、私は黄色の背景の変更を参照してください、しかし、ボタンが見つからないローカルサーバーが提供するWebページの一部ではないためです。これは、このエラーを示しています
Uncaught TypeError: Cannot read property 'style' of null
は、私は(私はその内容を知っていないと仮定)http://127.0.0.1:8000
のコンテンツの上部にあるボタンを注入するために何をすべき? DOMが完了した後