位置: IT常识 - 正文

Google Chrome 插件开发: 无法建立连接, 接收端不存在. Could not establish connection. Receiving end does not exist(谷歌插件下载网址)

编辑:rootadmin
Google Chrome 插件开发: 无法建立连接, 接收端不存在. Could not establish connection. Receiving end does not exist 通过以下代码向当前页面发送 “start” 消息:chrome.tabs.query({active: true,currentWindow: true}, tabs => { let tab = tabs[0]; chrome.tabs.sendMessage(tab.id, "start");});报错:Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist.可能的原因:

推荐整理分享Google Chrome 插件开发: 无法建立连接, 接收端不存在. Could not establish connection. Receiving end does not exist(谷歌插件下载网址),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:googlechrome插件chatGPT,谷歌 插件,googlechrome插件被阻止不能允许,googlechrome插件被阻止不能允许,谷歌 插件,googlechrome插件chatGPT,googlechrome插件被阻止不能允许,googlechrome插件chatGPT,内容如对您有帮助,希望把文章链接给更多的朋友!

接收端, 也就是说目标页面必须有 chrome.runtime.onMessage 监听消息, 如果 “content-script” 没有注入到页面中, 那么这个页面就无法接收消息

Google Chrome 插件开发: 无法建立连接, 接收端不存在. Could not establish connection. Receiving end does not exist(谷歌插件下载网址)

如果你的插件刚刚加载, 并且在一个已经加载完毕的页面中使用它, 则会出这个问题.

因为这个页面已经加载完了, 它并没有被注入脚本, 你需要刷新页面, 使脚本注入到页面中, 然后才可以发送消息

平台不允许文章内容太少, 下面是水

sendMessage chrome.tabs.sendMessage(integer tabId, any message, function responseCallback) 向指定标签页中的内容脚本发送一个消息,当发回响应时执行一个可选的回调函数。当前扩展程序在指定标签页中的每一个内容脚本都会收到 runtime.onMessage 事件。

参数类型tabIdintegermessageanyresponseCallbackoptional function

如果您指定了 responseCallback 参数,它应该指定一个如下形式的函数:

function(any response) {…}; response ( any ) 请求处理程序发出的 JSON 响应对象。如果连接到指定标签页的过程中发生错误,将不传递参数调用回调函数,并将 runtime.lastError 设置为错误消息。

本文链接地址:https://www.jiuchutong.com/zhishi/295995.html 转载请保留说明!

上一篇:html 隐藏和显示(html怎么设置隐藏元素)

下一篇:难以置信,已经有人用 ChatGPT 做 Excel 报表了?(难以置信含义)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络