Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist. 报错,说明 popup.js 通过 chrome.tabs.sendMessage 发送消息时,目标页面并没有注入 content script(即 content.js 未在该 tab 上运行)。
常见原因及排查建议:
-
manifest.json 未配置 content_scripts
- 检查 manifest.json 是否有如下内容:
"content_scripts": [ { "matches": ["https://chat.openai.com/*", "https://chatgpt.com/*"], "js": ["content.js"] } ] - 若无此配置,content.js 不会自动注入,导致消息无接收方。
- 检查 manifest.json 是否有如下内容:
-
目标页面未刷新
- 安装/更新扩展后,需刷新目标网页,确保 content script 注入。
-
发送消息的 tabId 不正确
- popup.js 需确保发送消息到当前激活的 tab,且该 tab 的 url 匹配 content_scripts 的 matches。
-
动态注入脚本未成功
- 若用
chrome.scripting.executeScript动态注入,需确保注入成功且 content.js 已执行。
- 若用
-
页面为特殊 iframe 或未匹配 host_permissions
- 某些 iframe 或未在 host_permissions 范围内的页面不会注入 content script。
建议操作:
- 检查 manifest.json 是否正确配置 content_scripts 和 host_permissions。
- 刷新目标网页后再点击 popup。(这点很重要)
- 在 content.js 顶部加日志,确认脚本已注入。
- 在 popup.js 发送消息前后加日志,确认 tabId 和 url。

2万+

被折叠的 条评论
为什么被折叠?



