我已经仔细阅读了所有chrome.tabs.executeScript文档和所有问题。似乎什么都没用...我尝试过的代码是-
清单:
{
"name": "A de test",
"version": "0.0.1",
"manifest_version": 2,
"description": "YEET",
"homepage_url": "https://www.youtube.com/channel/UCbmPRCzP88oaId-4piz5Weg",
"icons": {
"128": "icons/Icon-128.png"
},
"default_locale": "en",
"browser_action": {
"default_icon": "icons/Icon-128.png",
"default_title": "GAME HUB.io TESTING",
"default_popup": "src/html/popup.html"
},
"permissions": [
"activeTab",
]
}
HTML(src / html / Popup.html)+ JS(Popup.js):
document.getElementById("Mr_Button-Click_Extend").addEventListener("click", function() {
chrome.tabs.executeScript(null, {
file: 'inject.js'
});
});
<!DOCTYPE html>
<html>
<head>
<script src="popup.js" type="application/javascript"></script>
</head>
<body>
<button id="Mr_Button-Click_Extend">hello this is a test</button>
</body>
</html>
Inject.js:
document.body.bgColor='red'
我已经使用 all 的权限进行了尝试,所以我怀疑是...我还修改了代码,以使错误日志消失了...因此,除非它是未列出的错误,否则正在发生或者只是我的浏览器出现故障(我通常使用Opera ...但我使用的是chrome,并且也测试了我在其中找到/修改过的所有方法)。
有人可以提供帮助吗?我不知道我在这里做错了什么...
答案 0 :(得分:0)
1. Move popup.js script tag down before the closing tag of body or wrap the code in DOMContentLoaded listener, 2. document.body.style.backgroundColor = 'red'
– wOxxOm