for an easier visualisation. Here are the steps:
- chrome.tabs.sendMessage(tab.id), where I get the tabId from the chrome.tabs.update() which correctly focuses the previous tab | Problem: Could not establish connection. Receiving end does not exist.
- chrome.tabs.connect(tab.id, {name: "foo"}), where my content-script has a listener for that port | Problem: I can see that my content-script's console shows that my connection is disconnected after navigating to the new tab (verifying by using the port.onDisconnect.addListener in the content-script). I'm unable to re-establish the connection to that content-script from the background even though I have the tabId. 🤔
How a simplified implementation looks from my side:
```
// in my content-script (via react)
const init = async () => {
chrome.runtime.onConnect.addListener((port) => {
console.log("hi") // ❌ doesn't log if I navigate to the tab
if (
port.name == "refreshTabAfterAuthentication") {
port.onMessage.addListener(() => forceUpdate())
}
})
}
useEffect(() => init(), [])
// in my background.ts (MV3)
// ...in some onMessage handler:
const port = chrome.tabs.connect(toRefresh.signInInitiatedBy.tabId, {
name: "refreshTabAfterAuthentication"
})
port.postMessage({ toRefresh.signInInitiatedBy.url })