mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-16 23:40:32 +08:00
chore(monaco): ignore worker errors in console
This commit is contained in:
parent
45193e017f
commit
231517b5db
14
src/main.tsx
14
src/main.tsx
@ -26,6 +26,10 @@ import {
|
|||||||
UpdateStateProvider,
|
UpdateStateProvider,
|
||||||
} from "./services/states";
|
} from "./services/states";
|
||||||
import { disableWebViewShortcuts } from "./utils/disable-webview-shortcuts";
|
import { disableWebViewShortcuts } from "./utils/disable-webview-shortcuts";
|
||||||
|
import {
|
||||||
|
isIgnoredMonacoWorkerError,
|
||||||
|
patchMonacoWorkerConsole,
|
||||||
|
} from "./utils/monaco-worker-ignore";
|
||||||
|
|
||||||
if (!window.ResizeObserver) {
|
if (!window.ResizeObserver) {
|
||||||
window.ResizeObserver = ResizeObserver;
|
window.ResizeObserver = ResizeObserver;
|
||||||
@ -87,12 +91,22 @@ bootstrap().catch((error) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
patchMonacoWorkerConsole();
|
||||||
|
|
||||||
// Error handling
|
// Error handling
|
||||||
window.addEventListener("error", (event) => {
|
window.addEventListener("error", (event) => {
|
||||||
|
if (isIgnoredMonacoWorkerError(event.error ?? event.message)) {
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.error("[main.tsx] Global error:", event.error);
|
console.error("[main.tsx] Global error:", event.error);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("unhandledrejection", (event) => {
|
window.addEventListener("unhandledrejection", (event) => {
|
||||||
|
if (isIgnoredMonacoWorkerError(event.reason)) {
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.error("[main.tsx] Unhandled promise rejection:", event.reason);
|
console.error("[main.tsx] Unhandled promise rejection:", event.reason);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
38
src/utils/monaco-worker-ignore.ts
Normal file
38
src/utils/monaco-worker-ignore.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// These warnings are safe to ignore: they occur when Monaco models or workers are manually disposed.
|
||||||
|
const ignoredGlobalErrorMessages = [
|
||||||
|
"Missing requestHandler or method:",
|
||||||
|
"Could not create web worker(s). Falling back to loading web worker code in main thread",
|
||||||
|
"Cannot use 'in' operator to search for 'then' in undefined",
|
||||||
|
];
|
||||||
|
|
||||||
|
const isIgnoredMessage = (message: string) =>
|
||||||
|
ignoredGlobalErrorMessages.some((snippet) => message.includes(snippet));
|
||||||
|
|
||||||
|
export const isIgnoredMonacoWorkerError = (reason: unknown) => {
|
||||||
|
const message = String(
|
||||||
|
reason instanceof Error ? reason.message : (reason ?? ""),
|
||||||
|
);
|
||||||
|
return isIgnoredMessage(message);
|
||||||
|
};
|
||||||
|
|
||||||
|
const shouldIgnoreConsoleArgs = (args: unknown[]) =>
|
||||||
|
args.some((arg) => {
|
||||||
|
const message =
|
||||||
|
typeof arg === "string" ? arg : arg instanceof Error ? arg.message : "";
|
||||||
|
return isIgnoredMessage(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const patchMonacoWorkerConsole = () => {
|
||||||
|
const originalWarn = console.warn;
|
||||||
|
const originalError = console.error;
|
||||||
|
|
||||||
|
console.warn = (...args) => {
|
||||||
|
if (shouldIgnoreConsoleArgs(args)) return;
|
||||||
|
originalWarn(...args);
|
||||||
|
};
|
||||||
|
|
||||||
|
console.error = (...args) => {
|
||||||
|
if (shouldIgnoreConsoleArgs(args)) return;
|
||||||
|
originalError(...args);
|
||||||
|
};
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user