Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document PerformanceObserver's droppedEntriesCount #22318

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ new PerformanceObserver(callback)
### Parameters

- `callback`
- : A `PerformanceObserverCallback` callback that will be invoked when observed performance events are recorded. When the callback is invoked, its first parameter is a {{domxref("PerformanceObserverEntryList","list of performance observer entries", '', 'true')}} and the second parameter is the {{domxref("PerformanceObserver","observer")}} object.
- : A `PerformanceObserverCallback` callback that will be invoked when observed performance events are recorded. When the callback is invoked, the following parameters are available:
- `entries`
- : The {{domxref("PerformanceObserverEntryList","list of performance observer entries", '', 'true')}}.
- `observer`
- : The {{domxref("PerformanceObserver","observer")}} object that is receiving the above entries.
- `droppedEntriesCount` {{optional_inline}}
- : The number of buffered entries which got dropped from the buffer due to the buffer being full. See the [`buffered`](/en-US/docs/Web/API/PerformanceObserver/observe#parameters) flag.

### Return value

Expand Down Expand Up @@ -52,6 +58,26 @@ const observer = new PerformanceObserver(perfObserver);
observer.observe({ entryTypes: ["measure", "mark"] });
```

### Dropped buffer entries

You can use {{domxref("PerformanceObserver")}} with a `buffered` flag to listen to past performance entries.
There is a buffer size limit, though. The performance observer callback contains an optional `droppedEntriesCount` parameter that informs you about the amount of lost entries due to the buffer storage being full.

```js
function perfObserver(list, observer, droppedEntriesCount) {
list.getEntries().forEach((entry) => {
// do something with the entries
});
if (droppedEntriesCount > 0) {
console.warn(`${droppedEntriesCount} entries got dropped due to the buffer being full.`);
}
}
const observer = new PerformanceObserver(perfObserver);
observer.observe({ type: "resource", buffered: true });
```

Usually, there are a lot of resource timing entries, and for these entries specifically, you can also set a larger buffer using {{domxref("performance.setResourceTimingBufferSize()")}} and watch for the {{domxref("Performance/resourcetimingbufferfull_event", "resourcetimingbufferfull")}} event.

## Specifications

{{Specifications}}
Expand Down