Fix DevTools from losing connection (#1767)

* Fix DevTools from losing connection

* Create kind-seals-arrive.md
This commit is contained in:
Nathan Bierema 2024-09-19 21:07:52 -04:00 committed by GitHub
parent 344387c9c6
commit 50d7682776
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 12 deletions

View File

@ -0,0 +1,5 @@
---
'remotedev-redux-devtools-extension': patch
---
Fix DevTools from losing connection

View File

@ -29,3 +29,9 @@ chrome.storage.onChanged.addListener((changes) => {
else removeMenu(); else removeMenu();
} }
}); });
// https://developer.chrome.com/docs/extensions/develop/migrate/to-service-workers#keep_a_service_worker_alive_continuously
setInterval(
() => chrome.storage.local.set({ 'last-heartbeat': new Date().getTime() }),
20000,
);

View File

@ -553,8 +553,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
console.log(`Connected to tab ${id}`); console.log(`Connected to tab ${id}`);
if (port.sender!.frameId) id = `${id}-${port.sender!.frameId}`; if (port.sender!.frameId) id = `${id}-${port.sender!.frameId}`;
connections.tab[id] = port; connections.tab[id] = port;
listener = (msg: ContentScriptToBackgroundMessage<S, A> | 'heartbeat') => { listener = (msg: ContentScriptToBackgroundMessage<S, A>) => {
if (msg === 'heartbeat') return;
console.log(`Message from tab ${id}: ${msg.name}`); console.log(`Message from tab ${id}: ${msg.name}`);
if (msg.name === 'INIT_INSTANCE') { if (msg.name === 'INIT_INSTANCE') {
if (typeof id === 'number') { if (typeof id === 'number') {
@ -593,8 +592,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
connections.panel[id] = port; connections.panel[id] = port;
monitors++; monitors++;
toAllTabs({ type: 'START' }); toAllTabs({ type: 'START' });
listener = (msg: BackgroundAction | 'heartbeat') => { listener = (msg: BackgroundAction) => {
if (msg === 'heartbeat') return;
console.log(`Message from monitor ${id}: ${msg.type}`); console.log(`Message from monitor ${id}: ${msg.type}`);
store.dispatch(msg); store.dispatch(msg);
}; };

View File

@ -343,7 +343,3 @@ function handleMessages<S, A extends Action<string>>(
prefetchOptions(); prefetchOptions();
window.addEventListener('message', handleMessages, false); window.addEventListener('message', handleMessages, false);
setInterval(() => {
bg?.postMessage('heartbeat');
}, 15000);

View File

@ -116,10 +116,6 @@ function init() {
} }
bgConnection = chrome.runtime.connect({ name }); bgConnection = chrome.runtime.connect({ name });
setInterval(() => {
bgConnection.postMessage('heartbeat');
}, 15000);
bgConnection.onMessage.addListener( bgConnection.onMessage.addListener(
<S, A extends Action<string>>( <S, A extends Action<string>>(
message: PanelMessageWithSplitAction<S, A>, message: PanelMessageWithSplitAction<S, A>,