mirror of https://github.com/garrytan/gstack.git
merge: PR #315 - feat(browse): support Chrome extensions via BROWSE_EXTENSIONS_DIR
This commit is contained in:
commit
baf3c1b23c
|
|
@ -62,7 +62,28 @@ export class BrowserManager {
|
||||||
private consecutiveFailures: number = 0;
|
private consecutiveFailures: number = 0;
|
||||||
|
|
||||||
async launch() {
|
async launch() {
|
||||||
this.browser = await chromium.launch({ headless: true });
|
// ─── Extension Support ────────────────────────────────────
|
||||||
|
// 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 launchArgs: string[] = [];
|
||||||
|
let useHeadless = true;
|
||||||
|
|
||||||
|
if (extensionsDir) {
|
||||||
|
launchArgs.push(
|
||||||
|
`--disable-extensions-except=${extensionsDir}`,
|
||||||
|
`--load-extension=${extensionsDir}`,
|
||||||
|
'--window-position=-9999,-9999',
|
||||||
|
'--window-size=1,1',
|
||||||
|
);
|
||||||
|
useHeadless = false; // extensions require headed mode; off-screen window simulates headless
|
||||||
|
console.log(`[browse] Extensions loaded from: ${extensionsDir}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.browser = await chromium.launch({
|
||||||
|
headless: useHeadless,
|
||||||
|
...(launchArgs.length > 0 ? { args: launchArgs } : {}),
|
||||||
|
});
|
||||||
|
|
||||||
// Chromium crash → exit with clear message
|
// Chromium crash → exit with clear message
|
||||||
this.browser.on('disconnected', () => {
|
this.browser.on('disconnected', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue