Skip to content

Commit

Permalink
Document PerformanceObserver's droppedEntriesCount (mdn#22318)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
  • Loading branch information
2 people authored and hamishwillee committed Dec 9, 2022
1 parent 84b4902 commit 3591f1f
Showing 1 changed file with 27 additions and 1 deletion.
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

0 comments on commit 3591f1f

Please sign in to comment.