ladybird/Tests/LibWeb/Text/input/performance-timing-and-navigation-not-exposed-outside-of-window.html
Luke Wilde da5fca15ee LibWeb: Only expose performance.{timing,navigation} on Window
They are only valid in a Window context, and the spec only exposes them
in Window contexts.

Fixes workers crashing on:
- https://web.whatsapp.com/
- https://pro.kraken.com/app/trade/btc-usd
2025-07-25 11:46:58 +02:00

36 lines
1.4 KiB
HTML

<!DOCTYPE html>
<script type="worker">
globalThis.onmessage = () => {
const result = [];
result.push("(worker) navigation: " + typeof performance.navigation);
result.push("(worker) timing: " + typeof performance.timing);
result.push("(worker) performance JSON: " + JSON.stringify(performance));
postMessage(result);
}
</script>
<script src="include.js"></script>
<script>
asyncTest((done) => {
const replacePotentiallyFlakyTimes = (string) => {
return string.replace(/("[a-zA-Z]+":)(\d+(\.\d+)?)/g, "$1[removed-potentially-flaky-time-value]");
};
println("(window) navigation: " + typeof performance.navigation);
println("(window) timing: " + typeof performance.timing);
println("(window) performance JSON: " + replacePotentiallyFlakyTimes(JSON.stringify(performance)));
const workerSource = document.querySelector('[type=worker]').innerText;
const workerBlob = new Blob([workerSource], { type: "text/javascript" });
const workerBlobURL = URL.createObjectURL(workerBlob);
const worker = new Worker(workerBlobURL);
worker.onmessage = ({ data }) => {
for (const string of data) {
println(replacePotentiallyFlakyTimes(string));
}
done();
};
worker.postMessage("start");
});
</script>