Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b2efe28f4d | |||
| 1ab34d909b | |||
| 09a8888d47 | |||
| 243beb2c75 | |||
| c6fd1bea7a | |||
| 4f94fa31ac | |||
| ac61d8ff4d | |||
| 107178e9e7 | |||
| 0b5c030d5d | |||
| 94f145c3dc | |||
| ebd60756ea | |||
| 8305dd105c | |||
| 797cac672b | |||
| 4b1f058a21 | |||
| c38f338f8e | |||
| 103c7eb11e | |||
| 0190f1bb77 | |||
| 87d7460183 | |||
| ed1522062e | |||
| 116f700d5c | |||
| 366a033904 | |||
| 5f1f4b3c53 | |||
| 255bd7046e | |||
| bb82845f27 | |||
| 8ec23ba414 | |||
| 937605f8c1 | |||
| f05c2226c5 | |||
| 1d2eca0991 | |||
| c91f77a0d4 | |||
| d94826a7b7 | |||
| 636f0580c6 | |||
| aa5552ce3a | |||
| 3ef298215a | |||
| 23c65e23ae | |||
| ef55253b8e |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
||||||
108
.gitlab-ci.yml
108
.gitlab-ci.yml
@@ -7,41 +7,10 @@ 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:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
@@ -49,78 +18,5 @@ testStable:
|
|||||||
- 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
11
.vscode/launch.json
vendored
Normal 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
26
.vscode/settings.json
vendored
Normal 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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
22471
package-lock.json
generated
22471
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
package.json
27
package.json
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpuppeteer",
|
"name": "@pushrocks/smartpuppeteer",
|
||||||
"version": "1.0.16",
|
"version": "1.0.35",
|
||||||
"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,33 @@
|
|||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.28",
|
||||||
"@gitzone/tstest": "^1.0.52",
|
"@gitzone/tstest": "^1.0.59",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/node": "^14.14.20",
|
"@types/node": "^16.11.6",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartenv": "^4.0.16",
|
"@pushrocks/smartenv": "^4.0.16",
|
||||||
"@types/puppeteer": "^5.4.2",
|
"@pushrocks/smartshell": "^2.0.29",
|
||||||
"puppeteer": "^5.5.0"
|
"puppeteer": "^11.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"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
23
readme.md
23
readme.md
@@ -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
|
||||||
[](https://gitlab.com/pushrocks/smartpuppeteer/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartpuppeteer/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartpuppeteer)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartpuppeteer)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](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();
|
||||||
```
|
```
|
||||||
|
|||||||
12
test/test.ts
12
test/test.ts
@@ -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();
|
||||||
|
|||||||
@@ -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';
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ export class IncognitoBrowser {
|
|||||||
public status: 'started' | 'stopped' = 'stopped';
|
public status: 'started' | 'stopped' = 'stopped';
|
||||||
public browser: plugins.puppeteer.Browser;
|
public browser: plugins.puppeteer.Browser;
|
||||||
|
|
||||||
constructor() {
|
constructor() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* starts the IncognitoBrowser
|
* starts the IncognitoBrowser
|
||||||
@@ -15,14 +13,14 @@ export class IncognitoBrowser {
|
|||||||
public async start() {
|
public async start() {
|
||||||
this.status = 'started';
|
this.status = 'started';
|
||||||
this.browser = await getEnvAwareBrowserInstance();
|
this.browser = await getEnvAwareBrowserInstance();
|
||||||
this.browser.addListener('disconnected', async eventArg => {
|
this.browser.on('disconnected', async (eventArg) => {
|
||||||
try {
|
try {
|
||||||
this.browser.removeAllListeners();
|
this.browser.removeAllListeners();
|
||||||
} catch(err) {}
|
} catch (err) {}
|
||||||
if (this.status === 'started') {
|
if (this.status === 'started') {
|
||||||
this.browser = await getEnvAwareBrowserInstance();
|
this.browser = await getEnvAwareBrowserInstance();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,6 +28,16 @@ export class IncognitoBrowser {
|
|||||||
*/
|
*/
|
||||||
public async stop() {
|
public async stop() {
|
||||||
this.status = 'stopped';
|
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> {
|
public async getNewIncognitoContext(): Promise<plugins.puppeteer.BrowserContext> {
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ 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 || plugins.os.userInfo().username === 'root')) {
|
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']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +24,17 @@ export const getEnvAwareBrowserInstance = async (
|
|||||||
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,
|
||||||
|
...(() => {
|
||||||
|
const returnObject: any = {};
|
||||||
|
const googleChrome = plugins.smartshell.which.sync('google-chrome')
|
||||||
|
if(googleChrome) {
|
||||||
|
returnObject.executablePath = googleChrome
|
||||||
|
}
|
||||||
|
return returnObject;
|
||||||
|
})()
|
||||||
});
|
});
|
||||||
|
|
||||||
return headlessBrowser;
|
return headlessBrowser;
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
// node native scope
|
// node native scope
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
|
|
||||||
export {
|
export { os };
|
||||||
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';
|
||||||
|
import * as smartshell from '@pushrocks/smartshell';
|
||||||
|
|
||||||
export { smartdelay, smartenv };
|
export { smartdelay, smartenv, smartshell };
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import puppeteer from 'puppeteer';
|
import puppeteer from 'puppeteer';
|
||||||
|
import treeKill from 'tree-kill';
|
||||||
|
|
||||||
export { puppeteer };
|
export { puppeteer, treeKill };
|
||||||
|
|||||||
Reference in New Issue
Block a user