Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
9615d7d0e3 | |||
431f63e283 | |||
e9bf2032fb | |||
3a2e85b4e5 | |||
fdfa6a72c8 | |||
801416dc1e | |||
84cf226d42 | |||
63f56da150 | |||
3559453579 | |||
ea509d4246 | |||
c13a125ac7 | |||
8f6949b1b8 | |||
9b698c6dea | |||
157bcff7c4 | |||
934423f0ad | |||
e6d7fdced6 | |||
2fc4e691ac | |||
7e8035ea61 | |||
1bc3112bb7 | |||
4a177fd166 | |||
c1cf019af2 | |||
9ecf7c81d4 | |||
8fa40087d4 | |||
a5576410cd | |||
dff08ed54b | |||
fe4dd5c1ee | |||
7f146b547f | |||
4ee936035c | |||
2e95f1db7f | |||
35e5ded808 |
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
|
128
.gitlab-ci.yml
128
.gitlab-ci.yml
@ -1,16 +1,19 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,102 +21,115 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- 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
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
testBuild:
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
only:
|
||||||
- docker:stable-dind
|
- tags
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--volume "$PWD":/code
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -121,5 +137,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
28
README.md
28
README.md
@ -1,28 +0,0 @@
|
|||||||
# @pushrocks/smartbrowser
|
|
||||||
puppeteer wrapper for easy tasks
|
|
||||||
|
|
||||||
## Availabililty and Links
|
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartbrowser)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartbrowser)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartbrowser)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartbrowser/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/smartbrowser/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartbrowser/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartbrowser)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartbrowser)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://prettier.io/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
@ -1,10 +1,9 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"globalNpmTools": [
|
"npmAccessLevel": "public"
|
||||||
"npmts"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
|
2548
package-lock.json
generated
2548
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
46
package.json
46
package.json
@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartbrowser",
|
"name": "@pushrocks/smartbrowser",
|
||||||
"version": "1.0.13",
|
"version": "2.0.5",
|
||||||
"description": "simplified puppeteer",
|
"description": "simplified puppeteer",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tstest test/",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "tsbuild"
|
"build": "(tsbuild --web --allowimplicitany)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -19,27 +20,32 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartbrowser#README",
|
"homepage": "https://gitlab.com/pushrocks/smartbrowser#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.3",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartpdf": "^1.0.17",
|
"@pushrocks/smartpdf": "^3.0.15",
|
||||||
"@pushrocks/smartunique": "^3.0.1",
|
"@pushrocks/smartpuppeteer": "^2.0.0",
|
||||||
"puppeteer": "^1.17.0"
|
"@pushrocks/smartunique": "^3.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@gitzone/tsbuild": "^2.1.61",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tsrun": "^1.2.39",
|
||||||
"@pushrocks/tapbundle": "^3.0.9",
|
"@gitzone/tstest": "^1.0.69",
|
||||||
"tslint": "^5.17.0",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"@types/node": "^18.11.9"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": false,
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_*/**/*",
|
||||||
"assets/*",
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
4085
pnpm-lock.yaml
generated
Normal file
4085
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
39
readme.md
Normal file
39
readme.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# @pushrocks/smartbrowser
|
||||||
|
puppeteer wrapper for easy tasks
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartbrowser)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartbrowser)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartbrowser)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartbrowser/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
## 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). :)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
25
test/test.ts
25
test/test.ts
@ -1,29 +1,36 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import * as smartbrowser from '../ts/index';
|
import * as smartbrowser from '../ts/index.js';
|
||||||
let testSmartBrowser: smartbrowser.SmartBrowser;
|
let testSmartBrowser: smartbrowser.SmartBrowser;
|
||||||
|
|
||||||
tap.test('should instanstiate a new browser ', async () => {
|
tap.test('should instanstiate a new browser ', async () => {
|
||||||
testSmartBrowser = new smartbrowser.SmartBrowser();
|
testSmartBrowser = new smartbrowser.SmartBrowser();
|
||||||
return expect(testSmartBrowser).to.be.instanceof(smartbrowser.SmartBrowser);
|
return expect(testSmartBrowser).toBeInstanceOf(smartbrowser.SmartBrowser);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start the browser ', async () => {
|
tap.test('should start the browser ', async () => {
|
||||||
await expect(testSmartBrowser.start()).to.eventually.be.fulfilled;
|
await testSmartBrowser.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a PDF from a page', async tools => {
|
tap.test('should create a PDF from a page', async (tools) => {
|
||||||
const result = await testSmartBrowser.pdfFromPage('https://lossless.com');
|
const result = await testSmartBrowser.pdfFromPage('https://lossless.com');
|
||||||
expect(result.buffer).to.be.instanceOf(Buffer);
|
expect(result.buffer).toBeInstanceOf(Buffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should produce a valid screenshot', async tools => {
|
tap.test('should produce a valid screenshot', async (tools) => {
|
||||||
const result = await testSmartBrowser.screenshotFromPage('https://lossless.com');
|
const result = await testSmartBrowser.screenshotFromPage('https://lossless.com');
|
||||||
expect(result.buffer).to.be.instanceOf(Buffer);
|
expect(result.buffer).toBeInstanceOf(Buffer);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should evalute something in the browser', async () => {
|
||||||
|
const result = await testSmartBrowser.evaluateOnPage('https://lossless.com', async () => {
|
||||||
|
return window.location.toString();
|
||||||
|
});
|
||||||
|
console.log(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should stop the browser ', async () => {
|
tap.test('should stop the browser ', async () => {
|
||||||
await expect(testSmartBrowser.stop()).to.eventually.be.fulfilled;
|
await testSmartBrowser.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/smartbrowser',
|
||||||
|
version: '2.0.5',
|
||||||
|
description: 'simplified puppeteer'
|
||||||
|
}
|
64
ts/index.ts
64
ts/index.ts
@ -1,20 +1,37 @@
|
|||||||
import * as plugins from './smartbrowser.plugins';
|
import * as plugins from './smartbrowser.plugins.js';
|
||||||
|
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SmartBrowser
|
* SmartBrowser
|
||||||
*/
|
*/
|
||||||
export class SmartBrowser {
|
export class SmartBrowser {
|
||||||
public headlessBrowser: plugins.puppeteer.Browser;
|
public headlessBrowser: plugins.smartpuppeteer.puppeteer.Browser;
|
||||||
public smartpdf: plugins.smartpdf.SmartPdf;
|
public smartpdf: plugins.smartpdf.SmartPdf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* start the SmartBrowser instance
|
||||||
|
*/
|
||||||
|
public async start() {
|
||||||
|
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
|
||||||
|
this.smartpdf = new plugins.smartpdf.SmartPdf();
|
||||||
|
await this.smartpdf.start(this.headlessBrowser);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stop the SmartBrowser instance
|
||||||
|
*/
|
||||||
|
public async stop() {
|
||||||
|
await this.headlessBrowser.close();
|
||||||
|
await this.smartpdf.stop();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a pdf from page
|
* create a pdf from page
|
||||||
* @param urlArg
|
* @param urlArg
|
||||||
*/
|
*/
|
||||||
public pdfFromPage(urlArg: string) {
|
public async pdfFromPage(urlArg: string): Promise<plugins.smartpdf.IPdf> {
|
||||||
const result = this.smartpdf.getFullWebsiteAsSinglePdf(urlArg);
|
const result = await this.smartpdf.getFullWebsiteAsSinglePdf(urlArg);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,16 +43,16 @@ export class SmartBrowser {
|
|||||||
const pageId = plugins.smartunique.shortId();
|
const pageId = plugins.smartunique.shortId();
|
||||||
const page = await this.headlessBrowser.newPage();
|
const page = await this.headlessBrowser.newPage();
|
||||||
await page.goto(urlArg, {
|
await page.goto(urlArg, {
|
||||||
waitUntil: 'networkidle2'
|
waitUntil: 'networkidle2',
|
||||||
});
|
});
|
||||||
const screenshotBuffer = await page.screenshot({
|
const screenshotBuffer = await page.screenshot({
|
||||||
encoding: 'binary'
|
encoding: 'binary',
|
||||||
});
|
}) as Buffer;
|
||||||
await page.close();
|
await page.close();
|
||||||
return {
|
return {
|
||||||
name: pageId,
|
name: pageId,
|
||||||
id: `${pageId}.js`,
|
id: `${pageId}.js`,
|
||||||
buffer: screenshotBuffer
|
buffer: screenshotBuffer,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,32 +61,13 @@ export class SmartBrowser {
|
|||||||
* @param urlArg
|
* @param urlArg
|
||||||
* @param funcArg
|
* @param funcArg
|
||||||
*/
|
*/
|
||||||
public async evaluateOnPage(urlArg: string, funcArg: () => Promise<any>) {
|
public async evaluateOnPage<T>(urlArg: string, funcArg: () => Promise<T>) {
|
||||||
const page = await this.headlessBrowser.newPage();
|
const page = await this.headlessBrowser.newPage();
|
||||||
await page.goto(urlArg, {
|
await page.goto(urlArg, {
|
||||||
waitUntil: 'networkidle2'
|
waitUntil: 'networkidle2',
|
||||||
});
|
});
|
||||||
}
|
const result = await page.evaluate(funcArg);
|
||||||
|
await page.close();
|
||||||
/**
|
return result;
|
||||||
* start a page
|
|
||||||
*/
|
|
||||||
public async start() {
|
|
||||||
this.headlessBrowser = await plugins.puppeteer.launch({
|
|
||||||
defaultViewport: {
|
|
||||||
width: 1600,
|
|
||||||
height: 1080
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.smartpdf = new plugins.smartpdf.SmartPdf();
|
|
||||||
await this.smartpdf.start(this.headlessBrowser);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stops the smartbrowser instance
|
|
||||||
*/
|
|
||||||
public async stop() {
|
|
||||||
await this.headlessBrowser.close();
|
|
||||||
await this.smartpdf.stop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
export * from './interfaces.screenshotresult';
|
export * from './interfaces.screenshotresult.js';
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as smartpdf from '@pushrocks/smartpdf';
|
import * as smartpdf from '@pushrocks/smartpdf';
|
||||||
|
import * as smartpuppeteer from '@pushrocks/smartpuppeteer';
|
||||||
import * as smartunique from '@pushrocks/smartunique';
|
import * as smartunique from '@pushrocks/smartunique';
|
||||||
|
|
||||||
export { smartpdf, smartunique };
|
export { smartpdf, smartpuppeteer, smartunique };
|
||||||
|
|
||||||
// third party
|
// third party
|
||||||
import puppeteer from 'puppeteer';
|
|
||||||
|
|
||||||
export { puppeteer };
|
|
||||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
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