> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# PerformanceObserver

APISummary
The `PerformanceObserver` is used to observe performance events and receive notifications when [Lynx Engine](/next/guide/spec.md#engine) generates [performance entries](/next/api/lynx-api/performance-api/performance-entry.md).
It must be created through [`lynx.performance.createObserver()`](/next/api/lynx-api/lynx/lynx-performance/create-observer.md) and bind with a callback function for handling received performance entries upon creation.

## Instance methods

[`PerformanceObserver.observe()`](/next/api/lynx-api/performance-api/performance-observer/observe.md)

Specify a set of performance entry types to observe and start observing.

[`PerformanceObserver.disconnect()`](/next/api/lynx-api/performance-api/performance-observer/disconnect.md)

Stop receiving performance entries.

## Examples

### Creating a PerformanceObserver

The following example creates a `PerformanceObserver` watching for [`metric.fcp`](/next/api/lynx-api/performance-api/performance-entry/metric-fcp-entry.md) and [`pipeline`](/next/api/lynx-api/performance-api/performance-entry/pipeline-entry.md) entries.

**This is an example below: performance-api**

**Entry:** `src/simple-observe`
**Bundle:** `dist/simple-observe.lynx.bundle`

```tsx {11-30}
import * as React from "@lynx-js/react";
import { root, useMemo, useState } from "@lynx-js/react";
import type { PerformanceEntry } from "@lynx-js/types";
import "../common/common.css";
import "./index.css";

export default function SimpleObserveExample(this: any) {
  const [receivedEntries, setReceivedEntries] = useState<Set<string>>(new Set<string>());

  useMemo(() => {
    "background-only";
    // 1. Create a performance observer.
    const observer = lynx.performance.createObserver((entry: PerformanceEntry) => {
      // 3. process "metric.fsp" and "pipeline"
      let entryType: string | undefined;
      if (entry.entryType == "metric" && entry.name == "fsp") {
        entryType = "MetricFspEntry";
      } else if (entry.entryType == "pipeline") {
        entryType = "PipelineEntry";
      }
      if (entryType) {
        setReceivedEntries(prevEntries => {
          const newEntries = new Set(prevEntries);
          newEntries.add(entryType);
          return newEntries;
        });
      }
    });
    // 2. register to listen to the "metric.fsp" and "pipeline" event.
    observer.observe(["metric.fsp", "pipeline"]);
  }, []);

  return (
    <view className="container">
      <view className="title-container">
        <text className="title">Hello PerformanceObserver</text>
      </view>
      <view className="card">
        <text className="section-title">Received PerformanceEntry:</text>
        <view className="entries-container">
          {Array.from(receivedEntries).map((entryName, index) => (
            <text
              key={index}
              className="entry-item"
            >
              {entryName}
            </text>
          ))}
        </view>
      </view>
    </view>
  );
}

root.render(<SimpleObserveExample />);

if (import.meta.webpackHot) {
  import.meta.webpackHot.accept();
}

```

v0.8.0



## Compatibility

**Compatibility Table**

**Query:** `lynx-api.performance-api.performance-observer`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/performance-api/performance-observer.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| performance-observer | Yes (3.1) | Yes (3.4) | Yes (3.1) | Yes (3.7) | Yes (3.7) | No |

