Fix capture and display rejected promises in web editor console

This commit is contained in:
ridait 2020-08-26 19:15:21 +02:00
parent f918669116
commit 111abb2b93

View file

@ -38,6 +38,22 @@ export const hijackConsoleErrorsScript = (offs) => {
}], '*'); }], '*');
return false; 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; return s;
}; };
@ -46,7 +62,7 @@ export const startTag = '@fs-';
export const getAllScriptOffsets = (htmlFile) => { export const getAllScriptOffsets = (htmlFile) => {
const offs = []; const offs = [];
const hijackConsoleErrorsScriptLength = 36; const hijackConsoleErrorsScriptLength = 52;
const embeddedJSStart = 'script crossorigin=""'; const embeddedJSStart = 'script crossorigin=""';
let foundJSScript = true; let foundJSScript = true;
let foundEmbeddedJS = true; let foundEmbeddedJS = true;