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 val = AsyncContext.Variable(); | |
async main() { | |
console.log(val.get()); // Expect: undefined | |
await val.withValue(1); | |
console.log(val.get()); // Expect: 1 | |
await 1; | |
console.log(val.get()); // Expect: 1 |
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
<script> | |
const observer = new PerformanceObserver(list => { | |
for (let entry of list.getEntries()) { | |
const size = entry.size || entry.intersectionRect.height * entry.intersectionRect.width; | |
console.log(entry.entryType, size, entry.element, entry); | |
if (entry.intersectionRect) showRect(entry.intersectionRect); | |
} | |
}) | |
observer.observe({ type: 'element', buffered: true }); | |
observer.observe({ type: 'largest-contentful-paint', buffered: true }); |
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 eventsForTiming = [ | |
'keydown', | |
'keypress', | |
'keyup', | |
'pointerdown', | |
'pointerup', | |
'click', | |
]; | |
// Add this as early as possible in order to measure events which stop propagation. |
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
<!-- Add to <head> or as first script in body before any content --> | |
<script type='text/javascript'> | |
const observedElements = new WeakSet(); // Keep track of processed elements | |
new MutationObserver((mutationsList, observer) => { | |
for (let mutation of mutationsList) { | |
for (let node of mutation.addedNodes) { | |
if (node.nodeType === Node.ELEMENT_NODE && !observedElements.has(node)) { | |
node.setAttribute('elementtiming', 'test'); | |
observedElements.add(node); // Mark the element as processed |
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 interestingEventTypes = [ 'pointerdown', 'pointerup', 'click', 'keydown', 'keypress', 'keyup']; | |
const mapOfTargets = Object.fromEntries(interestingEventTypes.map(type => [type, {}])); | |
interestingEventTypes.forEach(type => | |
document.addEventListener(type, (event) => { | |
// TODO: Improve this | |
const nodeType = event.target.nodeName.toLowerCase(); | |
const nodeId = event.target.id; | |
const nodeClasses = event.target.className.replace(/\s/g, '.'); |
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
function processArrayOfWork(arr) { | |
const item = arr.shift(); | |
console.log(`Processing array item: ${item}`); | |
if (arr.length > 0) { | |
// Recursive call. | |
processArrayOfWork(arr); | |
} else { | |
console.log('End processing array of data.'); | |
} |
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
(() => { | |
// processLoAFEntry.js | |
function floorObject(o) { | |
return Object.fromEntries( | |
Array.from(Object.entries(o)).map(([key, value]) => [ | |
key, | |
typeof value === "number" ? Math.floor(value) : value | |
]) | |
); | |
} |
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 RATING_COLORS = { | |
good: "#0CCE6A", | |
"needs-improvement": "#FFA400", | |
poor: "#FF4E42" | |
}; | |
function onInteraction(callback) { | |
const valueToRating = (score) => | |
score <= 200 ? "good" : score <= 500 ? "needs-improvement" : "poor"; |
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
// max-INP: | |
(()=>{let o=globalThis;return void 0===o.winp&&(o.winp=0,new PerformanceObserver(n=>{for(let e of n.getEntries()){if(!e.interactionId)continue;o.winp=Math.max(e.duration,o.winp);let r=o=>o<=200?"color: green":o<=500?"color: yellow":"color: red";console.log(`%c[Interaction: ${e.name.padEnd(12)}] %cDuration: %c${e.duration}`,"color: grey; font-family: Consolas,monospace","",r(e.duration))}}).observe({type:"event",durationThreshold:0,buffered:!0})),o.winp})(); | |
// interactionCount | |
performance.interactionCount; |
NewerOlder