Google chrome extension 无法读取属性';executeScript';未定义的
我遵循了chrome扩展的“入门”教程,但我发现了以下错误 我搜索谷歌,有人说无法访问content.js中的“executeScript”,但错误来自popup.js 我曾尝试将“chrome.scripting.executeScript”更改为“chrome.tabs.executeScript”,但效果不佳 manifest.jsonGoogle chrome extension 无法读取属性';executeScript';未定义的,google-chrome-extension,Google Chrome Extension,我遵循了chrome扩展的“入门”教程,但我发现了以下错误 我搜索谷歌,有人说无法访问content.js中的“executeScript”,但错误来自popup.js 我曾尝试将“chrome.scripting.executeScript”更改为“chrome.tabs.executeScript”,但效果不佳 manifest.json { “名称”:“入门示例”, “版本”:“1.0”, “说明”:“生成扩展!”, “权限”:[“存储”、“声明性内容”、“活动选项卡”], “背景”:
{
“名称”:“入门示例”,
“版本”:“1.0”,
“说明”:“生成扩展!”,
“权限”:[“存储”、“声明性内容”、“活动选项卡”],
“背景”:{
“脚本”:[“background.js”],
“持续”:假
},
“页面操作”:{
“默认弹出窗口”:“popup.html”
},
“选项页面”:“options.html”,
“清单版本”:2
}
您需要迁移到manifest v3,或者使用chrome.tabs.executeScript
而不是chrome.scripting.executeScript您的manifest.json
中的权限缺少一项,即“scripting”
应该是这样的:
…
"permissions": ["storage", "declarativeContent", "activeTab", "scripting"],
…
这实际上可以在上看到。在我的例子中,异常日志“无法读取未定义的属性'executeScript'”非常容易引起误解
有了正确的清单,事情就发生了,这是因为待注入函数中的输入错误,如下所示
document.body.style.backgroundColor=颜色
更正为
document.body.style.backgroundColor=颜色
它成功了