Skip to content

Commit abd03a7

Browse files
authored
Fix: only send data to extension if DevTools are open (#1735)
* Fix: only send data to extension if DevTools are open * Create odd-apples-argue.md
1 parent b3e8f20 commit abd03a7

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

.changeset/odd-apples-argue.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: only send data to extension if DevTools are open

extension/src/background/store/apiMiddleware.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ const chunks: {
249249
>;
250250
} = {};
251251
let monitors = 0;
252+
let isMonitored = false;
252253

253254
const getId = (sender: chrome.runtime.MessageSender, name?: string) =>
254255
sender.tab ? sender.tab.id! : name || sender.id!;
@@ -262,12 +263,7 @@ type MonitorAction<S, A extends Action<string>> =
262263
// Chrome message limit is 64 MB, but we're using 32 MB to include other object's parts
263264
const maxChromeMsgSize = 32 * 1024 * 1024;
264265

265-
// TODO Clean up args
266-
function toMonitors<S, A extends Action<string>>(
267-
action: MonitorAction<S, A>,
268-
tabId?: string | number,
269-
verbose?: boolean,
270-
) {
266+
function toMonitors<S, A extends Action<string>>(action: MonitorAction<S, A>) {
271267
for (const port of [
272268
...Object.values(connections.monitor),
273269
...Object.values(connections.panel),
@@ -417,6 +413,7 @@ function toAllTabs(msg: TabMessage) {
417413
}
418414

419415
function monitorInstances(shouldMonitor: boolean, id?: string) {
416+
if (!id && isMonitored === shouldMonitor) return;
420417
const action = {
421418
type: shouldMonitor ? ('START' as const) : ('STOP' as const),
422419
};
@@ -425,6 +422,7 @@ function monitorInstances(shouldMonitor: boolean, id?: string) {
425422
} else {
426423
toAllTabs(action);
427424
}
425+
isMonitored = shouldMonitor;
428426
}
429427

430428
function getReducerError() {
@@ -499,7 +497,7 @@ function messaging<S, A extends Action<string>>(
499497
}
500498
if (request.type === 'ERROR') {
501499
if (request.payload) {
502-
toMonitors(request, tabId);
500+
toMonitors(request);
503501
return;
504502
}
505503
if (!request.message) return;
@@ -541,11 +539,7 @@ function messaging<S, A extends Action<string>>(
541539
}
542540
store.dispatch(action);
543541

544-
if (request.type === 'EXPORT') {
545-
toMonitors(action, tabId, true);
546-
} else {
547-
toMonitors(action, tabId);
548-
}
542+
toMonitors(action);
549543
}
550544

551545
function disconnect(
@@ -587,7 +581,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
587581
chrome.action.enable(id);
588582
chrome.action.setIcon({ tabId: id, path: 'img/logo/38x38.png' });
589583
}
590-
port.postMessage({ type: 'START' });
584+
if (isMonitored) port.postMessage({ type: 'START' });
591585

592586
const state = store.getState();
593587
if (state.instances.persisted) {

0 commit comments

Comments
 (0)