diff --git a/dist/functions/server/web-pages/grab-web-page-hydration-script.js b/dist/functions/server/web-pages/grab-web-page-hydration-script.js
index 86868a9..14788d1 100644
--- a/dist/functions/server/web-pages/grab-web-page-hydration-script.js
+++ b/dist/functions/server/web-pages/grab-web-page-hydration-script.js
@@ -12,6 +12,9 @@ export default async function (params) {
const supress_condition = errors_to_supress
.map((e) => `args[0].includes("${e}")`)
.join(" || ");
+ const runtime_supress_condition = errors_to_supress
+ .map((e) => `message.includes("${e}")`)
+ .join(" || ");
script += `const _ce = console.error.bind(console);\n`;
script += `console.error = (...args) => {\n`;
script += ` if (typeof args[0] === "string" && (${supress_condition})) return;\n`;
@@ -26,10 +29,26 @@ export default async function (params) {
script += ` overlay.innerHTML = \`
Runtime Error
\${message}
\${source ? \`
\${source}
\` : ""}\${stack ? \`
\${stack}\` : ""}
\`;\n`;
script += ` document.body.appendChild(overlay);\n`;
script += `}\n\n`;
+ script += `function __bunext_should_suppress_runtime_error(message) {\n`;
+ script += ` return typeof message === "string" && (${runtime_supress_condition});\n`;
+ script += `}\n\n`;
script += `window.addEventListener("error", (e) => {\n`;
- script += ` __bunext_show_error(e.message, e.filename ? e.filename + ":" + e.lineno + ":" + e.colno : "", e.error?.stack ?? "");\n`;
+ script += ` const message = String(e.message ?? "");\n`;
+ script += ` if (__bunext_should_suppress_runtime_error(message)) {\n`;
+ script += ` e.preventDefault();\n`;
+ script += ` e.stopImmediatePropagation();\n`;
+ script += ` return;\n`;
+ script += ` }\n`;
+ script += ` __bunext_show_error(message, e.filename ? e.filename + ":" + e.lineno + ":" + e.colno : "", e.error?.stack ?? "");\n`;
script += `});\n`;
- script += `window.addEventListener("unhandledrejection", (e) => __bunext_show_error(String(e.reason?.message ?? e.reason), "", e.reason?.stack ?? ""));\n\n`;
+ script += `window.addEventListener("unhandledrejection", (e) => {\n`;
+ script += ` const message = String(e.reason?.message ?? e.reason ?? "");\n`;
+ script += ` if (__bunext_should_suppress_runtime_error(message)) {\n`;
+ script += ` e.preventDefault();\n`;
+ script += ` return;\n`;
+ script += ` }\n`;
+ script += ` __bunext_show_error(message, "", e.reason?.stack ?? "");\n`;
+ script += `});\n\n`;
script += `const hmr = new EventSource("/__hmr");\n`;
script += `window.BUNEXT_HMR = hmr;\n`;
script += `window.addEventListener("beforeunload", () => hmr.close());\n`;
diff --git a/src/functions/server/web-pages/grab-web-page-hydration-script.tsx b/src/functions/server/web-pages/grab-web-page-hydration-script.tsx
index 1948936..fb93f6c 100644
--- a/src/functions/server/web-pages/grab-web-page-hydration-script.tsx
+++ b/src/functions/server/web-pages/grab-web-page-hydration-script.tsx
@@ -23,6 +23,10 @@ export default async function (params?: Params) {
.map((e) => `args[0].includes("${e}")`)
.join(" || ");
+ const runtime_supress_condition = errors_to_supress
+ .map((e) => `message.includes("${e}")`)
+ .join(" || ");
+
script += `const _ce = console.error.bind(console);\n`;
script += `console.error = (...args) => {\n`;
script += ` if (typeof args[0] === "string" && (${supress_condition})) return;\n`;
@@ -38,10 +42,26 @@ export default async function (params?: Params) {
script += ` overlay.innerHTML = \`Runtime Error
\${message}
\${source ? \`
\${source}
\` : ""}\${stack ? \`
\${stack}\` : ""}
\`;\n`;
script += ` document.body.appendChild(overlay);\n`;
script += `}\n\n`;
+ script += `function __bunext_should_suppress_runtime_error(message) {\n`;
+ script += ` return typeof message === "string" && (${runtime_supress_condition});\n`;
+ script += `}\n\n`;
script += `window.addEventListener("error", (e) => {\n`;
- script += ` __bunext_show_error(e.message, e.filename ? e.filename + ":" + e.lineno + ":" + e.colno : "", e.error?.stack ?? "");\n`;
+ script += ` const message = String(e.message ?? "");\n`;
+ script += ` if (__bunext_should_suppress_runtime_error(message)) {\n`;
+ script += ` e.preventDefault();\n`;
+ script += ` e.stopImmediatePropagation();\n`;
+ script += ` return;\n`;
+ script += ` }\n`;
+ script += ` __bunext_show_error(message, e.filename ? e.filename + ":" + e.lineno + ":" + e.colno : "", e.error?.stack ?? "");\n`;
script += `});\n`;
- script += `window.addEventListener("unhandledrejection", (e) => __bunext_show_error(String(e.reason?.message ?? e.reason), "", e.reason?.stack ?? ""));\n\n`;
+ script += `window.addEventListener("unhandledrejection", (e) => {\n`;
+ script += ` const message = String(e.reason?.message ?? e.reason ?? "");\n`;
+ script += ` if (__bunext_should_suppress_runtime_error(message)) {\n`;
+ script += ` e.preventDefault();\n`;
+ script += ` return;\n`;
+ script += ` }\n`;
+ script += ` __bunext_show_error(message, "", e.reason?.stack ?? "");\n`;
+ script += `});\n\n`;
script += `const hmr = new EventSource("/__hmr");\n`;
script += `window.BUNEXT_HMR = hmr;\n`;