Reason for Uncaught Error: Attempting to use a disconnected port object

后端 未结 2 1162
一向
一向 2020-12-31 04:42

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:

相关标签:
2条回答
  • 2020-12-31 04:51

    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.

    0 讨论(0)
  • 2020-12-31 05:05

    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.

    0 讨论(0)
提交回复
热议问题