← snapshot
1536 bytes
/** Throws in a real page and checks the relay fired. */
import { chromium } from "@playwright/test";
const b = await chromium.launch();
const p = await b.newPage({ colorScheme: "dark" });
let posted = null;
await p.route("**/api/telemetry/bug", async (route) => {
posted = JSON.parse(route.request().postData() ?? "{}");
await route.continue();
});
await p.goto("http://localhost:3000/lab", { waitUntil: "networkidle" });
await p.waitForTimeout(1500);
// A genuine uncaught error, the way a broken render would produce one.
await p.evaluate(() => {
setTimeout(() => { throw new Error("probe: uncaught from the page"); }, 0);
});
await p.waitForTimeout(1200);
console.log("window error reported:", posted ? JSON.stringify({
message: posted.message, pathname: posted.pathname, kind: posted.kind,
hasStack: Boolean(posted.stack),
}) : "NOT REPORTED");
// And an unhandled rejection.
posted = null;
await p.evaluate(() => { void Promise.reject(new Error("probe: unhandled rejection")); });
await p.waitForTimeout(1200);
console.log("rejection reported:", posted ? posted.message + " / " + posted.kind : "NOT REPORTED");
// Repeats of the same failure must not flood.
posted = null;
let count = 0;
await p.route("**/api/telemetry/bug", async (r) => { count++; await r.continue(); });
for (let i = 0; i < 5; i++) {
await p.evaluate(() => { setTimeout(() => { throw new Error("probe: uncaught from the page"); }, 0); });
}
await p.waitForTimeout(1200);
console.log("5 repeats ->", count, "reports (deduped)");
await b.close();