Compare commits

..

34 Commits

Author SHA1 Message Date
107178e9e7 1.0.31 2021-11-07 18:33:26 +01:00
0b5c030d5d fix(core): update 2021-11-07 18:33:25 +01:00
94f145c3dc 1.0.30 2021-11-07 18:30:09 +01:00
ebd60756ea fix(core): update 2021-11-07 18:30:08 +01:00
8305dd105c 1.0.29 2021-11-07 15:58:45 +01:00
797cac672b fix(core): update 2021-11-07 15:58:45 +01:00
4b1f058a21 1.0.28 2021-11-07 15:46:31 +01:00
c38f338f8e 1.0.27 2021-08-17 17:51:50 +02:00
103c7eb11e fix(core): update 2021-08-17 17:51:50 +02:00
0190f1bb77 1.0.26 2021-08-17 15:22:10 +02:00
87d7460183 fix(core): update 2021-08-17 15:22:10 +02:00
ed1522062e 1.0.25 2021-08-17 12:20:54 +02:00
116f700d5c fix(core): update 2021-08-17 12:20:54 +02:00
366a033904 1.0.24 2021-08-17 02:53:34 +02:00
5f1f4b3c53 fix(core): update 2021-08-17 02:53:34 +02:00
255bd7046e 1.0.23 2021-08-17 02:51:24 +02:00
bb82845f27 1.0.22 2021-08-17 02:50:49 +02:00
8ec23ba414 fix(core): update 2021-08-17 02:50:49 +02:00
937605f8c1 1.0.21 2021-01-12 14:41:45 +00:00
f05c2226c5 fix(core): update 2021-01-12 14:41:44 +00:00
1d2eca0991 1.0.20 2021-01-12 14:24:22 +00:00
c91f77a0d4 fix(core): update 2021-01-12 14:24:21 +00:00
d94826a7b7 1.0.19 2021-01-08 21:53:18 +00:00
636f0580c6 fix(core): update 2021-01-08 21:53:17 +00:00
aa5552ce3a 1.0.18 2021-01-08 21:42:53 +00:00
3ef298215a fix(core): update 2021-01-08 21:42:52 +00:00
23c65e23ae 1.0.17 2021-01-08 21:16:26 +00:00
ef55253b8e fix(core): update 2021-01-08 21:16:25 +00:00
1b72af4702 1.0.16 2021-01-08 21:14:01 +00:00
44314c9894 fix(core): update 2021-01-08 21:14:01 +00:00
35129df11c 1.0.15 2020-02-25 01:38:24 +00:00
5dd6450347 fix(core): update 2020-02-25 01:38:24 +00:00
190d57bbe2 1.0.14 2019-11-16 17:51:13 +01:00
8d4519d615 fix(cli logs): now correctly stating when WSL is detected. 2019-11-16 17:51:11 +01:00
13 changed files with 25941 additions and 885 deletions

4
.gitignore vendored
View File

@@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom

View File

@@ -7,120 +7,17 @@ cache:
key: '$CI_BUILD_STAGE' key: '$CI_BUILD_STAGE'
stages: stages:
- security - only
- test
- release
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- lossless
- docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- lossless
- docker
- notpriv
# ====================
# test stage
# ====================
testStable: testStable:
stage: test stage: only
script: script:
- whereis google-chrome
- npmci npm prepare - npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

11
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@@ -1,5 +1,6 @@
{ {
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",

26525
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,10 @@
{ {
"name": "@pushrocks/smartpuppeteer", "name": "@pushrocks/smartpuppeteer",
"version": "1.0.13", "version": "1.0.31",
"private": false, "private": false,
"description": "simplified access to puppeteer", "description": "simplified access to puppeteer",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
@@ -13,28 +13,32 @@
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.28",
"@gitzone/tstest": "^1.0.28", "@gitzone/tstest": "^1.0.59",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^12.12.7", "@types/node": "^16.11.6",
"tslint": "^5.20.1", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.6", "@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartenv": "^4.0.8", "@pushrocks/smartenv": "^4.0.16",
"@types/puppeteer": "^1.20.2", "puppeteer": "^11.0.0",
"puppeteer": "^2.0.0" "tree-kill": "^1.2.2"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
"ts_web/**/*", "ts_web/**/*",
"dist/**/*", "dist/**/*",
"dist_web/**/*", "dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
],
"browserslist": [
"last 1 chrome versions"
] ]
} }

View File

@@ -8,13 +8,20 @@ simplified access to puppeteer
* [docs (typedoc)](https://pushrocks.gitlab.io/smartpuppeteer/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartpuppeteer/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/smartpuppeteer/badges/master/build.svg)](https://gitlab.com/pushrocks/smartpuppeteer/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartpuppeteer/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartpuppeteer/commits/master) Status Category | Status Badge
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartpuppeteer.svg)](https://www.npmjs.com/package/@pushrocks/smartpuppeteer) -- | --
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartpuppeteer/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartpuppeteer) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartpuppeteer/badges/master/pipeline.svg)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartpuppeteer/badges/master/coverage.svg)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartpuppeteer)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartpuppeteer)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartpuppeteer)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartpuppeteer)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartpuppeteer)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage
@@ -22,7 +29,7 @@ Use TypeScript for best in class intellisense.
```typescript ```typescript
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({ const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({
forceNoSandbox: true // if you really want no sandbox, you can do this. Otherwise its starting things as necessary forceNoSandbox: true, // if you really want no sandbox, you can do this. Otherwise its starting things as necessary
}); });
await headlessBrowser.close(); await headlessBrowser.close();
``` ```

View File

@@ -1,11 +1,19 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as smartpuppeteer from '../ts/index'; import * as smartpuppeteer from '../ts/index';
tap.test('first test', async tools => { tap.test('first test', async (tools) => {
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({ const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({
forceNoSandbox: true forceNoSandbox: true,
}); });
const page = await headlessBrowser.newPage();
await headlessBrowser.close(); await headlessBrowser.close();
}); });
tap.test('should get and stop an Incognito browser', async () => {
const incognitoInstance = new smartpuppeteer.IncognitoBrowser();
await incognitoInstance.start();
const page = await incognitoInstance.browser.newPage();
await incognitoInstance.stop();
});
tap.start(); tap.start();

View File

@@ -1,6 +1,7 @@
// module exports // module exports
export * from './smartpuppeteer.classes.smartpuppeteer'; export * from './smartpuppeteer.classes.smartpuppeteer';
export * from './smartpuppeteer.classes.incognitobrowser';
// direct exports // direct exports
import { puppeteer } from './smartpuppeteer.plugins'; import { puppeteer } from './smartpuppeteer.plugins';

View File

@@ -0,0 +1,50 @@
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.on('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';
plugins.treeKill(this.browser.process().pid, 'SIGKILL');
await this.browser.close();
}
/**
* rotate
*/
public async rotateBrowser() {
this.browser.close().catch();
this.browser = await getEnvAwareBrowserInstance();
}
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');
}
}
}

View File

@@ -10,24 +10,24 @@ export const getEnvAwareBrowserInstance = async (
const smartenv = new plugins.smartenv.Smartenv(); const smartenv = new plugins.smartenv.Smartenv();
const options: IEnvAwareOptions = { const options: IEnvAwareOptions = {
...{ ...{
forceNoSandbox: false forceNoSandbox: false,
}, },
...optionsArg ...optionsArg,
}; };
let chromeArgs: string[] = []; let chromeArgs: string[] = [];
if ((process.env.CI || options.forceNoSandbox) && !smartenv.isWsl) { if (process.env.CI || options.forceNoSandbox || plugins.os.userInfo().username === 'root') {
chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']); chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']);
} else if (smartenv.isWsl) {
console.log('Detected WSL. Using chromium.');
chromeArgs = chromeArgs.concat(['--no-sandbox', '--single-process']);
} }
let headlessBrowser: plugins.puppeteer.Browser; let headlessBrowser: plugins.puppeteer.Browser;
console.log('launching puppeteer bundled chrome with arguments:'); console.log('launching puppeteer bundled chrome with arguments:');
console.log(chromeArgs); console.log(chromeArgs);
headlessBrowser = await plugins.puppeteer.launch({ headlessBrowser = await plugins.puppeteer.launch({
args: chromeArgs args: chromeArgs,
pipe: true,
headless: true,
executablePath: '/bin/chrome'
}); });
return headlessBrowser; return headlessBrowser;

View File

@@ -1,3 +1,8 @@
// node native scope
import * as os from 'os';
export { os };
// @pushrocks scope // @pushrocks scope
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
import * as smartenv from '@pushrocks/smartenv'; import * as smartenv from '@pushrocks/smartenv';
@@ -6,5 +11,6 @@ export { smartdelay, smartenv };
// third party scope // third party scope
import puppeteer from 'puppeteer'; import puppeteer from 'puppeteer';
import treeKill from 'tree-kill';
export { puppeteer }; export { puppeteer, treeKill };