mirror of https://github.com/garrytan/gstack.git
Merge ae1d370802 into 7c9df1c568
This commit is contained in:
commit
a2ddfba035
|
|
@ -342,6 +342,7 @@ export class BrowserManager {
|
||||||
// BROWSE_EXTENSIONS_DIR points to an unpacked Chrome extension directory.
|
// BROWSE_EXTENSIONS_DIR points to an unpacked Chrome extension directory.
|
||||||
// Extensions only work in headed mode, so we use an off-screen window.
|
// Extensions only work in headed mode, so we use an off-screen window.
|
||||||
const extensionsDir = process.env.BROWSE_EXTENSIONS_DIR;
|
const extensionsDir = process.env.BROWSE_EXTENSIONS_DIR;
|
||||||
|
const channel = process.env.BROWSE_CHANNEL;
|
||||||
const { STEALTH_LAUNCH_ARGS, buildGStackLaunchArgs } = await import('./stealth');
|
const { STEALTH_LAUNCH_ARGS, buildGStackLaunchArgs } = await import('./stealth');
|
||||||
const launchArgs: string[] = [...STEALTH_LAUNCH_ARGS, ...buildGStackLaunchArgs()];
|
const launchArgs: string[] = [...STEALTH_LAUNCH_ARGS, ...buildGStackLaunchArgs()];
|
||||||
let useHeadless = true;
|
let useHeadless = true;
|
||||||
|
|
@ -369,7 +370,7 @@ export class BrowserManager {
|
||||||
console.log(`[browse] Extensions loaded from: ${extensionsDir}`);
|
console.log(`[browse] Extensions loaded from: ${extensionsDir}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.browser = await chromium.launch({
|
const launchOpts = {
|
||||||
headless: useHeadless,
|
headless: useHeadless,
|
||||||
// On Windows, Chromium's sandbox fails when the server is spawned through
|
// On Windows, Chromium's sandbox fails when the server is spawned through
|
||||||
// the Bun→Node process chain (GitHub #276). Disable it — local daemon
|
// the Bun→Node process chain (GitHub #276). Disable it — local daemon
|
||||||
|
|
@ -379,7 +380,24 @@ export class BrowserManager {
|
||||||
chromiumSandbox: shouldEnableChromiumSandbox(),
|
chromiumSandbox: shouldEnableChromiumSandbox(),
|
||||||
...(launchArgs.length > 0 ? { args: launchArgs } : {}),
|
...(launchArgs.length > 0 ? { args: launchArgs } : {}),
|
||||||
...(this.proxyConfig ? { proxy: this.proxyConfig } : {}),
|
...(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
|
// Chromium disconnect → distinguish clean user-quit from crash. Both
|
||||||
// events look identical to Playwright (one 'disconnected' fires), but
|
// events look identical to Playwright (one 'disconnected' fires), but
|
||||||
|
|
@ -394,15 +412,6 @@ export class BrowserManager {
|
||||||
void handleChromiumDisconnect(this.browser);
|
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) {
|
if (Object.keys(this.extraHeaders).length > 0) {
|
||||||
await this.context.setExtraHTTPHeaders(this.extraHeaders);
|
await this.context.setExtraHTTPHeaders(this.extraHeaders);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue