fix(core): update
This commit is contained in:
69
ts/index.ts
69
ts/index.ts
@ -1,21 +1,76 @@
|
||||
import * as plugins from './smartbrowser.plugins';
|
||||
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
/**
|
||||
* SmartBrowser
|
||||
*/
|
||||
export class SmartBrowser {
|
||||
puppeteer: plugins.puppeteer.Browser;
|
||||
smartpdf: plugins.smartpdf.SmartPdf;
|
||||
pdfFromPage(urlArg: string) {
|
||||
this.smartpdf.getFullWebsiteAsSinglePdf(urlArg: );
|
||||
public headlessBrowser: plugins.puppeteer.Browser;
|
||||
public smartpdf: plugins.smartpdf.SmartPdf;
|
||||
|
||||
/**
|
||||
* 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 (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();
|
||||
this.smartpdf.init();
|
||||
await this.smartpdf.start(this.headlessBrowser);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* stops the smartbrowser instance
|
||||
*/
|
||||
stop() {
|
||||
this.smartpdf.close();
|
||||
public async stop() {
|
||||
await this.headlessBrowser.close();
|
||||
await this.smartpdf.stop();
|
||||
}
|
||||
}
|
||||
|
2
ts/interfaces/index.ts
Normal file
2
ts/interfaces/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
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,9 +1,10 @@
|
||||
// pushrocks scope
|
||||
import * as smartpdf from '@pushrocks/smartpdf';
|
||||
import * as smartunique from '@pushrocks/smartunique';
|
||||
|
||||
export { smartpdf };
|
||||
export { smartpdf, smartunique };
|
||||
|
||||
// third party
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import puppeteer from 'puppeteer';
|
||||
|
||||
export { puppeteer };
|
||||
|
Reference in New Issue
Block a user