Performance: clearMarks() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
Note: This feature is available in Web Workers.
Phương thức clearMarks() xóa tất cả hoặc các đối tượng PerformanceMark cụ thể khỏi performance timeline của trình duyệt.
Cú pháp
js
clearMarks()
clearMarks(name)
Tham số
nameOptional-
Một chuỗi biểu thị
namecủa đối tượngPerformanceMark. Nếu bỏ qua đối số này, tất cả các entry cóentryTypelà"mark"sẽ bị xóa.
Giá trị trả về
Không có (undefined).
Ví dụ
>Xóa các marker
Để dọn sạch tất cả performance mark, hoặc chỉ các entry cụ thể, hãy dùng phương thức clearMarks() như sau:
js
// Tạo một loạt mark
performance.mark("login-started");
performance.mark("login-started");
performance.mark("login-finished");
performance.mark("form-sent");
performance.mark("video-loaded");
performance.mark("video-loaded");
performance.getEntriesByType("mark").length; // 6
// Chỉ xóa các entry mark "login-started"
performance.clearMarks("login-started");
performance.getEntriesByType("mark").length; // 4
// Xóa tất cả entry mark
performance.clearMarks();
performance.getEntriesByType("mark").length; // 0
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| User Timing> # dom-performance-clearmarks> |