Google chrome extension 未注入Chrome扩展简单脚本
我正在尝试编写一个最小的Chrome扩展的第一步,我不明白为什么它不执行clientScript.js 这是我的manifest.json:Google chrome extension 未注入Chrome扩展简单脚本,google-chrome-extension,Google Chrome Extension,我正在尝试编写一个最小的Chrome扩展的第一步,我不明白为什么它不执行clientScript.js 这是我的manifest.json: { "name": "Sit back, relax and enjoy", "version": "0.1", "description": "Finds and clicks the +extra channel points button when it is available", "permissions": [
{
"name": "Sit back, relax and enjoy",
"version": "0.1",
"description": "Finds and clicks the +extra channel points button when it is available",
"permissions": [ "activeTab" ],
"content_scripts": [
{
"matches": [ "https://twitch.tv/*" ],
"js": [ "contentScript.js" ],
"run_at": "document_idle"
}
],
"manifest_version": 2
}
这就是我想要在匹配页面上执行的脚本https://twitch.tv/*:
我在同一文件夹中有两个文件:
此外,我已经正确安装了扩展:
控制台没有显示与扩展相关的错误
我遗漏了什么?假设您确实重新加载了选项卡,内容脚本仅在初始选项卡加载时注入,请参阅以了解更多信息和解决方法,您可能是地址栏中的错误的受害者:如果您进入编辑模式并选择/复制整个文本,或者只需双击地址,您将看到站点的URL实际上是错误的https://www.twitch.tv/ 因此,manifest.json的URL模式不正确,与实际站点不匹配 只需使用一个通用模式,如https://*.twitch.tv/*即可将两者匹配https://www.twitch.tv/ 和https://twitch.tv/ 和任何其他子域
另外,作为调试步骤,您可以通过查看devtools控制台工具栏或devtools->Sources->content scripts面板中的上下文选择器来检查内容脚本是否被注入。如果您想恢复经典的地址栏行为,请参见网站的URL实际上是https://twitch.tv 并且该脚本在“开发人员工具”的“源”面板中不可用。@connexo,假设您确实重新加载了选项卡,内容脚本仅在初始选项卡加载时注入,则您的注释只能表示manifest.json中使用的站点URL不正确。我在网站的URL中看到了www,我在回答中提到了以下步骤:
let intervalTimer
function sibareaen() {
const btn = document.querySelector('.tw-button.tw-button--success.tw-interactive')
if (btn) {
btn.click()
console.log('At your service - clicked the button for you!')
}
}
function toggleSibareaen(on) {
switch (on) {
case true:
intervalTimer = setInterval(sibareaen, 750)
break
case false:
clearInterval(intervalTimer)
break
default:
clearInterval(intervalTimer)
}
}
console.log('At your service - ready to click for you!')
toggleSibareaen(true)