Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
59eed53644 | |||
473aaa004a | |||
ecfd4115a1 | |||
0fbbfaac7c | |||
86d2fc2c5b | |||
f97866fe82 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpdf",
|
"name": "@pushrocks/smartpdf",
|
||||||
"version": "1.0.13",
|
"version": "1.0.16",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpdf",
|
"name": "@pushrocks/smartpdf",
|
||||||
"version": "1.0.13",
|
"version": "1.0.16",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "create pdfs on the fly",
|
"description": "create pdfs on the fly",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -5,7 +5,7 @@ import { PdfCandidate } from './smartpdf.classes.pdfcandidate';
|
|||||||
|
|
||||||
declare const document;
|
declare const document;
|
||||||
|
|
||||||
import { IPdfResult } from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
export class SmartPdf {
|
export class SmartPdf {
|
||||||
htmlServerInstance: Server;
|
htmlServerInstance: Server;
|
||||||
@ -15,15 +15,22 @@ export class SmartPdf {
|
|||||||
private _readyDeferred: plugins.smartpromise.Deferred<void>;
|
private _readyDeferred: plugins.smartpromise.Deferred<void>;
|
||||||
private _candidates: { [key: string]: PdfCandidate } = {};
|
private _candidates: { [key: string]: PdfCandidate } = {};
|
||||||
|
|
||||||
constructor(headlessBrowserArg?) {
|
constructor() {
|
||||||
this.headlessBrowser = headlessBrowserArg
|
|
||||||
this._readyDeferred = new plugins.smartpromise.Deferred();
|
this._readyDeferred = new plugins.smartpromise.Deferred();
|
||||||
}
|
}
|
||||||
|
|
||||||
async start() {
|
async start(headlessBrowserArg?) {
|
||||||
|
// lets set the external browser in case one is provided
|
||||||
|
this.headlessBrowser = headlessBrowserArg
|
||||||
// setup puppeteer
|
// setup puppeteer
|
||||||
if (!this.headlessBrowser) {
|
if (!this.headlessBrowser) {
|
||||||
this.headlessBrowser = await plugins.puppeteer.launch();
|
let chromeArgs: string[] = [];
|
||||||
|
if(process.env.CI) {
|
||||||
|
chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox'])
|
||||||
|
}
|
||||||
|
this.headlessBrowser = await plugins.puppeteer.launch({
|
||||||
|
args: chromeArgs
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.externalBrowser = true;
|
this.externalBrowser = true;
|
||||||
}
|
}
|
||||||
@ -43,6 +50,7 @@ export class SmartPdf {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stop
|
||||||
async stop() {
|
async stop() {
|
||||||
const done = plugins.smartpromise.defer<void>();
|
const done = plugins.smartpromise.defer<void>();
|
||||||
this.htmlServerInstance.close(() => {
|
this.htmlServerInstance.close(() => {
|
||||||
@ -59,7 +67,7 @@ export class SmartPdf {
|
|||||||
/**
|
/**
|
||||||
* returns a pdf for a given html string;
|
* returns a pdf for a given html string;
|
||||||
*/
|
*/
|
||||||
async getPdfForHtmlString(htmlStringArg: string): Promise<IPdfResult> {
|
async getPdfForHtmlString(htmlStringArg: string): Promise<interfaces.IPdfResult> {
|
||||||
await this._readyDeferred.promise;
|
await this._readyDeferred.promise;
|
||||||
const pdfCandidate = new PdfCandidate(htmlStringArg);
|
const pdfCandidate = new PdfCandidate(htmlStringArg);
|
||||||
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
|
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
|
||||||
@ -89,7 +97,7 @@ export class SmartPdf {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPdfForWebsite(websiteUrl: string): Promise<IPdfResult> {
|
async getPdfForWebsite(websiteUrl: string): Promise<interfaces.IPdfResult> {
|
||||||
const page = await this.headlessBrowser.newPage();
|
const page = await this.headlessBrowser.newPage();
|
||||||
page.emulateMedia('screen');
|
page.emulateMedia('screen');
|
||||||
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });
|
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });
|
||||||
|
Reference in New Issue
Block a user