Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. PerformanceObserver

PerformanceObserver

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

* Some parts of this feature may have varying levels of support.

Note: This feature is available inWeb Workers.

ThePerformanceObserver interface is used to observe performance measurement events and be notified of newperformance entries as they are recorded in the browser'sperformance timeline.

Constructor

PerformanceObserver()

Creates and returns a newPerformanceObserver object.

Static properties

PerformanceObserver.supportedEntryTypesRead only

Returns an array of theentryType values supported by the user agent.

Instance methods

PerformanceObserver.observe()

Specifies the set of entry types to observe. The performance observer's callback function will be invoked when performance entry is recorded for one of the specifiedentryTypes.

PerformanceObserver.disconnect()

Stops the performance observer callback from receiving performance entries.

PerformanceObserver.takeRecords()

Returns the current list of performance entries stored in the performance observer, emptying it out.

Examples

Creating a PerformanceObserver

The following example creates aPerformanceObserver watching for "mark" (PerformanceMark) and "measure" (PerformanceMeasure) events.TheperfObserver callback provides alist (PerformanceObserverEntryList) which allows you to get observed performance entries.

js
function perfObserver(list, observer) {  list.getEntries().forEach((entry) => {    if (entry.entryType === "mark") {      console.log(`${entry.name}'s startTime: ${entry.startTime}`);    }    if (entry.entryType === "measure") {      console.log(`${entry.name}'s duration: ${entry.duration}`);    }  });}const observer = new PerformanceObserver(perfObserver);observer.observe({ entryTypes: ["measure", "mark"] });

Specifications

Specification
Performance Timeline
# dom-performanceobserver

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp