PerformancePaintTiming: toJSON() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
Phương thức toJSON() của giao diện PerformancePaintTiming là một bộ tuần tự hóa; nó trả về biểu diễn JSON của đối tượng PerformancePaintTiming.
Cú pháp
js
toJSON()
Tham số
Không có.
Giá trị trả về
Một đối tượng JSON là biểu diễn tuần tự hóa của đối tượng PerformancePaintTiming.
Ví dụ
>Sử dụng phương thức toJSON
Trong ví dụ này, gọi entry.toJSON() trả về biểu diễn JSON của đối tượng PerformancePaintTiming.
js
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
console.log(entry.toJSON());
});
});
observer.observe({ type: "paint", buffered: true });
Kết quả sẽ ghi log một đối tượng JSON như sau:
json
{
"name": "first-contentful-paint",
"entryType": "paint",
"startTime": 234.5,
"duration": 0
}
Để lấy chuỗi JSON, bạn có thể sử dụng trực tiếp JSON.stringify(entry); nó sẽ tự động gọi toJSON().
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Paint Timing> # dom-performancepainttiming-tojson> |