Skip to content

Commit ba2dd3b

Browse files
Guard proxy message forwarding
1 parent 5b5ea00 commit ba2dd3b

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
@@ -159,7 +159,15 @@ function setPortProxy(port, proxyTabId) {
159159
port._reconnectAttempts = 0
160160
console.debug('[background] Reset reconnect attempts after successful proxy message.')
161161
}
162-
port.postMessage(msg)
162+
if (port._isClosed) {
163+
console.debug('[background] Main port closed; skipping proxy message.')
164+
return
165+
}
166+
try {
167+
port.postMessage(msg)
168+
} catch (e) {
169+
console.warn('[background] Failed to post message to main port (likely disconnected):', e)
170+
}
163171
}
164172
port._portOnMessage = (msg) => {
165173
if (msg?.session && !msg?.stop) {

0 commit comments

Comments
 (0)