mark() method creates a timestamp in the browser's performance entry buffer with the given name.

The application defined timestamp can be retrieved by one of the 性能 接口的 getEntries*() methods ( getEntries() , getEntriesByName() or getEntriesByType() ).

mark()'s stores its data internally as PerformanceEntry .

注意: 此特征可用于 Web 工作者 .

句法

performance.mark(name);
					

自变量

名称
DOMString representing the name of the mark. 名称 given to this method already exists in the PerformanceTiming interface, SyntaxError is thrown.

返回值

void

范例

The following example shows how to use mark() to create and retrieve PerformanceMark 条目。

// Create a bunch of marks.
performance.mark("squirrel");
performance.mark("squirrel");
performance.mark("monkey");
performance.mark("monkey");
performance.mark("dog");
performance.mark("dog");
// Get all of the PerformanceMark entries.
const allEntries = performance.getEntriesByType("mark");
console.log(allEntries.length);
// 6
// Get all of the "monkey" PerformanceMark entries.
const monkeyEntries = performance.getEntriesByName("monkey");
console.log(monkeyEntries.length);
// 2
// Clear out all of the marks.
performance.clearMarks();
					

规范

规范 状态 注释
User Timing Level 2
The definition of 'mark()' in that specification.
工作草案 Clarifies mark() processing model.
User Timing
The definition of 'mark()' in that specification.
推荐 Basic definition.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
mark Chrome 28
28
25 — 28 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 12 Firefox 41 IE 10 Opera 33 Safari 11 WebView Android Yes Chrome Android 28
28
25 — 28 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 42 Opera Android 33 Safari iOS 11 Samsung Internet Android 1.5

图例

完整支持

完整支持

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

元数据

  • 最后修改: