TaskAttributionTiming: toJSON() method
Limited availability
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.
Phương thức toJSON() của giao diện TaskAttributionTiming là một bộ tuần tự hóa; nó trả về biểu diễn JSON của đối tượng TaskAttributionTiming.
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 TaskAttributionTiming.
Ví dụ
>Sử dụng phương thức toJSON
Trong ví dụ này, việc gọi entry.toJSON() trả về biểu diễn JSON của đối tượng TaskAttributionTiming.
js
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
console.log(entry.toJSON());
});
});
observer.observe({ type: "taskattribution", buffered: true });
Đoạn này sẽ ghi một đối tượng JSON như sau:
json
{
"name": "unknown",
"entryType": "taskattribution",
"startTime": 0,
"duration": 0,
"containerType": "window",
"containerSrc": "",
"containerId": "",
"containerName": ""
}
Để lấy chuỗi JSON, bạn có thể dùng JSON.stringify(entry) trực tiếp; nó sẽ tự động gọi toJSON().
Thông số kỹ thuật
| Specification |
|---|
| Long Tasks API> # dom-taskattributiontiming-tojson> |