Skip to content

Commit 1b701e9

Browse files
Guard proxy message forwarding
1 parent 17b5fc0 commit 1b701e9

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/background/index.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,15 @@ function setPortProxy(port, proxyTabId) {
185185
port._reconnectAttempts = 0
186186
console.debug('[background] Reset reconnect attempts after successful proxy message.')
187187
}
188-
port.postMessage(msg)
188+
if (port._isClosed) {
189+
console.debug('[background] Main port closed; skipping proxy message.')
190+
return
191+
}
192+
try {
193+
port.postMessage(msg)
194+
} catch (e) {
195+
console.warn('[background] Failed to post message to main port (likely disconnected):', e)
196+
}
189197
}
190198
port._portOnMessage = (msg) => {
191199
if (msg?.session && !msg?.stop) {

0 commit comments

Comments
 (0)