Skip to content

Instantly share code, notes, and snippets.

@c-j-j
Created February 24, 2021 16:57
Show Gist options
  • Save c-j-j/5ff6bea351d676e22231045fd4ad4b6f to your computer and use it in GitHub Desktop.
Save c-j-j/5ff6bea351d676e22231045fd4ad4b6f to your computer and use it in GitHub Desktop.
Chrome extension: CLS Logger
console.log("MONITORING CLS")
let cls = 0;
new PerformanceObserver((entryList) => {
for (const entry of entryList.getEntries()) {
if (!entry.hadRecentInput) {
cls += entry.value;
console.log('Current CLS value:', cls, entry);
}
}
}).observe({type: 'layout-shift', buffered: true});
{
"name": "CLS Monitoring",
"version": "1.0",
"description": "Monitors CLS on a page",
"content_scripts": [
{
"matches": [
"https://www.example.co.uk/*"
],
"run_at": "document_start",
"js": [
"contentScript.js"
]
}
],
"manifest_version": 2,
"permissions": [
"activeTab"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment