Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/page/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};