Skip to content

Commit 2ca2b7b

Browse files
committed
Prevent flooding with error notifications
Related to #27.
1 parent 3567f0a commit 2ca2b7b

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/browser/extension/inject/pageScript.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,24 @@ window.devToolsExtension.open = function(position) {
129129
};
130130

131131
// Catch non-reducer errors
132-
function catchErrors(e) {
133-
if (window.devToolsOptions && !window.devToolsOptions.notifyErrors) return;
134-
window.postMessage({
135-
source: 'redux-page',
136-
type: 'ERROR',
137-
message: e.message
138-
}, '*');
139-
}
140-
141132
window.devToolsExtension.notifyErrors = function() {
133+
let lastError = 0;
134+
function postError(message) {
135+
window.postMessage({
136+
source: 'redux-page',
137+
type: 'ERROR',
138+
message: message
139+
}, '*');
140+
}
141+
function catchErrors(e) {
142+
if (window.devToolsOptions && !window.devToolsOptions.notifyErrors) return;
143+
const timeout = (window.devToolsOptions.timeout || 1) * 1000;
144+
if (!lastError) {
145+
setTimeout(() => { postError(e.message); }, window.devToolsOptions.timeout ? timeout : 0);
146+
} else if (lastError + timeout < e.timeStamp) {
147+
postError(e.message);
148+
}
149+
lastError = e.timeStamp;
150+
}
142151
window.addEventListener('error', catchErrors, false);
143152
};

0 commit comments

Comments
 (0)