Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 57776a67b3 | |||
| 8809b9755b | |||
| 1138897da2 | |||
| 831f967960 | |||
| fc602235cf | |||
| 775f2bde13 | |||
| 3c436b7167 | |||
| e955876a7c | |||
| b6472f38e2 | |||
| d4232decdd | |||
| 76999d8720 | |||
| 407ccf66b9 | |||
| 72e6ef04cb | |||
| d3732dcecc | |||
| a10b42270c | |||
| 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 | |||
| 1b72af4702 | |||
| 44314c9894 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -15,8 +15,6 @@ node_modules/
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
dist_*/
|
||||
|
||||
# custom
|
||||
@@ -12,6 +12,9 @@ stages:
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
@@ -19,22 +22,36 @@ 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
|
||||
allow_failure: true
|
||||
|
||||
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 +66,7 @@ testStable:
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
@@ -62,9 +77,7 @@ testBuild:
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
@@ -84,6 +97,8 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
@@ -109,7 +124,7 @@ pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci command npm install -g @git.zone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
|
||||
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartpuppeteer",
|
||||
"shortDescription": "simplified access to puppeteer",
|
||||
"npmPackagename": "@pushrocks/smartpuppeteer",
|
||||
"npmPackagename": "@push.rocks/smartpuppeteer",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
}
|
||||
@@ -13,5 +14,8 @@
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdocs": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
||||
11251
package-lock.json
generated
11251
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
39
package.json
39
package.json
@@ -1,40 +1,43 @@
|
||||
{
|
||||
"name": "@pushrocks/smartpuppeteer",
|
||||
"version": "1.0.15",
|
||||
"name": "@push.rocks/smartpuppeteer",
|
||||
"version": "2.0.3",
|
||||
"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",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web)",
|
||||
"format": "(gitzone format)"
|
||||
"test": "tstest test/",
|
||||
"build": "tsbuild --web --allowimplicitany"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/tapbundle": "^3.2.0",
|
||||
"@types/node": "^13.7.4",
|
||||
"tslint": "^6.0.0",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
"@git.zone/tsbuild": "^2.1.63",
|
||||
"@git.zone/tsrun": "^1.2.46",
|
||||
"@git.zone/tstest": "^1.0.71",
|
||||
"@push.rocks/tapbundle": "^5.0.8",
|
||||
"@types/node": "^20.12.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.6",
|
||||
"@pushrocks/smartenv": "^4.0.8",
|
||||
"@types/puppeteer": "^2.0.0",
|
||||
"puppeteer": "^2.1.1"
|
||||
"@push.rocks/smartdelay": "^3.0.1",
|
||||
"@push.rocks/smartshell": "^3.0.3",
|
||||
"puppeteer": "^22.6.4",
|
||||
"tree-kill": "^1.2.2"
|
||||
},
|
||||
"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"
|
||||
]
|
||||
}
|
||||
|
||||
5135
pnpm-lock.yaml
generated
Normal file
5135
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
27
readme.md
27
readme.md
@@ -1,20 +1,27 @@
|
||||
# @pushrocks/smartpuppeteer
|
||||
# @push.rocks/smartpuppeteer
|
||||
simplified access to puppeteer
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartpuppeteer)
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartpuppeteer)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartpuppeteer)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartpuppeteer)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartpuppeteer/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartpuppeteer/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartpuppeteer/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartpuppeteer)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartpuppeteer)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
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
|
||||
|
||||
@@ -22,7 +29,7 @@ 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
|
||||
forceNoSandbox: true, // if you really want no sandbox, you can do this. Otherwise its starting things as necessary
|
||||
});
|
||||
await headlessBrowser.close();
|
||||
```
|
||||
|
||||
31
test/test.ts
31
test/test.ts
@@ -1,11 +1,34 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartpuppeteer from '../ts/index';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartpuppeteer from '../ts/index.js';
|
||||
|
||||
tap.test('first test', async tools => {
|
||||
tap.test('should use pipe', async (tools) => {
|
||||
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({
|
||||
forceNoSandbox: true
|
||||
forceNoSandbox: false,
|
||||
});
|
||||
const page = await headlessBrowser.newPage();
|
||||
await page.goto('https://lossless.com');
|
||||
console.log(await page.title());
|
||||
expect(headlessBrowser.wsEndpoint()).toEqual('');
|
||||
await headlessBrowser.close();
|
||||
});
|
||||
|
||||
tap.test('should use websocket', async (tools) => {
|
||||
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({
|
||||
forceNoSandbox: false,
|
||||
usePipe: false,
|
||||
});
|
||||
const page = await headlessBrowser.newPage();
|
||||
await page.goto('https://lossless.com');
|
||||
console.log(await page.title());
|
||||
expect(headlessBrowser.wsEndpoint()).not.toEqual('');
|
||||
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();
|
||||
|
||||
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartpuppeteer',
|
||||
version: '2.0.3',
|
||||
description: 'simplified access to puppeteer'
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
// module exports
|
||||
|
||||
export * from './smartpuppeteer.classes.smartpuppeteer';
|
||||
export * from './smartpuppeteer.classes.smartpuppeteer.js';
|
||||
export * from './smartpuppeteer.classes.incognitobrowser.js';
|
||||
|
||||
// direct exports
|
||||
import { puppeteer } from './smartpuppeteer.plugins';
|
||||
import { puppeteer } from './smartpuppeteer.plugins.js';
|
||||
export { puppeteer };
|
||||
|
||||
50
ts/smartpuppeteer.classes.incognitobrowser.ts
Normal file
50
ts/smartpuppeteer.classes.incognitobrowser.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { getEnvAwareBrowserInstance } from './smartpuppeteer.classes.smartpuppeteer.js';
|
||||
import * as plugins from './smartpuppeteer.plugins.js';
|
||||
|
||||
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 as number, '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');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,40 @@
|
||||
import * as plugins from './smartpuppeteer.plugins';
|
||||
import * as plugins from './smartpuppeteer.plugins.js';
|
||||
|
||||
export interface IEnvAwareOptions {
|
||||
forceNoSandbox?: boolean;
|
||||
usePipe?: boolean;
|
||||
}
|
||||
|
||||
export const getEnvAwareBrowserInstance = async (
|
||||
optionsArg: IEnvAwareOptions = {}
|
||||
): Promise<plugins.puppeteer.Browser> => {
|
||||
const smartenv = new plugins.smartenv.Smartenv();
|
||||
const options: IEnvAwareOptions = {
|
||||
...{
|
||||
forceNoSandbox: false
|
||||
forceNoSandbox: false,
|
||||
},
|
||||
...optionsArg
|
||||
...optionsArg,
|
||||
};
|
||||
|
||||
let chromeArgs: string[] = [];
|
||||
if ((process.env.CI || options.forceNoSandbox || plugins.os.userInfo().username === 'root') && !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.');
|
||||
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: options.usePipe !== undefined ? options.usePipe : true,
|
||||
headless: true,
|
||||
...(() => {
|
||||
const returnObject: any = {};
|
||||
const googleChrome = plugins.smartshell.which.sync('google-chrome');
|
||||
if (googleChrome) {
|
||||
returnObject.executablePath = googleChrome;
|
||||
}
|
||||
return returnObject;
|
||||
})(),
|
||||
});
|
||||
|
||||
return headlessBrowser;
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
// node native scope
|
||||
import * as os from 'os';
|
||||
|
||||
export {
|
||||
os
|
||||
};
|
||||
export { os };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartenv from '@pushrocks/smartenv';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
|
||||
export { smartdelay, smartenv };
|
||||
export { smartdelay, smartshell };
|
||||
|
||||
// third party scope
|
||||
import puppeteer from 'puppeteer';
|
||||
import treeKill from 'tree-kill';
|
||||
|
||||
export { puppeteer };
|
||||
export { puppeteer, treeKill };
|
||||
|
||||
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
17
tslint.json
17
tslint.json
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
||||
Reference in New Issue
Block a user