fix(IncognitoBrowser): Enhance IncognitoBrowser error handling and process management

This commit is contained in:
2025-02-25 17:33:48 +00:00
parent 1839c56130
commit 6ef281c871
5 changed files with 8322 additions and 3292 deletions

View File

@@ -9,33 +9,44 @@ export const getEnvAwareBrowserInstance = async (
optionsArg: IEnvAwareOptions = {}
): Promise<plugins.puppeteer.Browser> => {
const options: IEnvAwareOptions = {
...{
forceNoSandbox: false,
},
forceNoSandbox: false,
...optionsArg,
};
let chromeArgs: string[] = [];
if (process.env.CI || options.forceNoSandbox || plugins.os.userInfo().username === 'root') {
if (
process.env.CI ||
options.forceNoSandbox ||
plugins.os.userInfo().username === 'root'
) {
chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']);
console.warn('********************************************************');
console.warn('WARNING: Launching browser without sandbox. This can be insecure!');
console.warn('********************************************************');
}
let headlessBrowser: plugins.puppeteer.Browser;
console.log('launching puppeteer bundled chrome with arguments:');
// Automatically choose an executable if available: prefer google-chrome, then chromium, then chromium-browser.
const execPath =
plugins.smartshell.which.sync('google-chrome') ||
plugins.smartshell.which.sync('chromium') ||
plugins.smartshell.which.sync('chromium-browser');
const executablePathOptions = execPath ? { executablePath: execPath } : {};
console.log('Launching puppeteer browser with arguments:');
console.log(chromeArgs);
headlessBrowser = await plugins.puppeteer.launch({
if (execPath) {
console.log(`Using executable: ${execPath}`);
} else {
console.log('No specific browser executable found; falling back to Puppeteer default.');
}
const headlessBrowser = await plugins.puppeteer.launch({
args: chromeArgs,
pipe: options.usePipe !== undefined ? options.usePipe : true,
headless: true,
...(() => {
const returnObject: any = {};
const googleChrome = plugins.smartshell.which.sync('google-chrome');
if (googleChrome) {
returnObject.executablePath = googleChrome;
}
return returnObject;
})(),
...executablePathOptions,
});
return headlessBrowser;
};
};