8000 fix: seamless automatic reconnection (#201) · sveltejs/svelte-devtools@e5897e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit e5897e5

Browse files
authored
fix: seamless automatic reconnection (#201)
1 parent 86c67dc commit e5897e5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/lib/runtime.svelte.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import { type DebugNode, app } from './state.svelte';
22

33
const tabId = chrome.devtools.inspectedWindow.tabId;
4-
const port = chrome.runtime.connect({ name: `${tabId}` });
4+
let port = chrome.runtime.connect({ name: `${tabId}` });
55

66
port.postMessage({ source: 'svelte-devtools', tabId, type: 'bypass::ext/init' });
77

88
export const background = {
99
send(type: `bridge::${'ext' | 'page'}/${string}` | 'bypass::ext/page->refresh', payload?: any) {
10-
port.postMessage({ source: 'svelte-devtools', tabId, type, payload });
10+
try {
11+
port.postMessage({ source: 'svelte-devtools', tabId, type, payload });
12+
} catch {
13+
// https://developer.chrome.com/docs/extensions/develop/concepts/messaging#port-lifetime
14+
// chrome aggressively disconnects the port, not much we can do other than to reconnect
15+
port = chrome.runtime.connect({ name: `${tabId}` });
16+
background.send(type, payload); // retry immediately
17+
}
1118
},
1219
};
1320

0 commit comments

Comments
 (0)
0