This commit is contained in:
haha1903 2026-07-14 17:20:49 +00:00 committed by GitHub
commit a2ddfba035
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 11 deletions

View File

@ -342,6 +342,7 @@ export class BrowserManager {
// BROWSE_EXTENSIONS_DIR points to an unpacked Chrome extension directory.
// Extensions only work in headed mode, so we use an off-screen window.
const extensionsDir = process.env.BROWSE_EXTENSIONS_DIR;
const channel = process.env.BROWSE_CHANNEL;
const { STEALTH_LAUNCH_ARGS, buildGStackLaunchArgs } = await import('./stealth');
const launchArgs: string[] = [...STEALTH_LAUNCH_ARGS, ...buildGStackLaunchArgs()];
let useHeadless = true;
@ -369,7 +370,7 @@ export class BrowserManager {
console.log(`[browse] Extensions loaded from: ${extensionsDir}`);
}
this.browser = await chromium.launch({
const launchOpts = {
headless: useHeadless,
// On Windows, Chromium's sandbox fails when the server is spawned through
// the Bun→Node process chain (GitHub #276). Disable it — local daemon
@ -379,7 +380,24 @@ export class BrowserManager {
chromiumSandbox: shouldEnableChromiumSandbox(),
...(launchArgs.length > 0 ? { args: launchArgs } : {}),
...(this.proxyConfig ? { proxy: this.proxyConfig } : {}),
});
};
const contextOpts: BrowserContextOptions = {
viewport: this.currentViewport,
deviceScaleFactor: this.deviceScaleFactor,
...(this.customUserAgent ? { userAgent: this.customUserAgent } : {}),
};
if (channel) {
// launchPersistentContext enables macOS platform SSO (newContext does not)
this.context = await chromium.launchPersistentContext('', {
...launchOpts, ...contextOpts, channel,
});
this.browser = this.context.browser();
} else {
this.browser = await chromium.launch(launchOpts);
this.context = await this.browser.newContext(contextOpts);
}
// Chromium disconnect → distinguish clean user-quit from crash. Both
// events look identical to Playwright (one 'disconnected' fires), but
@ -394,15 +412,6 @@ export class BrowserManager {
void handleChromiumDisconnect(this.browser);
});
const contextOptions: BrowserContextOptions = {
viewport: { width: this.currentViewport.width, height: this.currentViewport.height },
deviceScaleFactor: this.deviceScaleFactor,
};
if (this.customUserAgent) {
contextOptions.userAgent = this.customUserAgent;
}
this.context = await this.browser.newContext(contextOptions);
if (Object.keys(this.extraHeaders).length > 0) {
await this.context.setExtraHTTPHeaders(this.extraHeaders);
}