4 Commits

Author SHA1 Message Date
2e95f1db7f 1.0.14 2019-06-04 08:29:06 +02:00
35e5ded808 fix(core): update 2019-06-04 08:29:05 +02:00
f2430d095f 1.0.13 2019-06-03 17:17:20 +02:00
d79a5af51a fix(core): update 2019-06-03 17:17:20 +02:00
6 changed files with 44 additions and 43 deletions

11
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartbrowser",
"version": "1.0.12",
"version": "1.0.14",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -282,6 +282,15 @@
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.2.tgz",
"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": {
"version": "1.1.15",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.15.tgz",

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartbrowser",
"version": "1.0.12",
"version": "1.0.14",
"description": "simplified puppeteer",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@ -21,8 +21,8 @@
"dependencies": {
"@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartpdf": "^1.0.17",
"@pushrocks/smartunique": "^3.0.1",
"puppeteer": "^1.17.0"
"@pushrocks/smartpuppeteer": "^1.0.5",
"@pushrocks/smartunique": "^3.0.1"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.11",

View File

@ -3,22 +3,21 @@ import { tap, expect } from '@pushrocks/tapbundle';
import * as smartbrowser from '../ts/index';
let testSmartBrowser: smartbrowser.SmartBrowser;
tap
.test('should instanstiate a new browser ', async () => {
testSmartBrowser = new smartbrowser.SmartBrowser();
return expect(testSmartBrowser).to.be.instanceof(smartbrowser.SmartBrowser);
})
tap.test('should instanstiate a new browser ', async () => {
testSmartBrowser = new smartbrowser.SmartBrowser();
return expect(testSmartBrowser).to.be.instanceof(smartbrowser.SmartBrowser);
});
tap.test('should start the browser ', async () => {
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');
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');
expect(result.buffer).to.be.instanceOf(Buffer);
});

View File

@ -6,9 +6,26 @@ import * as interfaces from './interfaces';
* SmartBrowser
*/
export class SmartBrowser {
public headlessBrowser: plugins.puppeteer.Browser;
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
@ -20,7 +37,7 @@ export class SmartBrowser {
/**
* make a screenshot from a page
* @param urlArg
* @param urlArg
*/
public async screenshotFromPage(urlArg: string): Promise<interfaces.IScreenShotResult> {
const pageId = plugins.smartunique.shortId();
@ -41,36 +58,15 @@ export class SmartBrowser {
/**
* evalutes an expression on a page
* @param urlArg
* @param funcArg
* @param urlArg
* @param funcArg
*/
public async evaluateOnPage (urlArg: string, funcArg: () => Promise<any>) {
public async evaluateOnPage(urlArg: string, funcArg: () => Promise<any>) {
const page = await this.headlessBrowser.newPage();
await page.goto(urlArg, {
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();
}
}

View File

@ -1,2 +1 @@
export * from './interfaces.screenshotresult';

View File

@ -1,10 +1,8 @@
// pushrocks scope
import * as smartpdf from '@pushrocks/smartpdf';
import * as smartpuppeteer from '@pushrocks/smartpuppeteer';
import * as smartunique from '@pushrocks/smartunique';
export { smartpdf, smartunique };
export { smartpdf, smartpuppeteer, smartunique };
// third party
import puppeteer from 'puppeteer';
export { puppeteer };