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 ...@@ -39,7 +39,7 @@ program
"added to the HTML document before rendering. This is useful for " + "added to the HTML document before rendering. This is useful for " +
"adding custom pagedjs handlers. The option can be repeated.", "adding custom pagedjs handlers. The option can be repeated.",
collect, []) collect, [])
.option("--browserEndpoint", "Use a remote Chrome server with browserWSEndpoint") .option("--browserEndpoint <browserEndpoint>", "Use a remote Chrome server with browserWSEndpoint")
.parse(process.argv); .parse(process.argv);
function collect(value, previous) { function collect(value, previous) {
...@@ -115,6 +115,7 @@ if (typeof input === "string") { ...@@ -115,6 +115,7 @@ if (typeof input === "string") {
allowedPaths: program.allowedPaths, allowedPaths: program.allowedPaths,
allowedDomains: program.allowedDomains, allowedDomains: program.allowedDomains,
additionalScripts: program.additionalScript, additionalScripts: program.additionalScript,
browserEndpoint: program.browserEndpoint,
timeout: program.timeout, timeout: program.timeout,
}; };
......
...@@ -3,6 +3,7 @@ const puppeteer = require("puppeteer"); ...@@ -3,6 +3,7 @@ const puppeteer = require("puppeteer");
const fetch = require("node-fetch"); const fetch = require("node-fetch");
const path = require("path"); const path = require("path");
const fs = require("fs");
let dir = process.cwd(); let dir = process.cwd();
...@@ -44,13 +45,12 @@ class Printer extends EventEmitter { ...@@ -44,13 +45,12 @@ class Printer extends EventEmitter {
if (this.browserWSEndpoint) { if (this.browserWSEndpoint) {
puppeteerOptions.browserWSEndpoint = 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); return this.browser;
this.browser = browser;
return browser;
} }
async render(input) { async render(input) {
...@@ -79,7 +79,12 @@ class Printer extends EventEmitter { ...@@ -79,7 +79,12 @@ class Printer extends EventEmitter {
url = input; url = input;
} catch (error) { } catch (error) {
relativePath = path.resolve(dir, input); relativePath = path.resolve(dir, input);
url = "file://" + relativePath;
if (this.browserWSEndpoint) {
html = fs.readFileSync(relativePath, 'utf-8')
} else {
url = "file://" + relativePath;
}
} }
} else { } else {
url = input.url; 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