-
-
Save willmendesneto/f9b7fc1a1800badf7e24136ccca3af75 to your computer and use it in GitHub Desktop.
Logging Long Tasks in your browser and Sending the data to be logged in your Analytics Platform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const observer = new PerformanceObserver((list) => { | |
const freezeThreshold = 300; | |
const perfEntries = list.getEntries(); | |
// Get a list of all the `longtask` entries to be added as payload for your Analytics API | |
const analyticsData = perfEntries.filter(entry => entry.duration > freezeThreshold); | |
// In case of any longtask found, it sends the data to be logged in your Analytics platform | |
if (analyticsData.length > 0) { | |
navigator.sendBeacon('/my-analytics-log-platform', analyticsData); | |
} | |
}); | |
// register observer for long task notifications | |
observer.observe({entryTypes: ['longtask']}); | |
// Long script execution after this will result in queueing | |
// and receiving 'longtask' entries in the observer. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment