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

瀏覽器相容性

另見