Compare commits

...

30 Commits

Author SHA1 Message Date
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
42a68434c0 1.0.13 2019-11-16 01:22:10 +01:00
35fd4678d1 fix(core): update 2019-11-16 01:22:08 +01:00
01a4122529 1.0.12 2019-11-16 01:15:10 +01:00
fbb94fe51e fix(core): update 2019-11-16 01:15:08 +01:00
656e21c8fd 1.0.11 2019-11-16 00:35:05 +01:00
53b5cca687 fix(core): update 2019-11-16 00:35:03 +01:00
25d191a95b 1.0.10 2019-11-16 00:01:07 +01:00
d5b3e48f8d fix(core): update 2019-11-16 00:01:05 +01:00
dd6f24551d 1.0.9 2019-11-15 23:59:35 +01:00
f4d0e9ad87 fix(core): update 2019-11-15 23:59:34 +01:00
41aefa7f18 1.0.8 2019-11-15 23:41:41 +01:00
c9f42b4c66 fix(core): update 2019-11-15 23:41:39 +01:00
13 changed files with 26076 additions and 834 deletions

4
.gitignore vendored
View File

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

View File

@@ -1,16 +1,16 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
# ====================
# security stage
@@ -19,38 +19,41 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
snyk:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
- notpriv
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# test stage
# ====================
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
testStable:
stage: test
script:
- npmci npm prepare
@@ -60,7 +63,17 @@ testSTABLE:
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
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:
- docker
release:
stage: release
@@ -70,6 +83,7 @@ release:
only:
- tags
tags:
- lossless
- docker
- notpriv
@@ -78,20 +92,16 @@ release:
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
only:
- tags
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
- 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
@@ -102,18 +112,20 @@ trigger:
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
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:

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

@@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

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": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",

26551
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -8,19 +8,39 @@ simplified access to puppeteer
* [docs (typedoc)](https://pushrocks.gitlab.io/smartpuppeteer/)
## 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)
[![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)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartpuppeteer/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartpuppeteer/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartpuppeteer)](https://lossless.cloud)
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
Use TypeScript for best in class intellisense.
```typescript
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({
forceNoSandbox: true, // if you really want no sandbox, you can do this. Otherwise its starting things as necessary
});
await headlessBrowser.close();
```
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@@ -1,9 +1,9 @@
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
forceNoSandbox: true,
});
await headlessBrowser.close();
});

View File

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

View File

@@ -0,0 +1,49 @@
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';
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,30 +10,23 @@ export const getEnvAwareBrowserInstance = async (
const smartenv = new plugins.smartenv.Smartenv();
const options: IEnvAwareOptions = {
...{
forceNoSandbox: false
forceNoSandbox: false,
},
...optionsArg
...optionsArg,
};
let chromeArgs: string[] = [];
if ((process.env.CI || options.forceNoSandbox) && !smartenv.isWsl) {
chromeArgs = chromeArgs.concat([
'--no-sandbox',
'--disable-setuid-sandbox'
// '--disable-dev-shm-usage'
]);
if (process.env.CI || options.forceNoSandbox || plugins.os.userInfo().username === 'root') {
chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']);
}
let headlessBrowser: plugins.puppeteer.Browser;
if (!smartenv.isWsl) {
// lets get the actual instance
console.log('launching puppeteer bundled chrome with arguments:');
console.log(chromeArgs);
headlessBrowser = await plugins.puppeteer.launch({
args: chromeArgs
args: chromeArgs,
pipe: true
});
} else {
console.log('Detected WSL. Using chromium.');
headlessBrowser = await plugins.puppeteer.launch({executablePath: '/usr/bin/chromium-browser'});
}
return headlessBrowser;
};

View File

@@ -1,13 +1,15 @@
// node native scope
import * as os from 'os';
export { os };
// @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';
export {
puppeteer
}
export { puppeteer };