Performance: clearMarks() 方法

Baseline 已广泛支持

此功能已成熟,可跨多种设备和浏览器版本使用。自 2017 年 9 月以来,它已在浏览器中提供。

注意:此功能在 Web Workers 中可用。

clearMarks() 方法会从浏览器的性能时间线上移除所有或特定的 PerformanceMark 对象。

语法

js
clearMarks()
clearMarks(name)

参数

name 可选

一个表示 PerformanceMark 对象 name 的字符串。如果省略此参数,则会移除所有 entryType"mark" 的条目。

返回值

无(undefined)。

示例

移除标记

要清理所有性能标记,或仅清理特定条目,请像这样使用 clearMarks() 方法:

js
// Create a bunch of marks
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

// Delete just the "login-started" mark entries
performance.clearMarks("login-started");
performance.getEntriesByType("mark").length; // 4

// Delete all of the mark entries
performance.clearMarks();
performance.getEntriesByType("mark").length; // 0

规范

规范
用户计时
# dom-performance-clearmarks

浏览器兼容性

另见