未捕获错误的原因:尝试使用断开连接的端口对象

发布于 2024-10-22 07:59:07 字数 726 浏览 4 评论 0原文

响应请求时,我在后台页面中收到此错误 来自内容脚本。 有谁知道什么可能导致此错误?

完整堆栈跟踪:

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 

这仅在浏览几个小时后发生,重新加载扩展没有帮助 - 这并不是重新启动 Chrome 浏览器后的解决方案,所有内容在几个小时内恢复正常内容脚本可以继续向后台发送请求,但没有回复 从后台可以发回 有什么方法可以捕获此 Uncaught 错误并重置侦听器?

我正在使用 chrome.extension.onRequest.addListener 进行通信。在我响应之前,我查询数据库,并且在查询完成之前我不会发送任何其他响应。

谢谢, 马雷克

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅忆流年 2024-10-29 07:59:08

然而,就我而言,我需要向 chrome.runtime.sendMessage(msg, responseCallbackMissingHere) 提供 sendResponse 函数,这将为您提供“尝试使用断开的端口对象”错误。

In my case, however, I needed to provide the sendResponse function to the chrome.runtime.sendMessage(msg, responseCallbackMissingHere), which will give you the "Attempting to use a disconnected port object" error.

半城柳色半声笛 2024-10-29 07:59:07

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

在您的情况下,我猜测当选项卡关闭并打开新选项卡时,您正在尝试使用旧的 tabId 发布消息,而不是创建与新选项卡的新连接。我建议再次阅读长期连接部分

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文