fix(core): update
This commit is contained in:
28
ts/index.ts
28
ts/index.ts
@ -1,25 +1,9 @@
|
||||
import puppeteer from 'puppeteer';
|
||||
// module exports
|
||||
|
||||
export interface IEnvAwareOptions {
|
||||
forceNoSandbox?: boolean;
|
||||
}
|
||||
|
||||
export const getEnvAwareBrowserInstance = async (optionsArg: IEnvAwareOptions = {}): Promise<puppeteer.Browser> => {
|
||||
const options: IEnvAwareOptions = {
|
||||
...{
|
||||
forceNoSandbox: false
|
||||
},
|
||||
...optionsArg
|
||||
}
|
||||
|
||||
let chromeArgs: string[] = [];
|
||||
if (process.env.CI || options.forceNoSandbox) {
|
||||
chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']);
|
||||
}
|
||||
const headlessBrowser = await puppeteer.launch({
|
||||
args: chromeArgs
|
||||
});
|
||||
return headlessBrowser;
|
||||
};
|
||||
export * from './smartpuppeteer.classes.smartpuppeteer';
|
||||
|
||||
// direct exports
|
||||
import { puppeteer } from './smartpuppeteer.plugins';
|
||||
export { puppeteer };
|
||||
|
||||
|
||||
|
39
ts/smartpuppeteer.classes.smartpuppeteer.ts
Normal file
39
ts/smartpuppeteer.classes.smartpuppeteer.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import * as plugins from './smartpuppeteer.plugins';
|
||||
|
||||
export interface IEnvAwareOptions {
|
||||
forceNoSandbox?: boolean;
|
||||
}
|
||||
|
||||
export const getEnvAwareBrowserInstance = async (
|
||||
optionsArg: IEnvAwareOptions = {}
|
||||
): Promise<plugins.puppeteer.Browser> => {
|
||||
const smartenv = new plugins.smartenv.Smartenv();
|
||||
const options: IEnvAwareOptions = {
|
||||
...{
|
||||
forceNoSandbox: false
|
||||
},
|
||||
...optionsArg
|
||||
};
|
||||
|
||||
let chromeArgs: string[] = [];
|
||||
if ((process.env.CI || options.forceNoSandbox) && !smartenv.isWsl) {
|
||||
chromeArgs = chromeArgs.concat([
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox'
|
||||
// '--disable-dev-shm-usage'
|
||||
]);
|
||||
}
|
||||
|
||||
let headlessBrowser: plugins.puppeteer.Browser;
|
||||
if (!smartenv.isWsl) {
|
||||
// lets get the actual instance
|
||||
headlessBrowser = await plugins.puppeteer.launch({
|
||||
args: chromeArgs
|
||||
});
|
||||
} else {
|
||||
console.log('Detected WSL. Using chromium.');
|
||||
headlessBrowser = await plugins.puppeteer.launch({executablePath: '/usr/bin/chromium-browser'});
|
||||
}
|
||||
|
||||
return headlessBrowser;
|
||||
};
|
13
ts/smartpuppeteer.plugins.ts
Normal file
13
ts/smartpuppeteer.plugins.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// @pushrocks scope
|
||||
import * as smartenv from '@pushrocks/smartenv';
|
||||
|
||||
export {
|
||||
smartenv
|
||||
};
|
||||
|
||||
// third party scope
|
||||
import puppeteer from 'puppeteer';
|
||||
|
||||
export {
|
||||
puppeteer
|
||||
}
|
Reference in New Issue
Block a user