This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The toJSON() method of the PerformanceScriptTiming interface is a serializer; it returns a JSON representation of the PerformanceScriptTiming object.
toJSON()
None.
A JSON object that is the serialization of the PerformanceScriptTiming object.
toJSON methodIn this example, calling entry.toJSON() returns a JSON representation of the first PerformanceScriptTiming object available in an observed long animation frame.
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
console.log(entry.scripts[0].toJSON());
});
});
observer.observe({ type: "long-animation-frame", buffered: true });
This would log an object like so:
({
duration: 45,
entryType: "script",
executionStart: 11803.199999999255,
forcedStyleAndLayoutDuration: 0,
invoker: "DOMWindow.onclick",
invokerType: "event-listener",
name: "script",
pauseDuration: 0,
sourceURL: "https://web.dev/js/index-ffde4443.js",
sourceFunctionName: "myClickHandler",
sourceCharPosition: 17796,
startTime: 11803.199999999255,
windowAttribution: "self",
});
To get a JSON string, you can use JSON.stringify(entry) directly; it will call toJSON() automatically.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
toJSON |
123 | 123 | No | 109 | No | 123 | No | 82 | No | 27.0 | 123 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceScriptTiming/toJSON