Avoid logging unhandledRejection with browser extensions in stack trace
This commit is contained in:
parent
8f2c50918f
commit
5b80824f17
1 changed files with 9 additions and 0 deletions
|
|
@ -87,9 +87,18 @@ window.onerror = (msg, url, line, col, error) => {
|
||||||
return suppressErrorAlert;
|
return suppressErrorAlert;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isBrowserExtensionUnhandledRejection(reason) {
|
||||||
|
const stack = reason instanceof Error ? reason.stack : "";
|
||||||
|
return typeof stack === "string" && stack.includes("chrome-extension://");
|
||||||
|
}
|
||||||
|
|
||||||
// Log Promise rejections that are never handled (.catch / await try/catch), e.g. fire-and-forget async.
|
// Log Promise rejections that are never handled (.catch / await try/catch), e.g. fire-and-forget async.
|
||||||
window.addEventListener("unhandledrejection", (event) => {
|
window.addEventListener("unhandledrejection", (event) => {
|
||||||
const reason = event.reason;
|
const reason = event.reason;
|
||||||
|
if (isBrowserExtensionUnhandledRejection(reason)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const message = reason instanceof Error ? reason.message : String(reason);
|
const message = reason instanceof Error ? reason.message : String(reason);
|
||||||
global.$logger.logError(`unhandledrejection: ${message}`, {
|
global.$logger.logError(`unhandledrejection: ${message}`, {
|
||||||
stack: reason instanceof Error ? reason.stack : undefined,
|
stack: reason instanceof Error ? reason.stack : undefined,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue