Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0645364ca9 | |||
| 2d3f59cc65 | |||
| 0e9c81b898 | |||
| 64cd7cd75d | |||
| f110320dae | |||
| cbc7fcb323 | |||
| 0dc0e6ad53 |
762
package-lock.json
generated
762
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpuppeteer",
|
"name": "@pushrocks/smartpuppeteer",
|
||||||
"version": "1.0.3",
|
"version": "1.0.7",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "simplified access to puppeteer",
|
"description": "simplified access to puppeteer",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@@ -9,20 +9,21 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)",
|
"build": "(tsbuild --web)",
|
||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.0.13",
|
||||||
"@types/node": "^10.11.7",
|
"@types/node": "^12.12.7",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^5.20.1",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/puppeteer": "^1.12.4",
|
"@pushrocks/smartenv": "^4.0.8",
|
||||||
"puppeteer": "^1.17.0"
|
"@types/puppeteer": "^1.20.2",
|
||||||
|
"puppeteer": "^2.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/*",
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
|||||||
import * as smartpuppeteer from '../ts/index';
|
import * as smartpuppeteer from '../ts/index';
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance();
|
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({
|
||||||
|
forceNoSandbox: true
|
||||||
|
});
|
||||||
await headlessBrowser.close();
|
await headlessBrowser.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
17
ts/index.ts
17
ts/index.ts
@@ -1,14 +1,9 @@
|
|||||||
import puppeteer from 'puppeteer';
|
// module exports
|
||||||
|
|
||||||
export const getEnvAwareBrowserInstance = async (): Promise<puppeteer.Browser> => {
|
export * from './smartpuppeteer.classes.smartpuppeteer';
|
||||||
let chromeArgs: string[] = [];
|
|
||||||
if (process.env.CI) {
|
|
||||||
chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']);
|
|
||||||
}
|
|
||||||
const headlessBrowser = await puppeteer.launch({
|
|
||||||
args: chromeArgs
|
|
||||||
});
|
|
||||||
return headlessBrowser;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// direct exports
|
||||||
|
import { puppeteer } from './smartpuppeteer.plugins';
|
||||||
export { puppeteer };
|
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