未捕获错误的原因:尝试使用断开的端口对象 [英] Reason for Uncaught Error: Attempting to use a disconnected port object

查看:1357
本文介绍了未捕获错误的原因:尝试使用断开的端口对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在响应从内容脚本请求
时,我在后台页面中收到此错误。
有人知道是什么原因导致了这个错误吗?

完整堆栈跟踪:

 未捕获错误:尝试使用已断开连接的端口对象chrome / RendererExtensionBindings:147 
chrome.Port.postMessage chrome / RendererExtensionBindings:147
chromeHidden.Port.dispatchOnConnect.connectEvent chrome / RendererExtensionBindings :89
myExtension.foo.sendResponse.state background.js:1573
db.readTransaction.tx.executeSql.paramStr background.js:1038

只有在浏览器重新加载扩展数小时后才会发生这种情况 - 这并不是说在重新启动chrome浏览器后,它会成为一种解决方案,小时内容脚本可以继续发送请求到后台,但没有任何响应
从后台可以发回有什么方法可以捕捉到这个未捕获的错误并重置侦听器?



我使用chrome.extension.onRequest.addListener进行通信。

谢谢,
Marek

解决方案

这是连接关闭时引起的。例如,如果您打开一个包含content_script注入的选项卡,它将打开一个连接,关闭该选项卡,然后background_page尝试传递一条消息。它会失败,因为该标签不再处于活动状态接收消息。



在你的情况下,我猜测当tab关闭并且新标签打开时,你试图发送消息使用旧的tabId而不是创建到新标签的新连接。我建议再次阅读长期连接部分


I am getting this error in background page when responding to request from content script. Does anyone know what can be causing this error?

Full stack trace:

Uncaught Error: Attempting to use a disconnected port object   chrome/RendererExtensionBindings:147 
chrome.Port.postMessage     chrome/RendererExtensionBindings:147 
chromeHidden.Port.dispatchOnConnect.connectEvent         chrome/RendererExtensionBindings:89 
myExtension.foo.sendResponse.state      background.js:1573 
db.readTransaction.tx.executeSql.paramStr      background.js:1038 

This only happens after a couple of hours of browsing reloading extension is not helping - not that it would be a solution after restarting chrome browser all gets back to normal for couple of hours content script can keep sending request to background but NO response from background can be sent back Is there any way I could catch this Uncaught error and reset the listener?

I am using chrome.extension.onRequest.addListener for my communication. Before I respond I query DB and I do not send any other response before query is finished.

Thanks, Marek

解决方案

This is caused when a connection get closed. For example if you open a tab that has the content_script injected, it opens a connection, the tab is closed, and then the background_page tries to pass a message. It will fail because the tab is no longer active to receive the message.

In your case I would guess that as tabs close and new tabs open you are attempting to post messages with the old tabId instead of creating a new connection to the new tab. I would recommend reading through the long-lived connections section again.

这篇关于未捕获错误的原因:尝试使用断开的端口对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆