PerformanceLongAnimationFrameTiming: toJSON() 方法
toJSON() 方法是 PerformanceLongAnimationFrameTiming 接口的一个 序列化器;它返回 PerformanceLongAnimationFrameTiming 对象的 JSON 表示形式。
语法
js
toJSON()
参数
无。
返回值
一个 JSON 对象,它是 PerformanceLongAnimationFrameTiming 对象的序列化表示。
示例
使用 toJSON 方法
在此示例中,调用 entry.toJSON() 会返回 PerformanceLongAnimationFrameTiming 对象的 JSON 表示形式。
js
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
console.log(entry.toJSON());
});
});
observer.observe({ type: "long-animation-frame", buffered: true });
这将像这样记录一个对象:
js
({
blockingDuration: 0,
duration: 60,
entryType: "long-animation-frame",
firstUIEventTimestamp: 11801.099999999627,
name: "long-animation-frame",
renderStart: 11858.800000000745,
scripts: [
{
duration: 45,
entryType: "script",
executionStart: 11803.199999999255,
forcedStyleAndLayoutDuration: 0,
invoker: "DOMWindow.onclick",
invokerType: "event-listener",
name: "script",
pauseDuration: 0,
sourceURL: "https://webdev.ac.cn/js/index-ffde4443.js",
sourceFunctionName: "myClickHandler",
sourceCharPosition: 17796,
startTime: 11803.199999999255,
window: {
// …Window object…
},
windowAttribution: "self",
},
],
startTime: 11802.400000000373,
styleAndLayoutStart: 11858.800000000745,
});
要获取 JSON 字符串,您可以直接使用 JSON.stringify(entry);它会自动调用 toJSON()。
规范
| 规范 |
|---|
| Long Animation Frames API # dom-performancelonganimationframetiming-tojson |
浏览器兼容性
加载中…