Skip to content

Commit cb7c2d7

Browse files
committed
Add Long Task script
1 parent 2016a99 commit cb7c2d7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,24 @@ timingOptions.forEach((timing) => {
355355

356356
console.table(calculateTimings("first", "REQ_START_UNTIL_RES_END"));
357357
```
358+
## Interaction
359+
360+
### Long Task
361+
362+
To determine when long tasks happen, you can use [PerformanceObserver](https://developer.mozilla.org/docs/Web/API/PerformanceObserver) and register to observe entries of type `longtask`:
363+
364+
```js
365+
try {
366+
// Create the performance observer.
367+
const po = new PerformanceObserver((list) => {
368+
for (const entry of list.getEntries()) {
369+
// Log the entry and all associated details.
370+
console.table(entry.toJSON());
371+
}
372+
});
373+
// Start listening for `longtask` entries to be dispatched.
374+
po.observe({type: 'longtask', buffered: true});
375+
} catch (e) {
376+
console.log(`The browser doesn't support this API`)
377+
}
378+
```

0 commit comments

Comments
 (0)