Created
May 6, 2024 07:02
-
-
Save pmdartus/eeb101c06829fae3235db386caff645f to your computer and use it in GitHub Desktop.
WPT async processing bug repro
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>WPT async processing</title> | |
</head> | |
<body> | |
<script> | |
/* Simulate synchronous processing */ | |
function sleep(duration) { | |
const endTime = performance.now() + duration; | |
while (performance.now() < endTime) {} | |
} | |
/* Mark web page test waterfall by sending a request. */ | |
function markWaterfall(name) { | |
return fetch(`/?step=${name}`); | |
} | |
function doWork(name) { | |
performance.mark(`${name}::start`); | |
sleep(500); | |
performance.mark(`${name}::end`); | |
const { duration, startTime } = performance.measure(name, { | |
start: `${name}::start`, | |
end: `${name}::end` | |
}); | |
console.log(`[${name}] duration: ${duration}, start: ${startTime}`); | |
} | |
doWork('sync'); | |
Promise.resolve().then(() => { | |
doWork('microtask'); | |
}); | |
setTimeout(() => { | |
doWork('timeout'); | |
}) | |
fetch('/').then(() => { | |
doWork('fetch'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment