From dfbe2d0f0fcffc8fb4d9d15fc52b013c69b7197d Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Sat, 7 Mar 2026 12:47:14 +0500 Subject: [PATCH] web: don't crash on web extension errors --- .../src/components/error-boundary/index.tsx | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/apps/web/src/components/error-boundary/index.tsx b/apps/web/src/components/error-boundary/index.tsx index d482938a7..deac88022 100644 --- a/apps/web/src/components/error-boundary/index.tsx +++ b/apps/web/src/components/error-boundary/index.tsx @@ -38,11 +38,36 @@ const IGNORED_ERRORS = [ "network error", "NetworkError when attempting to fetch resource." ]; + +const EXTENSION_URL_PREFIXES = [ + "chrome-extension://", + "moz-extension://", + "safari-extension://", + "safari-web-extension://" +]; + +function isFromBrowserExtension(error: unknown): boolean { + const stack = + error instanceof Error + ? error.stack + : typeof error === "string" + ? error + : undefined; + if (stack && EXTENSION_URL_PREFIXES.some((prefix) => stack.includes(prefix))) + return true; + return false; +} + export function GlobalErrorHandler(props: PropsWithChildren) { const { showBoundary } = useErrorBoundary(); useEffect(() => { function handleError(e: ErrorEvent) { + if ( + e.filename && + EXTENSION_URL_PREFIXES.some((prefix) => e.filename.startsWith(prefix)) + ) + return; const error = new Error(e.message); error.stack = `${e.filename}:${e.lineno}:${e.colno}`; showBoundary(e.error || error); @@ -53,6 +78,7 @@ export function GlobalErrorHandler(props: PropsWithChildren) { IGNORED_ERRORS.includes(e.reason.message) ) return; + if (isFromBrowserExtension(e.reason)) return; showBoundary(e.reason); } window.addEventListener("unhandledrejection", handleUnhandledRejection);