Skip to content

Commit 3aa220f

Browse files
committed
Allow to init window.devToolsExtension.notifyErrors explicitely
Related to #27.
1 parent deae6a2 commit 3aa220f

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/browser/extension/background/messaging.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function messaging(request, sender, sendResponse) {
5151
return true;
5252
}
5353
if (request.type === 'ERROR') {
54+
if (catchedErrors.last) return true;
5455
chrome.notifications.create('app-error', {
5556
type: 'basic',
5657
title: 'An error occurred in the app',

src/browser/extension/inject/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ chrome.runtime.sendMessage(window.devToolsExtensionID, { type: 'GET_OPTIONS' },
1212
window.devToolsOptions = response.options;
1313
require('./contentScript');
1414
require('./pageScript');
15+
window.devToolsExtension.notifyErrors();
1516
});

src/browser/extension/inject/pageScript.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,7 @@ window.devToolsExtension = function(next) {
4848
init: init || false
4949
}, '*');
5050

51-
// Catch non-reducer errors
52-
window.addEventListener('error', function(e) {
53-
if (!window.devToolsOptions.notifyErrors || !e.filename) return;
54-
window.postMessage({
55-
source: 'redux-page',
56-
type: 'ERROR',
57-
message: e.message
58-
}, '*');
59-
});
51+
window.devToolsExtension.notifyErrors();
6052
}
6153

6254
function onChange(init) {
@@ -129,3 +121,17 @@ window.devToolsExtension.open = function(position) {
129121
position: position || ''
130122
}, '*');
131123
};
124+
125+
// Catch non-reducer errors
126+
function catchErrors(e) {
127+
if (window.devToolsOptions && !window.devToolsOptions.notifyErrors) return;
128+
window.postMessage({
129+
source: 'redux-page',
130+
type: 'ERROR',
131+
message: e.message
132+
}, '*');
133+
}
134+
135+
window.devToolsExtension.notifyErrors = function() {
136+
window.addEventListener('error', catchErrors, false);
137+
};

0 commit comments

Comments
 (0)