大网数据广告活动
Web 标准与前端开发

PerformanceMark: PerformanceMark() constructor

· 52CE 我爱测

The **`PerformanceMark()`** constructor creates a DOMHighResTimeStamp with the given name.

Performance API

The PerformanceMark() constructor creates a DOMHighResTimeStamp with the given name.

Unlike Performance.mark, performance marks created by the constructor aren't added to the browser's performance timeline. This means that calls to the Performance interface's getEntries*() methods (Performance.getEntries, Performance.getEntriesByName or Performance.getEntriesByType) won't show entries for these marks.

Syntax

new PerformanceMark(name)
new PerformanceMark(name, markOptions)

Parameters

  • name
    • : A string representing the name of the mark.
  • markOptions
    • : An object for specifying a timestamp and additional metadata for the mark.
      • detail
        • : Arbitrary metadata to include in the mark. Defaults to null.
          • devtools
            • : Some browsers have use a structured devtools object within the detail object as part of an Extensibility API that surfaces these in custom tracks in performance traces. See the Chrome's Extensibility API documentation for more information.
              • dataType
                • : A string which must be set to marker. Identifies as a marker.
              • color
                • : Defaults to "primary". Must be one of "primary", "primary-light", "primary-dark", "secondary", "secondary-light", "secondary-dark", "tertiary", "tertiary-light", "tertiary-dark", "error".
              • properties
                • : Array of key-value pairs. Values can be any JSON-compatible type.
              • tooltipText
                • : Short description for tooltip.
      • startTime
        • : DOMHighResTimeStamp to use as the mark time. Defaults to performance.now().

Return value

A PerformanceMark object.

Exceptions

  • SyntaxError: Thrown if the name given to this method already exists in the PerformanceTiming interface.
  • TypeError: Thrown if startTime is negative.

Examples

Creating named markers

The following example shows how PerformanceMark entries are constructed and then aren't part of the browser's performance timeline.

new PerformanceMark("squirrel");
new PerformanceMark("monkey");
new PerformanceMark("dog");

const allEntries = performance.getEntriesByType("mark");
console.log(allEntries.length);
// 0

DevTools Extensibility API

For browsers that support the Extensibility API you can use the detail parameter to provide more details in a devtools object that will be used to display this in performance profiles:

// Marker indicating when the processed image was uploaded
performance.mark("Image Upload", {
  detail: {
    devtools: {
      dataType: "marker",
      color: "secondary",
      properties: [
        ["Image Size", "2.5MB"],
        ["Upload Destination", "Cloud Storage"],
      ],
      tooltipText: "Processed image uploaded",
    },
  },
});

Specifications

Browser compatibility

See also

  • Performance.mark

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。