fix(browser): cleaned headless profile after failed launch

Remove the OMP-owned Chromium user-data directory when executable resolution or puppeteer launch fails before a browser handle exists.

Fixes #7058
This commit is contained in:
roboomp
2026-07-30 05:19:18 +00:00
parent afd6f8eed4
commit 7ab3d2ecb6
@@ -338,16 +338,23 @@ export async function launchHeadlessBrowser(opts: LaunchHeadlessOptions): Promis
userDataDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "omp-chrome-profile-"));
launchArgs.push(`--user-data-dir=${userDataDir}`);
}
const executablePath = await ensureChromiumExecutable();
const browser = await puppeteer.launch({
headless: opts.headless,
defaultViewport: opts.headless ? initialViewport : null,
executablePath,
args: launchArgs,
ignoreDefaultArgs: [...new Set([...stealthIgnoreDefaultArgs(executablePath), ...(opts.ignoreDefaultArgs ?? [])])],
protocolTimeout: BROWSER_PROTOCOL_TIMEOUT_MS,
});
return { browser, userDataDir };
try {
const executablePath = await ensureChromiumExecutable();
const browser = await puppeteer.launch({
headless: opts.headless,
defaultViewport: opts.headless ? initialViewport : null,
executablePath,
args: launchArgs,
ignoreDefaultArgs: [
...new Set([...stealthIgnoreDefaultArgs(executablePath), ...(opts.ignoreDefaultArgs ?? [])]),
],
protocolTimeout: BROWSER_PROTOCOL_TIMEOUT_MS,
});
return { browser, userDataDir };
} catch (error) {
if (userDataDir) await removeUserDataDir(userDataDir);
throw error;
}
}
/**