Skip to content

Commit 50d7682

Browse files
authored
Fix DevTools from losing connection (#1767)
* Fix DevTools from losing connection * Create kind-seals-arrive.md
1 parent 344387c commit 50d7682

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

.changeset/kind-seals-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'remotedev-redux-devtools-extension': patch
3+
---
4+
5+
Fix DevTools from losing connection

extension/src/background/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ chrome.storage.onChanged.addListener((changes) => {
2929
else removeMenu();
3030
}
3131
});
32+
33+
// https://developer.chrome.com/docs/extensions/develop/migrate/to-service-workers#keep_a_service_worker_alive_continuously
34+
setInterval(
35+
() => chrome.storage.local.set({ 'last-heartbeat': new Date().getTime() }),
36+
20000,
37+
);

extension/src/background/store/apiMiddleware.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
553553
console.log(`Connected to tab ${id}`);
554554
if (port.sender!.frameId) id = `${id}-${port.sender!.frameId}`;
555555
connections.tab[id] = port;
556-
listener = (msg: ContentScriptToBackgroundMessage<S, A> | 'heartbeat') => {
557-
if (msg === 'heartbeat') return;
556+
listener = (msg: ContentScriptToBackgroundMessage<S, A>) => {
558557
console.log(`Message from tab ${id}: ${msg.name}`);
559558
if (msg.name === 'INIT_INSTANCE') {
560559
if (typeof id === 'number') {
@@ -593,8 +592,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
593592
connections.panel[id] = port;
594593
monitors++;
595594
toAllTabs({ type: 'START' });
596-
listener = (msg: BackgroundAction | 'heartbeat') => {
597-
if (msg === 'heartbeat') return;
595+
listener = (msg: BackgroundAction) => {
598596
console.log(`Message from monitor ${id}: ${msg.type}`);
599597
store.dispatch(msg);
600598
};

extension/src/contentScript/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,3 @@ function handleMessages<S, A extends Action<string>>(
343343
prefetchOptions();
344344

345345
window.addEventListener('message', handleMessages, false);
346-
347-
setInterval(() => {
348-
bg?.postMessage('heartbeat');
349-
}, 15000);

extension/src/devpanel/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ function init() {
116116
}
117117
bgConnection = chrome.runtime.connect({ name });
118118

119-
setInterval(() => {
120-
bgConnection.postMessage('heartbeat');
121-
}, 15000);
122-
123119
bgConnection.onMessage.addListener(
124120
<S, A extends Action<string>>(
125121
message: PanelMessageWithSplitAction<S, A>,

0 commit comments

Comments
 (0)