Skip to content

Commit fcd1658

Browse files
committed
feat(browse): multi-browser support via BROWSE_BROWSER env var
Replaces hardcoded chromium.launch() with configurable browser engine. Playwright supports 3 engines — all now accessible: BROWSE_BROWSER=chromium # default (Chrome, Edge, Brave, Arc) BROWSE_BROWSER=firefox # Firefox BROWSE_BROWSER=webkit # Safari engine Both launch() and handoff() use getBrowserType() — no more hardcoded chromium references. When unset, defaults to chromium (zero change).
1 parent 7fbf68b commit fcd1658

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

browse/src/browser-manager.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,25 @@
1515
* restores state. Falls back to clean slate on any failure.
1616
*/
1717

18-
import { chromium, type Browser, type BrowserContext, type BrowserContextOptions, type Page, type Locator, type Cookie } from 'playwright';
18+
import { chromium, firefox, webkit, type Browser, type BrowserContext, type BrowserContextOptions, type Page, type Locator, type Cookie } from 'playwright';
19+
20+
/**
21+
* Resolve browser engine from BROWSE_BROWSER env var.
22+
* Supported: chromium (default), firefox, webkit (Safari engine).
23+
* Edge uses Chromium engine — set BROWSE_BROWSER=chromium (or omit).
24+
*/
25+
function getBrowserType() {
26+
const name = (process.env.BROWSE_BROWSER || 'chromium').toLowerCase();
27+
switch (name) {
28+
case 'firefox': return firefox;
29+
case 'webkit':
30+
case 'safari': return webkit;
31+
case 'chromium':
32+
case 'chrome':
33+
case 'edge':
34+
default: return chromium;
35+
}
36+
}
1937
import { addConsoleEntry, addNetworkEntry, addDialogEntry, networkBuffer, type DialogEntry } from './buffers';
2038
import { validateNavigationUrl } from './url-validation';
2139

@@ -62,7 +80,9 @@ export class BrowserManager {
6280
private consecutiveFailures: number = 0;
6381

6482
async launch() {
65-
this.browser = await chromium.launch({ headless: true });
83+
const browserType = getBrowserType();
84+
console.error(`[browse] Launching ${browserType.name()} (headless)`);
85+
this.browser = await browserType.launch({ headless: true });
6686

6787
// Chromium crash → exit with clear message
6888
this.browser.on('disconnected', () => {
@@ -464,7 +484,7 @@ export class BrowserManager {
464484
// 2. Launch new headed browser (try-catch — if this fails, headless stays running)
465485
let newBrowser: Browser;
466486
try {
467-
newBrowser = await chromium.launch({ headless: false, timeout: 15000 });
487+
newBrowser = await getBrowserType().launch({ headless: false, timeout: 15000 });
468488
} catch (err: unknown) {
469489
const msg = err instanceof Error ? err.message : String(err);
470490
return `ERROR: Cannot open headed browser — ${msg}. Headless browser still running.`;

0 commit comments

Comments
 (0)