Files
Codeman/test/mobile/helpers/browser.ts
T
Codeman maintainer f604deba3e chore: remove backend code nothing references
Found with knip (exports, types, class members) and confirmed by a text
search of src, test, scripts and packages before each removal.

- Per-CLI get<Cli>NotFoundMessage() (nine of them) with their message
  constants: missingCliMessage() builds that text from the registry now.
- Registry leftovers: renderCliCommand, asCliId, cliIds, isCliRunnable,
  createCliResolverForTest, profileExists, and two name lists that only
  repeated schema enums.
- A task-description cache in Session that was written on every chunk of
  terminal output (one regex pass per line) and never read since the
  subagent watcher takes descriptions from transcripts. The cache module,
  its pattern and both parse methods go with it.
- Session.parentAgentId / childAgentIds: never set by anything, so the two
  optional SessionState fields were never on the wire.
- Unreferenced methods on TmuxManager (pipe-pane pair, syncMouseMode),
  RespawnController, StateStore.recoverFromBackup (load() already falls
  back to the .bak file), TeamWatcher, SseStreamManager and the AI
  checkers' getErrorVerdict.
- updateCaseEnvVars: the settings.local.json env path that envOverrides
  replaced.
- Re-exports in the utils, cli-registry, routes and prompts barrels that
  no importer used, and unused test helpers (MockStateStore, the mobile
  throttle helpers and others).

Eight mobile tests imported the WebServer type from a path that does not
exist (../src instead of ../../src); type-only, so nothing failed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-13 13:58:22 +01:00

63 lines
2.1 KiB
TypeScript

import { chromium, webkit, type Browser, type BrowserContext, type Page } from 'playwright';
import type { DeviceEntry } from '../devices.js';
const browsers: Record<string, Browser> = {};
export async function getBrowser(engine: 'chromium' | 'webkit' = 'chromium'): Promise<Browser> {
if (!browsers[engine]?.isConnected()) {
const launcher = engine === 'webkit' ? webkit : chromium;
try {
browsers[engine] = await launcher.launch({ headless: true });
} catch (e: unknown) {
// Fall back to Chromium if WebKit libraries are missing
if (engine === 'webkit') {
const msg = e instanceof Error ? e.message : String(e);
if (msg.includes('Missing') || msg.includes('dependencies') || msg.includes('browserType.launch')) {
console.log('WebKit unavailable, falling back to Chromium');
return getBrowser('chromium');
}
}
throw e;
}
}
return browsers[engine];
}
export async function createDeviceContext(
device: DeviceEntry,
engineOverride?: 'chromium' | 'webkit',
): Promise<BrowserContext> {
const engine = engineOverride ?? device.defaultBrowserType;
const browser = await getBrowser(engine);
return browser.newContext({
viewport: device.viewport,
deviceScaleFactor: device.deviceScaleFactor,
isMobile: device.isMobile,
hasTouch: device.hasTouch,
userAgent: device.userAgent,
});
}
export async function createDevicePage(
device: DeviceEntry,
url: string,
engineOverride?: 'chromium' | 'webkit',
): Promise<{ context: BrowserContext; page: Page }> {
const context = await createDeviceContext(device, engineOverride);
const page = await context.newPage();
await page.goto(url, { waitUntil: 'domcontentloaded' });
// Wait for initial JS to execute and device classes to be applied
await page.waitForTimeout(1000);
return { context, page };
}
export async function closeAllBrowsers(): Promise<void> {
for (const [key, browser] of Object.entries(browsers)) {
if (browser.isConnected()) {
await browser.close();
}
delete browsers[key];
}
}