chrome 提示报错 Error handling response: TypeError: Cannot read properties of undefined (reading 'executeScript')
在 ChatGPT 的帮助下写了一个 Chrome 小插件,结果报错:
chrome 提示报错 Error handling response: TypeError: Cannot read properties of undefined (reading 'executeScript')
解决方法
这是因为 chrome.scripting 不是标准的 Chrome Extension API。从 Chrome 88 开始,chrome.scripting 被引入作为一个实验性 API,用于替代 chrome.tabs.executeScript。
如果你想要使用 chrome.scripting.executeScript,你需要在 manifest.json 中声明以下权限:
"permissions": ["scripting"]
整个的 mainfest.json 就变成了:
{
"manifest_version": 3,
"name": "CroWall Image Downloader",
"version": "1.0",
"description": "Download all images from a webpage and save them to a folder in Downloads.",
"permissions": [
"activeTab",
"downloads",
"scripting"
],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["https://crowall.com/*"],
"js": ["content.js"]
}
],
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icons/icon.png",
"48": "icons/icon.png",
"128": "icons/icon.png"
}
}
}
刷新后执行,问题解决。