/** * Playwright's surface, described structurally rather than imported. * * The plugin must type-check and install in a repository that has no browsers * anywhere near it — a Go service that only runs HTTP smoke checks should not * pull down 300MB because this package exists in the registry. So `playwright` * is an optional peer dependency, loaded at the moment a browser is first * needed, and the types below are the only coupling at build time. */ export type BrowserName = 'chromium' | 'firefox' | 'webkit' export interface Page { goto(url: string, options?: Record): Promise<{ status(): number } | null> title(): Promise url(): string click(selector: string, options?: Record): Promise fill(selector: string, value: string, options?: Record): Promise press(selector: string, key: string, options?: Record): Promise textContent(selector: string, options?: Record): Promise waitForSelector(selector: string, options?: Record): Promise isVisible(selector: string, options?: Record): Promise screenshot(options?: Record): Promise close(): Promise } export interface BrowserContext { newPage(): Promise close(): Promise } export interface Browser { newContext(options?: Record): Promise close(): Promise } export interface BrowserType { launch(options?: Record): Promise } const INSTALL_HINT = "@speqkit/plugin-playwright needs the 'playwright' package, which it does not bundle.\n" + ' pnpm add -D playwright && pnpm exec playwright install chromium' export async function loadBrowserType(name: BrowserName): Promise { // An indirect specifier on purpose: the module is resolved at run time by // the host project, not at build time by this package. const specifier = 'playwright' let mod: Record try { mod = (await import(specifier)) as Record } catch (err) { throw new Error(`${INSTALL_HINT}\n (import failed: ${err instanceof Error ? err.message : String(err)})`) } const type = mod[name] as BrowserType | undefined if (!type?.launch) { throw new Error(`playwright exposes no browser named '${name}'; expected chromium, firefox or webkit`) } return type }