Skip to content

Commit b05ce99

Browse files
authored
Merge pull request #1565 from ridait/bugfix/rejected-promise-interception
Fixes #1546 capture and display rejected promises
2 parents 9e587fa + cdfb588 commit b05ce99

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

client/utils/consoleUtils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ export const hijackConsoleErrorsScript = (offs) => {
3838
}], '*');
3939
return false;
4040
};
41+
// catch rejected promises
42+
window.onunhandledrejection = function (event) {
43+
if (event.reason && event.reason.message && event.reason.stack){
44+
var errorNum = event.reason.stack.split('about:srcdoc:')[1].split(':')[0];
45+
var fileInfo = getScriptOff(errorNum);
46+
var data = event.reason.message + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')';
47+
window.parent.postMessage([{
48+
log: [{
49+
method: 'error',
50+
data: [data],
51+
id: Date.now().toString()
52+
}],
53+
source: fileInfo[1]
54+
}], '*');
55+
}
56+
};
4157
`;
4258
return s;
4359
};
@@ -46,7 +62,7 @@ export const startTag = '@fs-';
4662

4763
export const getAllScriptOffsets = (htmlFile) => {
4864
const offs = [];
49-
const hijackConsoleErrorsScriptLength = 36;
65+
const hijackConsoleErrorsScriptLength = 52;
5066
const embeddedJSStart = 'script crossorigin=""';
5167
let foundJSScript = true;
5268
let foundEmbeddedJS = true;

0 commit comments

Comments
 (0)