fix: auto-detect headless environment for Playwright browser launch (#183)
Browser launch was hardcoded to headless: false, crashing on Linux servers without a display server ($DISPLAY). Auto-detect headless environments and also support FORCE_HEADLESS=true override. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
66196b4a4f
commit
788c356a25
1 changed files with 6 additions and 1 deletions
|
|
@ -181,7 +181,12 @@ export async function ensureBrowser(): Promise<{ browser: Browser; context: Brow
|
|||
// Lazy import so playwright is only loaded when actually needed
|
||||
const { chromium } = await import("playwright");
|
||||
|
||||
const launchOptions: Record<string, unknown> = { headless: false };
|
||||
// Auto-detect headless environments: Linux without $DISPLAY has no GUI.
|
||||
// All browser tool operations (navigation, screenshots, DOM) work in headless mode.
|
||||
const needsHeadless = process.platform === "linux" && !process.env.DISPLAY;
|
||||
const launchOptions: Record<string, unknown> = {
|
||||
headless: needsHeadless || process.env.FORCE_HEADLESS === "true",
|
||||
};
|
||||
const customPath = process.env.BROWSER_PATH;
|
||||
if (customPath) launchOptions.executablePath = customPath;
|
||||
const browser = await chromium.launch(launchOptions);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue