Last active
March 10, 2023 04:00
-
-
Save gitgrimbo/ff1e0a01b3b55c36ad5b to your computer and use it in GitHub Desktop.
Overcome performance.getEntries() limit of 150 resources
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
Browser hacks |
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
/* | |
Some code to pull more than 150 performance entries when "onresourcetimingbufferfull" or | |
"onwebkitresourcetimingbufferfull" events are available. | |
An internal entries array is maintained and added to when the either the buffer is full, | |
or the allEntries() function is called. | |
*/ | |
allEntries = (function() { | |
var entries = []; | |
function pullEntries() { | |
var latestEntries = performance.getEntriesByType("resource"); | |
entries = entries.concat(latestEntries); | |
var meth = "clearResourceTimings"; | |
if (!performance[meth]) { | |
meth = "webkitClearResourceTimings"; | |
} | |
performance[meth](); | |
return entries; | |
} | |
if ("performance" in window) { | |
performance.onresourcetimingbufferfull = performance.onwebkitresourcetimingbufferfull = pullEntries; | |
return pullEntries; | |
} | |
return function() { console.log("NOT SUPPORTED"); }; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment