Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.3 KB
Raw Blame
import { JSDOM } from "jsdom";

const dom = new JSDOM("<!doctype html><html><body></body></html>", { url: "http://localhost" });

for (const key of [
  "window",
  "document",
  "HTMLElement",
  "Element",
  "Node",
  "Event",
  "CustomEvent",
  "MouseEvent",
  "KeyboardEvent",
] as const) {
  try {
    (globalThis as unknown as Record<string, unknown>)[key] = (
      dom.window as unknown as Record<string, unknown>
    )[key];
  } catch {}
}
try {
  Object.defineProperty(globalThis, "navigator", {
    value: dom.window.navigator,
    configurable: true,
    writable: true,
  });
} catch {}
try {
  (globalThis as unknown as Record<string, unknown>).getComputedStyle =
    dom.window.getComputedStyle.bind(dom.window);
} catch {}

if (typeof (globalThis as unknown as { matchMedia?: unknown }).matchMedia !== "function") {
  (globalThis as unknown as { window: { matchMedia?: unknown } }).window.matchMedia = () =>
    ({
      matches: false,
      media: "",
      onchange: null,
      addListener: () => {},
      removeListener: () => {},
      addEventListener: () => {},
      removeEventListener: () => {},
      dispatchEvent: () => false,
    }) as unknown as MediaQueryList;
  (globalThis as unknown as Record<string, unknown>).matchMedia = (
    globalThis as unknown as { window: { matchMedia: unknown } }
  ).window.matchMedia;
}