Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
2e95f1db7f | |||
35e5ded808 | |||
f2430d095f | |||
d79a5af51a |
11
package-lock.json
generated
11
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartbrowser",
|
"name": "@pushrocks/smartbrowser",
|
||||||
"version": "1.0.12",
|
"version": "1.0.14",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -282,6 +282,15 @@
|
|||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.2.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.2.tgz",
|
||||||
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
|
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
|
||||||
},
|
},
|
||||||
|
"@pushrocks/smartpuppeteer": {
|
||||||
|
"version": "1.0.5",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpuppeteer/-/smartpuppeteer-1.0.5.tgz",
|
||||||
|
"integrity": "sha512-7iD2mxQHXG5/6PwZY2wU6GQjNXy9dR5cLP/nvfjxXaelX/x3N1yagjPAuMYxuIqiTtVfrHC4Ehq+gnTZ4mSPow==",
|
||||||
|
"requires": {
|
||||||
|
"@types/puppeteer": "^1.12.4",
|
||||||
|
"puppeteer": "^1.17.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@pushrocks/smartrequest": {
|
"@pushrocks/smartrequest": {
|
||||||
"version": "1.1.15",
|
"version": "1.1.15",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.15.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.15.tgz",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartbrowser",
|
"name": "@pushrocks/smartbrowser",
|
||||||
"version": "1.0.12",
|
"version": "1.0.14",
|
||||||
"description": "simplified puppeteer",
|
"description": "simplified puppeteer",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
@ -21,8 +21,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.3",
|
"@pushrocks/smartdelay": "^2.0.3",
|
||||||
"@pushrocks/smartpdf": "^1.0.17",
|
"@pushrocks/smartpdf": "^1.0.17",
|
||||||
"@pushrocks/smartunique": "^3.0.1",
|
"@pushrocks/smartpuppeteer": "^1.0.5",
|
||||||
"puppeteer": "^1.17.0"
|
"@pushrocks/smartunique": "^3.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@gitzone/tsbuild": "^2.1.11",
|
||||||
|
@ -3,22 +3,21 @@ import { tap, expect } from '@pushrocks/tapbundle';
|
|||||||
import * as smartbrowser from '../ts/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);
|
return expect(testSmartBrowser).to.be.instanceof(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 expect(testSmartBrowser.start()).to.eventually.be.fulfilled;
|
||||||
});
|
});
|
||||||
|
|
||||||
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).to.be.instanceOf(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).to.be.instanceOf(Buffer);
|
||||||
});
|
});
|
||||||
|
42
ts/index.ts
42
ts/index.ts
@ -6,9 +6,26 @@ import * as interfaces from './interfaces';
|
|||||||
* 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
|
||||||
@ -44,33 +61,12 @@ export class SmartBrowser {
|
|||||||
* @param urlArg
|
* @param urlArg
|
||||||
* @param funcArg
|
* @param funcArg
|
||||||
*/
|
*/
|
||||||
public async evaluateOnPage (urlArg: string, funcArg: () => Promise<any>) {
|
public async evaluateOnPage(urlArg: string, funcArg: () => Promise<any>) {
|
||||||
const page = await this.headlessBrowser.newPage();
|
const page = await this.headlessBrowser.newPage();
|
||||||
await page.goto(urlArg, {
|
await page.goto(urlArg, {
|
||||||
waitUntil: 'networkidle2'
|
waitUntil: 'networkidle2'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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,2 +1 @@
|
|||||||
export * from './interfaces.screenshotresult';
|
export * from './interfaces.screenshotresult';
|
||||||
|
|
||||||
|
@ -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 };
|
|
||||||
|
Reference in New Issue
Block a user