Commit 79227e1c authored by Fred Chasen's avatar Fred Chasen
Browse files

Merge branch 'stavnycha/pagedjs-cli-master'

parents f6b3b46a ee732289
Pipeline #754 passed with stages
in 1 minute and 16 seconds
......@@ -39,7 +39,7 @@ program
"added to the HTML document before rendering. This is useful for " +
"adding custom pagedjs handlers. The option can be repeated.",
collect, [])
.option("--browserEndpoint", "Use a remote Chrome server with browserWSEndpoint")
.option("--browserEndpoint <browserEndpoint>", "Use a remote Chrome server with browserWSEndpoint")
.parse(process.argv);
function collect(value, previous) {
......@@ -115,6 +115,7 @@ if (typeof input === "string") {
allowedPaths: program.allowedPaths,
allowedDomains: program.allowedDomains,
additionalScripts: program.additionalScript,
browserEndpoint: program.browserEndpoint,
timeout: program.timeout,
};
......
......@@ -3,6 +3,7 @@ const puppeteer = require("puppeteer");
const fetch = require("node-fetch");
const path = require("path");
const fs = require("fs");
let dir = process.cwd();
......@@ -44,13 +45,12 @@ class Printer extends EventEmitter {
if (this.browserWSEndpoint) {
puppeteerOptions.browserWSEndpoint = this.browserWSEndpoint;
this.browser = await puppeteer.connect(puppeteerOptions);
} else {
this.browser = await puppeteer.launch(puppeteerOptions);
}
const browser = await puppeteer.launch(puppeteerOptions);
this.browser = browser;
return browser;
return this.browser;
}
async render(input) {
......@@ -79,7 +79,12 @@ class Printer extends EventEmitter {
url = input;
} catch (error) {
relativePath = path.resolve(dir, input);
url = "file://" + relativePath;
if (this.browserWSEndpoint) {
html = fs.readFileSync(relativePath, 'utf-8')
} else {
url = "file://" + relativePath;
}
}
} else {
url = input.url;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment