Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@@ -36,6 +39,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|||||||
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
17359
package-lock.json
generated
17359
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@@ -1,30 +1,28 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpuppeteer",
|
"name": "@pushrocks/smartpuppeteer",
|
||||||
"version": "1.0.18",
|
"version": "2.0.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "simplified access to puppeteer",
|
"description": "simplified access to puppeteer",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "tstest test/",
|
||||||
"build": "(tsbuild --web)",
|
"build": "tsbuild --web --allowimplicitany"
|
||||||
"format": "(gitzone format)"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.63",
|
||||||
"@gitzone/tstest": "^1.0.52",
|
"@gitzone/tstest": "^1.0.71",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"@types/node": "^14.14.20",
|
"@types/node": "^18.0.6"
|
||||||
"tslint": "^6.1.3",
|
|
||||||
"tslint-config-prettier": "^1.15.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartenv": "^4.0.16",
|
"@pushrocks/smartshell": "^2.0.30",
|
||||||
"@types/puppeteer": "^5.4.2",
|
"puppeteer": "^15.4.0",
|
||||||
"puppeteer": "^5.5.0"
|
"tree-kill": "^1.2.2"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
|||||||
10
test/test.ts
10
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.js';
|
||||||
|
|
||||||
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();
|
||||||
|
|||||||
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: '@pushrocks/smartpuppeteer',
|
||||||
|
version: '2.0.1',
|
||||||
|
description: 'simplified access to puppeteer'
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
// module exports
|
// module exports
|
||||||
|
|
||||||
export * from './smartpuppeteer.classes.smartpuppeteer';
|
export * from './smartpuppeteer.classes.smartpuppeteer.js';
|
||||||
export * from './smartpuppeteer.classes.incognitobrowser';
|
export * from './smartpuppeteer.classes.incognitobrowser.js';
|
||||||
|
|
||||||
// direct exports
|
// direct exports
|
||||||
import { puppeteer } from './smartpuppeteer.plugins';
|
import { puppeteer } from './smartpuppeteer.plugins.js';
|
||||||
export { puppeteer };
|
export { puppeteer };
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { getEnvAwareBrowserInstance } from './smartpuppeteer.classes.smartpuppeteer';
|
import { getEnvAwareBrowserInstance } from './smartpuppeteer.classes.smartpuppeteer.js';
|
||||||
import * as plugins from './smartpuppeteer.plugins';
|
import * as plugins from './smartpuppeteer.plugins.js';
|
||||||
|
|
||||||
export class IncognitoBrowser {
|
export class IncognitoBrowser {
|
||||||
public status: 'started' | 'stopped' = 'stopped';
|
public status: 'started' | 'stopped' = 'stopped';
|
||||||
@@ -13,7 +13,7 @@ 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) {}
|
||||||
@@ -28,6 +28,16 @@ export class IncognitoBrowser {
|
|||||||
*/
|
*/
|
||||||
public async stop() {
|
public async stop() {
|
||||||
this.status = 'stopped';
|
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> {
|
public async getNewIncognitoContext(): Promise<plugins.puppeteer.BrowserContext> {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smartpuppeteer.plugins';
|
import * as plugins from './smartpuppeteer.plugins.js';
|
||||||
|
|
||||||
export interface IEnvAwareOptions {
|
export interface IEnvAwareOptions {
|
||||||
forceNoSandbox?: boolean;
|
forceNoSandbox?: boolean;
|
||||||
@@ -7,7 +7,6 @@ export interface IEnvAwareOptions {
|
|||||||
export const getEnvAwareBrowserInstance = async (
|
export const getEnvAwareBrowserInstance = async (
|
||||||
optionsArg: IEnvAwareOptions = {}
|
optionsArg: IEnvAwareOptions = {}
|
||||||
): Promise<plugins.puppeteer.Browser> => {
|
): Promise<plugins.puppeteer.Browser> => {
|
||||||
const smartenv = new plugins.smartenv.Smartenv();
|
|
||||||
const options: IEnvAwareOptions = {
|
const options: IEnvAwareOptions = {
|
||||||
...{
|
...{
|
||||||
forceNoSandbox: false,
|
forceNoSandbox: false,
|
||||||
@@ -25,6 +24,16 @@ export const getEnvAwareBrowserInstance = async (
|
|||||||
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;
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ 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 smartshell from '@pushrocks/smartshell';
|
||||||
|
|
||||||
export { smartdelay, smartenv };
|
export { smartdelay, 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 };
|
||||||
|
|||||||
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