Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
7f146b547f | |||
4ee936035c | |||
2e95f1db7f | |||
35e5ded808 | |||
f2430d095f | |||
d79a5af51a | |||
318bdd1bd8 | |||
54a0ec6c71 | |||
8853eecbb9 | |||
1bfca4456c | |||
b337e4c779 | |||
53d56d2d8a | |||
e3781cfd4d | |||
eca90bdf64 |
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
|
112
.gitlab-ci.yml
112
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
|||||||
# 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
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,102 +18,104 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
audit:
|
||||||
|
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 --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# 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
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- priv
|
||||||
testSTABLE:
|
|
||||||
|
testBuild:
|
||||||
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
|
- lossless
|
||||||
- notpriv
|
- 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:
|
|
||||||
- docker:stable-dind
|
|
||||||
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 +123,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
35
README.md
35
README.md
@ -1,35 +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://push.rocks)
|
|
||||||
|
|
||||||
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)
|
|
@ -5,6 +5,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
|
4259
package-lock.json
generated
4259
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartbrowser",
|
"name": "@pushrocks/smartbrowser",
|
||||||
"version": "1.0.8",
|
"version": "1.0.15",
|
||||||
"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",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "echo \"Not needed for now\""
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -19,22 +19,27 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartbrowser#README",
|
"homepage": "https://gitlab.com/pushrocks/smartbrowser#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"puppeteer": "^1.17.0"
|
"@pushrocks/smartdelay": "^2.0.9",
|
||||||
|
"@pushrocks/smartpdf": "^2.0.2",
|
||||||
|
"@pushrocks/smartpuppeteer": "^1.0.15",
|
||||||
|
"@pushrocks/smartunique": "^3.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@gitzone/tsbuild": "^2.1.24",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.32",
|
||||||
"@pushrocks/tapbundle": "^3.0.9",
|
"@pushrocks/tapbundle": "^3.2.1",
|
||||||
"tslint": "^5.16.0",
|
"tslint": "^6.1.2",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"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"
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
<head>
|
|
||||||
<title>Test</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
Test
|
|
||||||
</body>
|
|
33
test/test.js
33
test/test.js
@ -1,33 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-test");
|
|
||||||
const should = require("should");
|
|
||||||
const smartbrowser = require("../dist/index");
|
|
||||||
let testSmartBrowser;
|
|
||||||
describe('smartbrowser', () => {
|
|
||||||
it('should instanstiate a new browser ', function () {
|
|
||||||
testSmartBrowser = new smartbrowser.Smartbrowser({
|
|
||||||
webroot: './test/assets/',
|
|
||||||
watchFiles: ['./test/assets/']
|
|
||||||
});
|
|
||||||
should(testSmartBrowser).be.instanceof(smartbrowser.Smartbrowser);
|
|
||||||
});
|
|
||||||
it('should start the browser ', function (done) {
|
|
||||||
testSmartBrowser.start().then((bsInstance) => {
|
|
||||||
done();
|
|
||||||
}).catch((err) => { console.log(err); });
|
|
||||||
});
|
|
||||||
it('should stop the browser ', function (done) {
|
|
||||||
this.timeout(10000);
|
|
||||||
setTimeout(() => {
|
|
||||||
testSmartBrowser.stop().then(() => {
|
|
||||||
done();
|
|
||||||
}).catch((err) => { console.log(err); });
|
|
||||||
}, 2000);
|
|
||||||
});
|
|
||||||
it('should exit correctly', function () {
|
|
||||||
setTimeout(() => {
|
|
||||||
process.exit(0);
|
|
||||||
}, 2000);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsOENBQTZDO0FBRTdDLElBQUksZ0JBQTJDLENBQUE7QUFFL0MsUUFBUSxDQUFDLGNBQWMsRUFBRTtJQUNyQixFQUFFLENBQUMsb0NBQW9DLEVBQUU7UUFDckMsZ0JBQWdCLEdBQUcsSUFBSSxZQUFZLENBQUMsWUFBWSxDQUFDO1lBQzdDLE9BQU8sRUFBRSxnQkFBZ0I7WUFDekIsVUFBVSxFQUFFLENBQUMsZ0JBQWdCLENBQUM7U0FDakMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLGdCQUFnQixDQUFDLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxZQUFZLENBQUMsWUFBWSxDQUFDLENBQUE7SUFDckUsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsMkJBQTJCLEVBQUUsVUFBVSxJQUFJO1FBQzFDLGdCQUFnQixDQUFDLEtBQUssRUFBRSxDQUFDLElBQUksQ0FBQyxDQUFDLFVBQVU7WUFDckMsSUFBSSxFQUFFLENBQUE7UUFDVixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxHQUFHLE9BQU8sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO0lBQzNDLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLDBCQUEwQixFQUFFLFVBQVUsSUFBSTtRQUN6QyxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBQ25CLFVBQVUsQ0FBQztZQUNQLGdCQUFnQixDQUFDLElBQUksRUFBRSxDQUFDLElBQUksQ0FBQztnQkFDekIsSUFBSSxFQUFFLENBQUE7WUFDVixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxHQUFHLE9BQU8sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzNDLENBQUMsRUFBRSxJQUFJLENBQUMsQ0FBQTtJQUNaLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLHVCQUF1QixFQUFDO1FBQ3ZCLFVBQVUsQ0FBQztZQUNQLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDbkIsQ0FBQyxFQUFDLElBQUksQ0FBQyxDQUFBO0lBQ1gsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
|
|
56
test/test.ts
56
test/test.ts
@ -1,32 +1,36 @@
|
|||||||
import { tap, expect } from 'tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import * as smartdelay from 'smartdelay';
|
|
||||||
|
|
||||||
import * as smartbrowser from '../dist/index';
|
import * as smartbrowser from '../ts/index';
|
||||||
let testSmartBrowser: smartbrowser.Smartbrowser;
|
let testSmartBrowser: smartbrowser.SmartBrowser;
|
||||||
|
|
||||||
tap
|
tap.test('should instanstiate a new browser ', async () => {
|
||||||
.test('should instanstiate a new browser ', async () => {
|
testSmartBrowser = new smartbrowser.SmartBrowser();
|
||||||
testSmartBrowser = new smartbrowser.Smartbrowser({
|
return expect(testSmartBrowser).to.be.instanceof(smartbrowser.SmartBrowser);
|
||||||
webroot: './test/assets/',
|
});
|
||||||
watchFiles: ['./test/assets/']
|
|
||||||
});
|
|
||||||
return expect(testSmartBrowser).to.be.instanceof(smartbrowser.Smartbrowser);
|
|
||||||
})
|
|
||||||
.catch(tap.threw);
|
|
||||||
|
|
||||||
tap
|
tap.test('should start the browser ', async () => {
|
||||||
.test('should start the browser ', async () => {
|
await expect(testSmartBrowser.start()).to.eventually.be.fulfilled;
|
||||||
return await expect(testSmartBrowser.start()).to.eventually.be.fulfilled;
|
});
|
||||||
})
|
|
||||||
.catch(tap.threw);
|
tap.test('should create a PDF from a page', async tools => {
|
||||||
|
const result = await testSmartBrowser.pdfFromPage('https://lossless.com');
|
||||||
|
expect(result.buffer).to.be.instanceOf(Buffer);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should produce a valid screenshot', async tools => {
|
||||||
|
const result = await testSmartBrowser.screenshotFromPage('https://lossless.com');
|
||||||
|
expect(result.buffer).to.be.instanceOf(Buffer);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should evalute something in the browser', async () => {
|
||||||
|
const result = await testSmartBrowser.evaluateOnPage('https://lossless.com', async () => {
|
||||||
|
return 'hi';
|
||||||
|
});
|
||||||
|
console.log(result);
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('should stop the browser ', async () => {
|
tap.test('should stop the browser ', async () => {
|
||||||
return await smartdelay.delayFor(2000).then(() => {
|
await expect(testSmartBrowser.stop()).to.eventually.be.fulfilled;
|
||||||
return expect(testSmartBrowser.stop()).to.eventually.be.fulfilled;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
tap.test('should exit correctly', async () => {
|
|
||||||
smartdelay.delayFor(2000).then(() => {
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
72
ts/index.ts
72
ts/index.ts
@ -1,3 +1,73 @@
|
|||||||
import * as plugins from './smartbrowser.plugins';
|
import * as plugins from './smartbrowser.plugins';
|
||||||
|
|
||||||
export class SmartBrowser {}
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SmartBrowser
|
||||||
|
*/
|
||||||
|
export class SmartBrowser {
|
||||||
|
public headlessBrowser: plugins.smartpuppeteer.puppeteer.Browser;
|
||||||
|
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
|
||||||
|
* @param urlArg
|
||||||
|
*/
|
||||||
|
public pdfFromPage(urlArg: string) {
|
||||||
|
const result = this.smartpdf.getFullWebsiteAsSinglePdf(urlArg);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* make a screenshot from a page
|
||||||
|
* @param urlArg
|
||||||
|
*/
|
||||||
|
public async screenshotFromPage(urlArg: string): Promise<interfaces.IScreenShotResult> {
|
||||||
|
const pageId = plugins.smartunique.shortId();
|
||||||
|
const page = await this.headlessBrowser.newPage();
|
||||||
|
await page.goto(urlArg, {
|
||||||
|
waitUntil: 'networkidle2'
|
||||||
|
});
|
||||||
|
const screenshotBuffer = await page.screenshot({
|
||||||
|
encoding: 'binary'
|
||||||
|
});
|
||||||
|
await page.close();
|
||||||
|
return {
|
||||||
|
name: pageId,
|
||||||
|
id: `${pageId}.js`,
|
||||||
|
buffer: screenshotBuffer
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* evalutes an expression on a page
|
||||||
|
* @param urlArg
|
||||||
|
* @param funcArg
|
||||||
|
*/
|
||||||
|
public async evaluateOnPage<T>(urlArg: string, funcArg: () => Promise<T>) {
|
||||||
|
const page = await this.headlessBrowser.newPage();
|
||||||
|
await page.goto(urlArg, {
|
||||||
|
waitUntil: 'networkidle2'
|
||||||
|
});
|
||||||
|
const result = await page.evaluate(funcArg);
|
||||||
|
await page.close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './interfaces.screenshotresult';
|
5
ts/interfaces/interfaces.screenshotresult.ts
Normal file
5
ts/interfaces/interfaces.screenshotresult.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export interface IScreenShotResult {
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
buffer: Buffer;
|
||||||
|
}
|
@ -1,3 +1,8 @@
|
|||||||
import * as puppeteer from 'puppeteer';
|
// pushrocks scope
|
||||||
|
import * as smartpdf from '@pushrocks/smartpdf';
|
||||||
|
import * as smartpuppeteer from '@pushrocks/smartpuppeteer';
|
||||||
|
import * as smartunique from '@pushrocks/smartunique';
|
||||||
|
|
||||||
export { puppeteer };
|
export { smartpdf, smartpuppeteer, smartunique };
|
||||||
|
|
||||||
|
// third party
|
||||||
|
Reference in New Issue
Block a user