@push.rocks/smartpuppeteer 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * autocreated commitinfo by @pushrocks/commitinfo
3
+ */
4
+ export declare const commitinfo: {
5
+ name: string;
6
+ version: string;
7
+ description: string;
8
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * autocreated commitinfo by @pushrocks/commitinfo
3
+ */
4
+ export const commitinfo = {
5
+ name: '@pushrocks/smartpuppeteer',
6
+ version: '2.0.2',
7
+ description: 'simplified access to puppeteer'
8
+ };
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSwyQkFBMkI7SUFDakMsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLGdDQUFnQztDQUM5QyxDQUFBIn0=
@@ -0,0 +1,4 @@
1
+ export * from './smartpuppeteer.classes.smartpuppeteer.js';
2
+ export * from './smartpuppeteer.classes.incognitobrowser.js';
3
+ import { puppeteer } from './smartpuppeteer.plugins.js';
4
+ export { puppeteer };
@@ -0,0 +1,7 @@
1
+ // module exports
2
+ export * from './smartpuppeteer.classes.smartpuppeteer.js';
3
+ export * from './smartpuppeteer.classes.incognitobrowser.js';
4
+ // direct exports
5
+ import { puppeteer } from './smartpuppeteer.plugins.js';
6
+ export { puppeteer };
7
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxpQkFBaUI7QUFFakIsY0FBYyw0Q0FBNEMsQ0FBQztBQUMzRCxjQUFjLDhDQUE4QyxDQUFDO0FBRTdELGlCQUFpQjtBQUNqQixPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDeEQsT0FBTyxFQUFFLFNBQVMsRUFBRSxDQUFDIn0=
@@ -0,0 +1,19 @@
1
+ import * as plugins from './smartpuppeteer.plugins.js';
2
+ export declare class IncognitoBrowser {
3
+ status: 'started' | 'stopped';
4
+ browser: plugins.puppeteer.Browser;
5
+ constructor();
6
+ /**
7
+ * starts the IncognitoBrowser
8
+ */
9
+ start(): Promise<void>;
10
+ /**
11
+ * stops the IncognitoBrowser
12
+ */
13
+ stop(): Promise<void>;
14
+ /**
15
+ * rotate
16
+ */
17
+ rotateBrowser(): Promise<void>;
18
+ getNewIncognitoContext(): Promise<plugins.puppeteer.BrowserContext>;
19
+ }
@@ -0,0 +1,47 @@
1
+ import { getEnvAwareBrowserInstance } from './smartpuppeteer.classes.smartpuppeteer.js';
2
+ import * as plugins from './smartpuppeteer.plugins.js';
3
+ export class IncognitoBrowser {
4
+ constructor() {
5
+ this.status = 'stopped';
6
+ }
7
+ /**
8
+ * starts the IncognitoBrowser
9
+ */
10
+ async start() {
11
+ this.status = 'started';
12
+ this.browser = await getEnvAwareBrowserInstance();
13
+ this.browser.on('disconnected', async (eventArg) => {
14
+ try {
15
+ this.browser.removeAllListeners();
16
+ }
17
+ catch (err) { }
18
+ if (this.status === 'started') {
19
+ this.browser = await getEnvAwareBrowserInstance();
20
+ }
21
+ });
22
+ }
23
+ /**
24
+ * stops the IncognitoBrowser
25
+ */
26
+ async stop() {
27
+ this.status = 'stopped';
28
+ plugins.treeKill(this.browser.process()?.pid, 'SIGKILL');
29
+ await this.browser.close();
30
+ }
31
+ /**
32
+ * rotate
33
+ */
34
+ async rotateBrowser() {
35
+ this.browser.close().catch();
36
+ this.browser = await getEnvAwareBrowserInstance();
37
+ }
38
+ async getNewIncognitoContext() {
39
+ if (this.browser) {
40
+ return this.browser.createIncognitoBrowserContext();
41
+ }
42
+ else {
43
+ throw new Error('you need to start the IncognitoBrowser instance first');
44
+ }
45
+ }
46
+ }
47
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwdXBwZXRlZXIuY2xhc3Nlcy5pbmNvZ25pdG9icm93c2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRwdXBwZXRlZXIuY2xhc3Nlcy5pbmNvZ25pdG9icm93c2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSwwQkFBMEIsRUFBRSxNQUFNLDRDQUE0QyxDQUFDO0FBQ3hGLE9BQU8sS0FBSyxPQUFPLE1BQU0sNkJBQTZCLENBQUM7QUFFdkQsTUFBTSxPQUFPLGdCQUFnQjtJQUkzQjtRQUhPLFdBQU0sR0FBMEIsU0FBUyxDQUFDO0lBR2xDLENBQUM7SUFFaEI7O09BRUc7SUFDSSxLQUFLLENBQUMsS0FBSztRQUNoQixJQUFJLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQztRQUN4QixJQUFJLENBQUMsT0FBTyxHQUFHLE1BQU0sMEJBQTBCLEVBQUUsQ0FBQztRQUNsRCxJQUFJLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxjQUFjLEVBQUUsS0FBSyxFQUFFLFFBQVEsRUFBRSxFQUFFO1lBQ2pELElBQUk7Z0JBQ0YsSUFBSSxDQUFDLE9BQU8sQ0FBQyxrQkFBa0IsRUFBRSxDQUFDO2FBQ25DO1lBQUMsT0FBTyxHQUFHLEVBQUUsR0FBRTtZQUNoQixJQUFJLElBQUksQ0FBQyxNQUFNLEtBQUssU0FBUyxFQUFFO2dCQUM3QixJQUFJLENBQUMsT0FBTyxHQUFHLE1BQU0sMEJBQTBCLEVBQUUsQ0FBQzthQUNuRDtRQUNILENBQUMsQ0FBQyxDQUFDO0lBQ0wsQ0FBQztJQUVEOztPQUVHO0lBQ0ksS0FBSyxDQUFDLElBQUk7UUFDZixJQUFJLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQztRQUN4QixPQUFPLENBQUMsUUFBUSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxFQUFFLEVBQUUsR0FBYSxFQUFFLFNBQVMsQ0FBQyxDQUFDO1FBQ25FLE1BQU0sSUFBSSxDQUFDLE9BQU8sQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixDQUFDO0lBRUQ7O09BRUc7SUFDSSxLQUFLLENBQUMsYUFBYTtRQUN4QixJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssRUFBRSxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQzdCLElBQUksQ0FBQyxPQUFPLEdBQUcsTUFBTSwwQkFBMEIsRUFBRSxDQUFDO0lBQ3BELENBQUM7SUFFTSxLQUFLLENBQUMsc0JBQXNCO1FBQ2pDLElBQUksSUFBSSxDQUFDLE9BQU8sRUFBRTtZQUNoQixPQUFPLElBQUksQ0FBQyxPQUFPLENBQUMsNkJBQTZCLEVBQUUsQ0FBQztTQUNyRDthQUFNO1lBQ0wsTUFBTSxJQUFJLEtBQUssQ0FBQyx1REFBdUQsQ0FBQyxDQUFDO1NBQzFFO0lBQ0gsQ0FBQztDQUNGIn0=
@@ -0,0 +1,6 @@
1
+ import * as plugins from './smartpuppeteer.plugins.js';
2
+ export interface IEnvAwareOptions {
3
+ forceNoSandbox?: boolean;
4
+ usePipe?: boolean;
5
+ }
6
+ export declare const getEnvAwareBrowserInstance: (optionsArg?: IEnvAwareOptions) => Promise<plugins.puppeteer.Browser>;
@@ -0,0 +1,31 @@
1
+ import * as plugins from './smartpuppeteer.plugins.js';
2
+ export const getEnvAwareBrowserInstance = async (optionsArg = {}) => {
3
+ const options = {
4
+ ...{
5
+ forceNoSandbox: false,
6
+ },
7
+ ...optionsArg,
8
+ };
9
+ let chromeArgs = [];
10
+ if (process.env.CI || options.forceNoSandbox || plugins.os.userInfo().username === 'root') {
11
+ chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']);
12
+ }
13
+ let headlessBrowser;
14
+ console.log('launching puppeteer bundled chrome with arguments:');
15
+ console.log(chromeArgs);
16
+ headlessBrowser = await plugins.puppeteer.launch({
17
+ args: chromeArgs,
18
+ pipe: options.usePipe !== undefined ? options.usePipe : true,
19
+ headless: true,
20
+ ...(() => {
21
+ const returnObject = {};
22
+ const googleChrome = plugins.smartshell.which.sync('google-chrome');
23
+ if (googleChrome) {
24
+ returnObject.executablePath = googleChrome;
25
+ }
26
+ return returnObject;
27
+ })(),
28
+ });
29
+ return headlessBrowser;
30
+ };
31
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwdXBwZXRlZXIuY2xhc3Nlcy5zbWFydHB1cHBldGVlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0cHVwcGV0ZWVyLmNsYXNzZXMuc21hcnRwdXBwZXRlZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSw2QkFBNkIsQ0FBQztBQU92RCxNQUFNLENBQUMsTUFBTSwwQkFBMEIsR0FBRyxLQUFLLEVBQzdDLGFBQStCLEVBQUUsRUFDRyxFQUFFO0lBQ3RDLE1BQU0sT0FBTyxHQUFxQjtRQUNoQyxHQUFHO1lBQ0QsY0FBYyxFQUFFLEtBQUs7U0FDdEI7UUFDRCxHQUFHLFVBQVU7S0FDZCxDQUFDO0lBRUYsSUFBSSxVQUFVLEdBQWEsRUFBRSxDQUFDO0lBQzlCLElBQUksT0FBTyxDQUFDLEdBQUcsQ0FBQyxFQUFFLElBQUksT0FBTyxDQUFDLGNBQWMsSUFBSSxPQUFPLENBQUMsRUFBRSxDQUFDLFFBQVEsRUFBRSxDQUFDLFFBQVEsS0FBSyxNQUFNLEVBQUU7UUFDekYsVUFBVSxHQUFHLFVBQVUsQ0FBQyxNQUFNLENBQUMsQ0FBQyxjQUFjLEVBQUUsMEJBQTBCLENBQUMsQ0FBQyxDQUFDO0tBQzlFO0lBRUQsSUFBSSxlQUEwQyxDQUFDO0lBQy9DLE9BQU8sQ0FBQyxHQUFHLENBQUMsb0RBQW9ELENBQUMsQ0FBQztJQUNsRSxPQUFPLENBQUMsR0FBRyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0lBQ3hCLGVBQWUsR0FBRyxNQUFNLE9BQU8sQ0FBQyxTQUFTLENBQUMsTUFBTSxDQUFDO1FBQy9DLElBQUksRUFBRSxVQUFVO1FBQ2hCLElBQUksRUFBRSxPQUFPLENBQUMsT0FBTyxLQUFLLFNBQVMsQ0FBQyxDQUFDLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUMsSUFBSTtRQUM1RCxRQUFRLEVBQUUsSUFBSTtRQUNkLEdBQUcsQ0FBQyxHQUFHLEVBQUU7WUFDUCxNQUFNLFlBQVksR0FBUSxFQUFFLENBQUM7WUFDN0IsTUFBTSxZQUFZLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLGVBQWUsQ0FBQyxDQUFDO1lBQ3BFLElBQUksWUFBWSxFQUFFO2dCQUNoQixZQUFZLENBQUMsY0FBYyxHQUFHLFlBQVksQ0FBQzthQUM1QztZQUNELE9BQU8sWUFBWSxDQUFDO1FBQ3RCLENBQUMsQ0FBQyxFQUFFO0tBQ0wsQ0FBQyxDQUFDO0lBRUgsT0FBTyxlQUFlLENBQUM7QUFDekIsQ0FBQyxDQUFDIn0=
@@ -0,0 +1,8 @@
1
+ import * as os from 'os';
2
+ export { os };
3
+ import * as smartdelay from '@pushrocks/smartdelay';
4
+ import * as smartshell from '@pushrocks/smartshell';
5
+ export { smartdelay, smartshell };
6
+ import puppeteer from 'puppeteer';
7
+ import treeKill from 'tree-kill';
8
+ export { puppeteer, treeKill };
@@ -0,0 +1,12 @@
1
+ // node native scope
2
+ import * as os from 'os';
3
+ export { os };
4
+ // @pushrocks scope
5
+ import * as smartdelay from '@pushrocks/smartdelay';
6
+ import * as smartshell from '@pushrocks/smartshell';
7
+ export { smartdelay, smartshell };
8
+ // third party scope
9
+ import puppeteer from 'puppeteer';
10
+ import treeKill from 'tree-kill';
11
+ export { puppeteer, treeKill };
12
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRwdXBwZXRlZXIucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0cHVwcGV0ZWVyLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsb0JBQW9CO0FBQ3BCLE9BQU8sS0FBSyxFQUFFLE1BQU0sSUFBSSxDQUFDO0FBRXpCLE9BQU8sRUFBRSxFQUFFLEVBQUUsQ0FBQztBQUVkLG1CQUFtQjtBQUNuQixPQUFPLEtBQUssVUFBVSxNQUFNLHVCQUF1QixDQUFDO0FBQ3BELE9BQU8sS0FBSyxVQUFVLE1BQU0sdUJBQXVCLENBQUM7QUFFcEQsT0FBTyxFQUFFLFVBQVUsRUFBRSxVQUFVLEVBQUUsQ0FBQztBQUVsQyxvQkFBb0I7QUFDcEIsT0FBTyxTQUFTLE1BQU0sV0FBVyxDQUFDO0FBQ2xDLE9BQU8sUUFBUSxNQUFNLFdBQVcsQ0FBQztBQUVqQyxPQUFPLEVBQUUsU0FBUyxFQUFFLFFBQVEsRUFBRSxDQUFDIn0=
package/license ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2019 Lossless GmbH (hello@lossless.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/npmextra.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "gitzone": {
3
+ "projectType": "npm",
4
+ "module": {
5
+ "githost": "gitlab.com",
6
+ "gitscope": "pushrocks",
7
+ "gitrepo": "smartpuppeteer",
8
+ "shortDescription": "simplified access to puppeteer",
9
+ "npmPackagename": "@pushrocks/smartpuppeteer",
10
+ "license": "MIT",
11
+ "projectDomain": "push.rocks"
12
+ }
13
+ },
14
+ "npmci": {
15
+ "npmGlobalTools": [],
16
+ "npmAccessLevel": "public"
17
+ }
18
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@push.rocks/smartpuppeteer",
3
+ "version": "2.0.2",
4
+ "private": false,
5
+ "description": "simplified access to puppeteer",
6
+ "main": "dist_ts/index.js",
7
+ "typings": "dist_ts/index.d.ts",
8
+ "type": "module",
9
+ "author": "Lossless GmbH",
10
+ "license": "MIT",
11
+ "scripts": {
12
+ "test": "tstest test/",
13
+ "build": "tsbuild --web --allowimplicitany"
14
+ },
15
+ "devDependencies": {
16
+ "@gitzone/tsbuild": "^2.1.63",
17
+ "@gitzone/tstest": "^1.0.71",
18
+ "@pushrocks/tapbundle": "^5.0.3",
19
+ "@types/node": "^18.0.6"
20
+ },
21
+ "dependencies": {
22
+ "@pushrocks/smartdelay": "^2.0.13",
23
+ "@pushrocks/smartshell": "^2.0.30",
24
+ "puppeteer": "^15.4.0",
25
+ "tree-kill": "^1.2.2"
26
+ },
27
+ "files": [
28
+ "ts/**/*",
29
+ "ts_web/**/*",
30
+ "dist/**/*",
31
+ "dist_*/**/*",
32
+ "dist_ts/**/*",
33
+ "dist_ts_web/**/*",
34
+ "assets/**/*",
35
+ "cli.js",
36
+ "npmextra.json",
37
+ "readme.md"
38
+ ],
39
+ "browserslist": [
40
+ "last 1 chrome versions"
41
+ ]
42
+ }
package/readme.md ADDED
@@ -0,0 +1,46 @@
1
+ # @pushrocks/smartpuppeteer
2
+ simplified access to puppeteer
3
+
4
+ ## Availabililty and Links
5
+ * [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartpuppeteer)
6
+ * [gitlab.com (source)](https://gitlab.com/pushrocks/smartpuppeteer)
7
+ * [github.com (source mirror)](https://github.com/pushrocks/smartpuppeteer)
8
+ * [docs (typedoc)](https://pushrocks.gitlab.io/smartpuppeteer/)
9
+
10
+ ## Status for master
11
+
12
+ Status Category | Status Badge
13
+ -- | --
14
+ GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartpuppeteer/badges/master/pipeline.svg)](https://lossless.cloud)
15
+ GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartpuppeteer/badges/master/coverage.svg)](https://lossless.cloud)
16
+ npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartpuppeteer)](https://lossless.cloud)
17
+ Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartpuppeteer)](https://lossless.cloud)
18
+ TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
19
+ node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
20
+ Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
21
+ PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartpuppeteer)](https://lossless.cloud)
22
+ PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartpuppeteer)](https://lossless.cloud)
23
+ BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartpuppeteer)](https://lossless.cloud)
24
+ 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)
25
+
26
+ ## Usage
27
+
28
+ Use TypeScript for best in class intellisense.
29
+
30
+ ```typescript
31
+ const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({
32
+ forceNoSandbox: true, // if you really want no sandbox, you can do this. Otherwise its starting things as necessary
33
+ });
34
+ await headlessBrowser.close();
35
+ ```
36
+
37
+ ## Contribution
38
+
39
+ 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). :)
40
+
41
+ For further information read the linked docs at the top of this readme.
42
+
43
+ > MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
44
+ | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
45
+
46
+ [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
@@ -0,0 +1,8 @@
1
+ /**
2
+ * autocreated commitinfo by @pushrocks/commitinfo
3
+ */
4
+ export const commitinfo = {
5
+ name: '@pushrocks/smartpuppeteer',
6
+ version: '2.0.2',
7
+ description: 'simplified access to puppeteer'
8
+ }
package/ts/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ // module exports
2
+
3
+ export * from './smartpuppeteer.classes.smartpuppeteer.js';
4
+ export * from './smartpuppeteer.classes.incognitobrowser.js';
5
+
6
+ // direct exports
7
+ import { puppeteer } from './smartpuppeteer.plugins.js';
8
+ export { puppeteer };
@@ -0,0 +1,50 @@
1
+ import { getEnvAwareBrowserInstance } from './smartpuppeteer.classes.smartpuppeteer.js';
2
+ import * as plugins from './smartpuppeteer.plugins.js';
3
+
4
+ export class IncognitoBrowser {
5
+ public status: 'started' | 'stopped' = 'stopped';
6
+ public browser: plugins.puppeteer.Browser;
7
+
8
+ constructor() {}
9
+
10
+ /**
11
+ * starts the IncognitoBrowser
12
+ */
13
+ public async start() {
14
+ this.status = 'started';
15
+ this.browser = await getEnvAwareBrowserInstance();
16
+ this.browser.on('disconnected', async (eventArg) => {
17
+ try {
18
+ this.browser.removeAllListeners();
19
+ } catch (err) {}
20
+ if (this.status === 'started') {
21
+ this.browser = await getEnvAwareBrowserInstance();
22
+ }
23
+ });
24
+ }
25
+
26
+ /**
27
+ * stops the IncognitoBrowser
28
+ */
29
+ public async stop() {
30
+ this.status = 'stopped';
31
+ plugins.treeKill(this.browser.process()?.pid as number, 'SIGKILL');
32
+ await this.browser.close();
33
+ }
34
+
35
+ /**
36
+ * rotate
37
+ */
38
+ public async rotateBrowser() {
39
+ this.browser.close().catch();
40
+ this.browser = await getEnvAwareBrowserInstance();
41
+ }
42
+
43
+ public async getNewIncognitoContext(): Promise<plugins.puppeteer.BrowserContext> {
44
+ if (this.browser) {
45
+ return this.browser.createIncognitoBrowserContext();
46
+ } else {
47
+ throw new Error('you need to start the IncognitoBrowser instance first');
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,41 @@
1
+ import * as plugins from './smartpuppeteer.plugins.js';
2
+
3
+ export interface IEnvAwareOptions {
4
+ forceNoSandbox?: boolean;
5
+ usePipe?: boolean;
6
+ }
7
+
8
+ export const getEnvAwareBrowserInstance = async (
9
+ optionsArg: IEnvAwareOptions = {}
10
+ ): Promise<plugins.puppeteer.Browser> => {
11
+ const options: IEnvAwareOptions = {
12
+ ...{
13
+ forceNoSandbox: false,
14
+ },
15
+ ...optionsArg,
16
+ };
17
+
18
+ let chromeArgs: string[] = [];
19
+ if (process.env.CI || options.forceNoSandbox || plugins.os.userInfo().username === 'root') {
20
+ chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']);
21
+ }
22
+
23
+ let headlessBrowser: plugins.puppeteer.Browser;
24
+ console.log('launching puppeteer bundled chrome with arguments:');
25
+ console.log(chromeArgs);
26
+ headlessBrowser = await plugins.puppeteer.launch({
27
+ args: chromeArgs,
28
+ pipe: options.usePipe !== undefined ? options.usePipe : true,
29
+ headless: true,
30
+ ...(() => {
31
+ const returnObject: any = {};
32
+ const googleChrome = plugins.smartshell.which.sync('google-chrome');
33
+ if (googleChrome) {
34
+ returnObject.executablePath = googleChrome;
35
+ }
36
+ return returnObject;
37
+ })(),
38
+ });
39
+
40
+ return headlessBrowser;
41
+ };
@@ -0,0 +1,16 @@
1
+ // node native scope
2
+ import * as os from 'os';
3
+
4
+ export { os };
5
+
6
+ // @pushrocks scope
7
+ import * as smartdelay from '@pushrocks/smartdelay';
8
+ import * as smartshell from '@pushrocks/smartshell';
9
+
10
+ export { smartdelay, smartshell };
11
+
12
+ // third party scope
13
+ import puppeteer from 'puppeteer';
14
+ import treeKill from 'tree-kill';
15
+
16
+ export { puppeteer, treeKill };