faro-web-sdk icon indicating copy to clipboard operation
faro-web-sdk copied to clipboard

Session Manager: guard against circular references when stringifying a session

Open codecapitano opened this issue 1 year ago • 0 comments

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.

Context

image

codecapitano avatar May 08 '24 09:05 codecapitano