diff --git a/files/en-us/web/api/performanceobserver/performanceobserver/index.md b/files/en-us/web/api/performanceobserver/performanceobserver/index.md index 5d4271377d40f7e..c81d7d5dfafad62 100644 --- a/files/en-us/web/api/performanceobserver/performanceobserver/index.md +++ b/files/en-us/web/api/performanceobserver/performanceobserver/index.md @@ -19,13 +19,22 @@ new PerformanceObserver(callback) ### Parameters - `callback` + - : 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. + - `options` + + - : An object with the following properties: + + - `droppedEntriesCount` + + - : The number of entries which could not be recorded because the {{domxref("Performance")}} object's internal buffer was full. + + Note that this is only provided the first time the observer calls the callback, when the buffered entries are replayed. Once the observer starts making future observations, it no longer needs to use the buffer. After the first time, `options` will be an empty object (`{}`). ### Return value @@ -56,19 +65,20 @@ 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. +There is a buffer size limit, though. The performance observer callback contains an `options` object: the first time the observer calls the callback, the `options` parameter will have a `droppedEntriesCount` property that tells you how many entries were dropped due to the buffer storage being full. Subsequent callbacks will have an empty `options` parameter. ```js -function perfObserver(list, observer, droppedEntriesCount) { +function perfObserver(list, observer, options) { list.getEntries().forEach((entry) => { // do something with the entries }); - if (droppedEntriesCount > 0) { + if (options?.droppedEntriesCount > 0) { console.warn( - `${droppedEntriesCount} entries got dropped due to the buffer being full.`, + `${options?.droppedEntriesCount} entries got dropped due to the buffer being full.`, ); } } + const observer = new PerformanceObserver(perfObserver); observer.observe({ type: "resource", buffered: true }); ```