Compare commits

...

25 Commits

Author SHA1 Message Date
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
42a68434c0 1.0.13 2019-11-16 01:22:10 +01:00
35fd4678d1 fix(core): update 2019-11-16 01:22:08 +01:00
13 changed files with 24896 additions and 784 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

@@ -19,22 +19,35 @@ 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:
- lossless
- 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
@@ -49,9 +62,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@@ -62,9 +73,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@@ -84,6 +93,8 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare

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",

25461
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.12",
"version": "1.0.25",
"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,28 +13,31 @@
"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.26",
"@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/smartdelay": "^2.0.6",
"@pushrocks/smartenv": "^4.0.8",
"@types/puppeteer": "^1.20.2",
"puppeteer": "^2.0.0"
"@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartenv": "^4.0.16",
"puppeteer": "^10.2.0"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_web/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

View File

@@ -8,18 +8,32 @@ 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). :)

View File

@@ -1,9 +1,9 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartpuppeteer from '../ts/index';
tap.test('first test', async tools => {
tap.test('first test', async (tools) => {
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({
forceNoSandbox: true
forceNoSandbox: true,
});
await headlessBrowser.close();
});

View File

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

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.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';
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,22 @@ 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) {
if (process.env.CI || options.forceNoSandbox || plugins.os.userInfo().username === 'root') {
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;
console.log('launching puppeteer bundled chrome with arguments:');
console.log(chromeArgs);
headlessBrowser = await plugins.puppeteer.launch({
args: chromeArgs
args: chromeArgs,
pipe: true
});
return headlessBrowser;

View File

@@ -1,3 +1,8 @@
// node native scope
import * as os from 'os';
export { os };
// @pushrocks scope
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartenv from '@pushrocks/smartenv';