Merge pull request #1580 from ridait/bugfix/1546-rejected-promise-interception

Fix capture and display rejected promises in web editor console
This commit is contained in:
Cassie Tarakajian 2020-08-26 15:08:07 -04:00 committed by GitHub
commit 67ef2d3d72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,6 +38,22 @@ export const hijackConsoleErrorsScript = (offs) => {
}], '*');
return false;
};
// catch rejected promises
window.onunhandledrejection = function (event) {
if (event.reason && event.reason.message && event.reason.stack){
var errorNum = event.reason.stack.split('about:srcdoc:')[1].split(':')[0];
var fileInfo = getScriptOff(errorNum);
var data = event.reason.message + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')';
window.parent.postMessage([{
log: [{
method: 'error',
data: [data],
id: Date.now().toString()
}],
source: fileInfo[1]
}], '*');
}
};
`;
return s;
};
@ -46,7 +62,7 @@ export const startTag = '@fs-';
export const getAllScriptOffsets = (htmlFile) => {
const offs = [];
const hijackConsoleErrorsScriptLength = 36;
const hijackConsoleErrorsScriptLength = 52;
const embeddedJSStart = 'script crossorigin=""';
let foundJSScript = true;
let foundEmbeddedJS = true;