From c38ba1c9b45811bfd21b97ced3d5c79ee8eca259 Mon Sep 17 00:00:00 2001 From: velzie Date: Mon, 26 Aug 2024 12:22:02 -0400 Subject: [PATCH] internal error detection --- src/client/client.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index 8403e9a..07ccbaa 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -2,7 +2,7 @@ import { createDocumentProxy } from "./document"; import { createGlobalProxy } from "./global"; import { getOwnPropertyDescriptorHandler } from "./helpers"; import { createLocationProxy } from "./location"; -import { CookieStore, decodeUrl } from "./shared"; +import { CookieStore, config, decodeUrl } from "./shared"; declare global { interface Window { @@ -185,7 +185,32 @@ export class ScramjetClient { }, }; - handler.apply(ctx); + const pst = Error.prepareStackTrace; + + Error.prepareStackTrace = function (err, s) { + if ( + s[0].getFileName() && + !s[0].getFileName().startsWith(location.origin + config.prefix) + ) { + return s; + } + }; + + try { + handler.apply(ctx); + } catch (err) { + if (err instanceof Error) { + if ((err.stack as any) instanceof Object) { + console.error("ERROR FROM SCRMAJET INTERNALS", err); + } else { + throw err; + } + } else { + throw err; + } + } + + delete Error.prepareStackTrace; if (returnValue) { return returnValue;