From 53b5cca687b680cad2aab23d873a7104150d697d Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sat, 16 Nov 2019 00:35:03 +0100 Subject: [PATCH] fix(core): update --- package-lock.json | 1 - package.json | 1 + test/test.ts | 2 +- ts/smartpuppeteer.classes.smartpuppeteer.ts | 31 ++++++--------------- ts/smartpuppeteer.plugins.ts | 3 +- 5 files changed, 13 insertions(+), 25 deletions(-) diff --git a/package-lock.json b/package-lock.json index 294fc1e..8950afd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -140,7 +140,6 @@ "version": "2.0.6", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartdelay/-/smartdelay-2.0.6.tgz", "integrity": "sha512-4wUnzWNhRPODpaaL5GuRaje/C5dg+TMhBxmr57PKc2fqYpy6azWJwonf/s5xpcbJLCPJRbj1x8M5MqgCFq2uvg==", - "dev": true, "requires": { "@pushrocks/smartpromise": "^3.0.6" } diff --git a/package.json b/package.json index 2b3a125..36a0571 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "tslint-config-prettier": "^1.15.0" }, "dependencies": { + "@pushrocks/smartdelay": "^2.0.6", "@pushrocks/smartenv": "^4.0.8", "@types/puppeteer": "^1.20.2", "puppeteer": "^2.0.0" diff --git a/test/test.ts b/test/test.ts index 566f5a4..e76b492 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,7 +1,7 @@ import { expect, tap } from '@pushrocks/tapbundle'; import * as smartpuppeteer from '../ts/index'; -tap.test('first test', async () => { +tap.test('first test', async (tools) => { const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({ forceNoSandbox: true }); diff --git a/ts/smartpuppeteer.classes.smartpuppeteer.ts b/ts/smartpuppeteer.classes.smartpuppeteer.ts index 47c2f8c..9acd4bc 100644 --- a/ts/smartpuppeteer.classes.smartpuppeteer.ts +++ b/ts/smartpuppeteer.classes.smartpuppeteer.ts @@ -17,34 +17,21 @@ export const getEnvAwareBrowserInstance = async ( let chromeArgs: string[] = []; if ((process.env.CI || options.forceNoSandbox) && !smartenv.isWsl) { + chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']); + } else if (smartenv.isWsl) { + console.log('Detected WSL. Using chromium.'); chromeArgs = chromeArgs.concat([ '--no-sandbox', - '--disable-setuid-sandbox', - // '--disable-dev-shm-usage' + '--single-process' ]); } let headlessBrowser: plugins.puppeteer.Browser; - if (!smartenv.isWsl) { - // lets get the actual instance - console.log('launching puppeteer bundled chrome'); - headlessBrowser = await plugins.puppeteer.launch({ - args: chromeArgs - }); - } else { - console.log('Detected WSL. Using chromium.'); - headlessBrowser = await plugins.puppeteer.launch({ - args: [ - '--disable-gpu', - '--disable-dev-shm-usage', - '--disable-setuid-sandbox', - '--no-first-run', - '--no-sandbox', - '--no-zygote', - '--single-process' - ] - }); - } + console.log('launching puppeteer bundled chrome with arguments:'); + console.log(chromeArgs); + headlessBrowser = await plugins.puppeteer.launch({ + args: chromeArgs + }); return headlessBrowser; }; diff --git a/ts/smartpuppeteer.plugins.ts b/ts/smartpuppeteer.plugins.ts index 3225936..b06deb1 100644 --- a/ts/smartpuppeteer.plugins.ts +++ b/ts/smartpuppeteer.plugins.ts @@ -1,7 +1,8 @@ // @pushrocks scope +import * as smartdelay from '@pushrocks/smartdelay'; import * as smartenv from '@pushrocks/smartenv'; -export { smartenv }; +export { smartdelay, smartenv }; // third party scope import puppeteer from 'puppeteer';