fix(client): report cross origin errors (#37793)
* fix(client): report cross origin errors This reports errors generated in cross origin scripts to the dev console and lets the user know via the fcc console. * refactor: clean up script error checks Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
This commit is contained in:
committed by
mrugesh
parent
e154f38118
commit
d6c53eb914
@ -13,13 +13,18 @@ const testId = 'fcc-test-frame';
|
|||||||
// this also allows in-page anchors to work properly
|
// this also allows in-page anchors to work properly
|
||||||
// rather than load another instance of the learn
|
// rather than load another instance of the learn
|
||||||
|
|
||||||
// window.onerror is added here to catch any errors thrown during the building
|
// window.onerror is added here to report any errors thrown during the building
|
||||||
// of the frame.
|
// of the frame. React dom errors already appear in the console, so onerror
|
||||||
|
// does not need to pass them on to the default error handler.
|
||||||
const createHeader = (id = mainId) => `
|
const createHeader = (id = mainId) => `
|
||||||
<base href='' />
|
<base href='' />
|
||||||
<script>
|
<script>
|
||||||
window.__frameId = '${id}';
|
window.__frameId = '${id}';
|
||||||
window.onerror = function(msg) {
|
window.onerror = function(msg) {
|
||||||
|
var string = msg.toLowerCase();
|
||||||
|
if (string.includes('script error')) {
|
||||||
|
msg = 'Build error, open your browser console to learn more.';
|
||||||
|
}
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -108,11 +113,16 @@ const initMainFrame = (frameReady, proxyLogger) => ctx => {
|
|||||||
// after the frame is ready. It has to be overwritten, as proxyLogger cannot
|
// after the frame is ready. It has to be overwritten, as proxyLogger cannot
|
||||||
// be added as part of createHeader.
|
// be added as part of createHeader.
|
||||||
ctx.window.onerror = function(msg) {
|
ctx.window.onerror = function(msg) {
|
||||||
console.log(msg);
|
var string = msg.toLowerCase();
|
||||||
|
if (string.includes('script error')) {
|
||||||
|
msg = 'Error, open your browser console to learn more.';
|
||||||
|
}
|
||||||
if (proxyLogger) {
|
if (proxyLogger) {
|
||||||
proxyLogger(msg);
|
proxyLogger(msg);
|
||||||
}
|
}
|
||||||
return true;
|
// let the error propagate so it appears in the browser console, otherwise
|
||||||
|
// an error from a cross origin script just appears as 'Script error.'
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
frameReady();
|
frameReady();
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user