1// Runs the console script's synchronous start against a stub document, so a2// handler wired above the helper it calls, or any other error before the3// first await, fails typecheck instead of a live page. Syntax alone is not4// enough: `node --check` passed the day the page came up empty.5import { readFileSync } from "node:fs";67const js = readFileSync(new URL("../../src/console/console.js", import.meta.url), "utf8");89// Every element lookup answers with an object that accepts any property and10// any method call, so the script gets through its wiring.11const element = () => new Proxy(function () {}, {12 get: (_, k) => (k === Symbol.toPrimitive ? () => "" : k === "classList" ? { toggle() {}, add() {}, remove() {}, contains: () => false } : k === "style" ? { setProperty() {} } : element()),13 set: () => true,14 apply: () => element(),15});16const doc = element();17const define = (k, v) => Object.defineProperty(globalThis, k, { value: v, configurable: true, writable: true });18define("document", doc);19define("window", globalThis);20define("location", { host: "check.localhost", hostname: "check.localhost", origin: "http://check.localhost", protocol: "http:", hash: "", pathname: "/", search: "" });21define("localStorage", { getItem: () => null, setItem() {}, removeItem() {} });22define("history", { replaceState() {} });23define("navigator", { clipboard: { writeText: async () => {} } });24define("confirm", () => false);25define("prompt", () => null);26define("alert", () => {});27// fetch never answers, so the boot stops at its first await and only the synchronous start is judged.28define("fetch", () => new Promise(() => {}));29define("WebSocket", class { close() {} send() {} });30define("SIGNER_URL", "/signer.js");31define("addEventListener", () => {});32define("ResizeObserver", class { observe() {} disconnect() {} });3334let failed = null;35process.on("unhandledRejection", (e) => { failed = e; });36try {37 new Function(js)();38 // The script is an async IIFE; its synchronous part runs before this resolves.39 await new Promise((r) => setTimeout(r, 50));40} catch (e) {41 failed = e;42}43if (failed) {44 console.error("console script fails before it boots:", failed);45 process.exit(1);46}47console.log("console script starts");