diff --git a/src/page/stringify.ts b/src/page/stringify.ts index 34083e6..ed15c7b 100644 --- a/src/page/stringify.ts +++ b/src/page/stringify.ts @@ -5,19 +5,23 @@ function isReactSyntheticEvent(event: any) { return "_dispatchListeners" in event; } export const stringify = (obj: any) => { - return JSON.stringify(obj, (k, v) => { - if (v && isReactSyntheticEvent(v)) return "SyntheticEvent"; - if (v && typeof v === "object") { - // if (v instanceof Event || (typeof v?.originalEvent === 'object' && v?.originalEvent instanceof Event)) return 'Event'; - if (v instanceof Error) { - return Object.getOwnPropertyNames(v).reduce((acc, k) => { - acc[k] = v[k]; - return acc; - }, {}); + try { + return JSON.stringify(obj, (k, v) => { + if (v && isReactSyntheticEvent(v)) return "SyntheticEvent"; + if (v && typeof v === "object") { + // if (v instanceof Event || (typeof v?.originalEvent === 'object' && v?.originalEvent instanceof Event)) return 'Event'; + if (v instanceof Error) { + return Object.getOwnPropertyNames(v).reduce((acc, k) => { + acc[k] = v[k]; + return acc; + }, {}); + } + if (v instanceof Node) return "Node"; + if (v instanceof Window) return "Window"; } - if (v instanceof Node) return "Node"; - if (v instanceof Window) return "Window"; - } - return v; - }); + return v; + }); + } catch (e) { + return Object.prototype.toString.call(obj); + } };