faro-web-sdk
faro-web-sdk copied to clipboard
Session Manager: guard against circular references when stringifying a session
Description
A user reported a Maximum call stack size exceeded exception in Faro.
A "Maximum call stack size exceeded" during JSON serialisation happens when an object contains circular references. Circular references happen when an object references itself directly or through one of its child objects.
Example for a circular reference.
const x = {};
const y = { x };
x.y = y
Proposed solution
To handle circular references, you can use a custom replacer function as the second argument to JSON.stringify(). This function can check for circular references and either replace them with something JSON can serialize (like null or a special marker) or omit them from the resulting JSON.