From 742c9944b9e76c80567b589dad6a453e0da1dd20 Mon Sep 17 00:00:00 2001 From: Michael Lin Date: Thu, 2 Jan 2025 17:34:13 +0800 Subject: [PATCH] fix(chrome): fix chrome ext disconnect (#5) --- examples/browser-extension/src/background/index.ts | 4 ++++ src/transports/browserExtensionsTransport.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/examples/browser-extension/src/background/index.ts b/examples/browser-extension/src/background/index.ts index 7b84c85..d07f9fd 100644 --- a/examples/browser-extension/src/background/index.ts +++ b/examples/browser-extension/src/background/index.ts @@ -37,6 +37,10 @@ transport.onConnect((id) => { console.log('connect:', id); }); +transport.onDisconnect((id) => { + console.log('disconnect:', id); +}); + // @ts-ignore transport.listen('contentToBg', async (a, b) => a); diff --git a/src/transports/browserExtensionsTransport.ts b/src/transports/browserExtensionsTransport.ts index cd5677b..3cfcf10 100644 --- a/src/transports/browserExtensionsTransport.ts +++ b/src/transports/browserExtensionsTransport.ts @@ -163,6 +163,9 @@ export abstract class BrowserExtensionsMainTransport< this.ports.delete(id); } }); + this._onDisconnectCallback.forEach((callback) => { + callback(id); + }); }); // @ts-ignore