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

PerformanceContainerTiming: identifier property

· 52CE 我爱测

The **`identifier`** read-only property of the PerformanceContainerTiming interface returns the value of the `containertiming` attribute on the container's root element.

Performance API

The identifier read-only property of the PerformanceContainerTiming interface returns the value of the containertiming attribute on the container's root element.

This can be used to determine the container root that each entry belongs to, which is useful if multiple containers are being reported at the same time. This approach is easier than comparing PerformanceContainerTiming.rootElement references.

Value

A string.

Examples

Using identifier to distinguish containers

This example shows how you can determine the affected container using identifier.

HTML

First we define two elements that are marked as container roots with the containertiming attribute, identified as "hero" and "product-list", respectively.

<section containertiming="hero">
  <h2>Hero content</h2>
</section>
<div containertiming="product-list">
  <p>Product list content</p>
</div>

Note that there is also hidden HTML (and code) for displaying log information.

<pre id="log"></pre>
#log {
  height: 150px;
  overflow: scroll;
  padding: 0.5rem;
  border: 1px solid black;
}
const logElement = document.querySelector("#log");
function log(text) {
  logElement.innerText = `${logElement.innerText}${text}\n`;
  logElement.scrollTop = logElement.scrollHeight;
}

JavaScript

The following code first checks whether the browser supports "container" entries: if not, it logs that the feature is not supported. It then creates a PerformanceObserver that logs the identifier and PerformanceEntry.startTime of each entry, allowing the two containers to be told apart.

if (PerformanceObserver.supportedEntryTypes.includes("container")) {
  const observer = new PerformanceObserver((list) => {
    for (const entry of list.getEntries()) {
      log(`${entry.identifier} painted at ${entry.startTime.toFixed(1)}`);
    }
  });
  observer.observe({ type: "container", buffered: true });
} else {
  log("This feature is not supported by your browser.");
}

Result

The following log shows the identifier and startTime reported for each of the two containers. Note that the start time is the same in this case, as they are painted in the same frame.

Using identifier to distinguish containers

Specifications

Browser compatibility

See also

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

资料来源与适用范围

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

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

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