文章目录

  • 1. 文章引言
  • 2. 分析问题
  • 3. 解决问题
  • 4. 解决该错误的其他方法

1. 文章引言

今天启动项目后访问Knife4j接口文档,却报出下图错误:

在报出Knife4j文档请求异常错误时,赶紧打开控制台,如下所示:

Unchecked runtime.lastError: The message port closed before a response was received.

2. 分析问题

正赶上最近ChatGPT很火,于是借助ChatGPT来解决我的问题,如下所示:

Unchecked runtime.lastError: The message port closed before a response was received.

This error occurs when a message port fails to respond within a specified time frame, which means that the browser was unable to send data or receive a response from the server. This could be caused by an issue with the connection between the browser and the server, an issue with the server, or an issue with the messaging system between the browser and the server.

不巧的是,给出的是英文回复,我们可以将其翻译成中文,如下所示:

当消息端口无法在指定的时间范围内响应时,会发生此错误,这意味着浏览器无法发送数据或接收来自服务器的响应。这可能是由浏览器和服务器之间的连接问题、服务器问题或浏览器和服务器之间的邮件系统问题引起的。

简单理解ChatGPT的回复,即服务端无法在指定时间内,给到客户端的响应。

如果客户端的代码引入某一插件(比如vue,react等),而该插件中某一脚本页在接不到响应时,又使用了chrome.runtime.sendMessage或者tabs.sendMessage并调用了回调函数而接收函数并没调用导致的。

为了验证这个错误,我们使用node.js来写一段简单前后端代码,如下所示。

  1. 前端的简单代码(front-script.js):
//ront-script.js简单代码
chrome.runtime.sendMessage({action: "server",source: "test Unchecked runtime.lastError",
},function(e){alert('ok');
});

上面的函数发送了test Unchecked runtime.lastError消息,并调用了回调函数用来alter(‘ok’)

  1. 后端的简单代码(backend.js):
//backend.js简单代码
chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {if (request.action === "server") {var a= 0;}}
);

如果后端只处理逻辑,并不调用回调函数sendResponse(),就会出现这个错误:Unchecked runtime.lastError: The message port closed before a response was received.

3. 解决问题

backend.js中正确的处理方法是:

// backend.js正确的代码
chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {if (request.action === "server") {var a= 0;//注意就是这个sendResponse函数一定要调用,否则就会报错sendResponse({farewell: "ok"});  } }
);

也就是说sendResponse({farewell: "ok"})这一段不调用的话就会报这个错误:Unchecked runtime.lastError: The message port closed before a response was received

但是很多情况下并没有调用,而发送函数自己却使用到了,从而导致这个错误。

如果上述方法无法解决你的问题,可以参考下面的解决方法。

4. 解决该错误的其他方法

如果你在chrome中引入了某一扩展程序,比如vueVideo Speed Master等,有可能会因为插件和程序不兼容导致这个错误:Unchecked runtime.lastError: The message port closed before a response was received

解决方法:只要在chrome://extensions/里面把这个阅读模式关闭就可以,如下图所示:

如果还是无法解决你的问题,欢迎在评论区中留言。

如果你的错误不是通过以上方法解决的,也欢迎在评论区中留言。

全网多种方式解决Unchecked runtime.lastError: The message port closed before a response was received的错误相关推荐

  1. 谷歌浏览器插件扩展引起的报错 Unchecked runtime.lastError: The message port closed before a response was received.

    Unchecked runtime.lastError: The message port closed before a response was received.7Error handling ...

  2. 全网多种方式解决The requested resource [/] is not available的错误

    文章目录 1. 复现错误 2. 分析错误 3. 解决错误 3.1 本地项目 3.2 线上项目 4. 此错误的其他解决方法 1. 复现错误 曾记得,当初使用idea来写Java web项目时,常常因为T ...

  3. Chrome报错:Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

    Chrome报错:Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist. ...

  4. 报错:Unchecked runtime.lastError:Could not establish connection. Receiving end does not exist.

    报错:Unchecked runtime.lastError:Could not establish connection. Receiving end does not exist. 解决办法: 打 ...

  5. unchecked runtime.lasterror: cannot create item with duplicate id XXX 谷歌浏览器扩展插件开发问题

    在开发谷歌浏览器插件时候注册了一个右键菜单 每次刷新页面的时候就会出现这个重复添加的错误 unchecked runtime.lasterror: cannot create item with du ...

  6. Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

    控制台报错:Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist. 发现是 ...

  7. 成功解决:http.client.RemoteDisconnected: Remote end closed connection without response

    成功解决:http.client.RemoteDisconnected: Remote end closed connection without response 问题描述 运行程序超时,有时可以正 ...

  8. Java多种方式解决生产者消费者问题(十分详细)

    一.问题描述 生产者消费者问题(Producer-consumer problem),也称有限缓冲问题(Bounded-buffer problem),是一个多线程同步问题的经典案例.生产者生成一定量 ...

  9. 多种方式解决Java控制台报错 java.util.LinkedHashMap cannot be cast to.....

    问题描述 今天在使用RestTemplate调用服务的时候,因为服务提供者返回的是一个List集合,所以在使用消费者调用的时候,restTemplate.getForObject()期待返回的类型直接 ...

最新文章

  1. 对于计算机网络的整体框架的概括(转载) 个人感觉很好
  2. Codeforces数学1600----day1[同余定理,树状数组+两次二分,,组合计数]
  3. CSS0 -- 静态、自适应、流式、响应式
  4. hadoop-0.21.0 在Windows环境下的部署(2)Hadoop配置
  5. [bzoj4625][BeiJing2016]水晶
  6. linux串口对调,Linux串口调试详解
  7. C++字节存储方式和reinterpret_cast
  8. 编写高质量代码 —— 异常退出条件的判断
  9. 《深度学习》李宏毅 -- task5网络技巧设计
  10. VTDecompressionSessionDecodeFrame -8969
  11. Python动态数据展示
  12. UEdit初始化加载内容偶尔失败,解决
  13. 刷屏代码·稳 from林凯
  14. Spring 事务管理高级应用难点剖析: 第 3 部分
  15. lants vs Zombies 阳光修改器
  16. Ubuntu Linux,及Python matplot,安装Times New Roman等字体,让图标签可以用Times New Roman等字体
  17. Vue.js框架(二)
  18. repo拉代码The remote end hung up unexpectedly解决方法
  19. 我是斗图王之python爬取表情包
  20. segy和su文件格式说明

热门文章

  1. ubuntu下跑魔兽世界
  2. 麦克纳姆轮PID控制原理
  3. NFC开发 —————ID卡、IC卡(M1卡、CPU卡)的区别(三)
  4. Day 25 - HBuilder X 产生 apk
  5. 蓝桥杯垒骰子(动态规划)
  6. 逆战关于Vue学习的一点心得
  7. Unity GalGame插件 GalForUnity节点大全ChangeRoleDataNode 变更角色数据节点
  8. 【Debug经验】低电压电流模Bandgap电路DC温度曲线异常
  9. NANK南卡护眼台灯Pro新品测评:旗舰级护眼,降低80%近视风险!
  10. 【python】pyplot绘制横轴为时间的图