fix(core): update
This commit is contained in:
42
ts/smartpuppeteer.classes.incognitobrowser.ts
Normal file
42
ts/smartpuppeteer.classes.incognitobrowser.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { getEnvAwareBrowserInstance } from './smartpuppeteer.classes.smartpuppeteer';
|
||||
import * as plugins from './smartpuppeteer.plugins';
|
||||
|
||||
export class IncognitoBrowser {
|
||||
public status: 'started' | 'stopped' = 'stopped';
|
||||
public browser: plugins.puppeteer.Browser;
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* starts the IncognitoBrowser
|
||||
*/
|
||||
public async start() {
|
||||
this.status = 'started';
|
||||
this.browser = await getEnvAwareBrowserInstance();
|
||||
this.browser.addListener('disconnected', async eventArg => {
|
||||
try {
|
||||
this.browser.removeAllListeners();
|
||||
} catch(err) {}
|
||||
if (this.status === 'started') {
|
||||
this.browser = await getEnvAwareBrowserInstance();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* stops the IncognitoBrowser
|
||||
*/
|
||||
public async stop() {
|
||||
this.status = 'stopped';
|
||||
}
|
||||
|
||||
public async getNewIncognitoContext(): Promise<plugins.puppeteer.BrowserContext> {
|
||||
if (this.browser) {
|
||||
return this.browser.createIncognitoBrowserContext();
|
||||
} else {
|
||||
throw new Error('you need to start the IncognitoBrowser instance first');
|
||||
}
|
||||
}
|
||||
}
|
@ -16,11 +16,8 @@ export const getEnvAwareBrowserInstance = async (
|
||||
};
|
||||
|
||||
let chromeArgs: string[] = [];
|
||||
if ((process.env.CI || options.forceNoSandbox || plugins.os.userInfo().username === 'root') && !smartenv.isWsl) {
|
||||
if ((process.env.CI || options.forceNoSandbox || plugins.os.userInfo().username === 'root')) {
|
||||
chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']);
|
||||
} else if (smartenv.isWsl) {
|
||||
console.log('Detected WSL.');
|
||||
chromeArgs = chromeArgs.concat(['--no-sandbox', '--single-process']);
|
||||
}
|
||||
|
||||
let headlessBrowser: plugins.puppeteer.Browser;
|
||||
|
Reference in New Issue
Block a user