Skip to content
Snippets Groups Projects

Add request interception handler

Merged Boris Budini requested to merge request_interception into master
5 files
+ 569
344
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 13
3
@@ -26,6 +26,9 @@ program
@@ -26,6 +26,9 @@ program
.option("-t, --timeout [ms]", "Set a max timeout of [ms]")
.option("-t, --timeout [ms]", "Set a max timeout of [ms]")
.option("-x, --html", "output html file")
.option("-x, --html", "output html file")
.option("-b, --blockLocal", "Disallow access to filesystem for local files")
.option("-b, --blockLocal", "Disallow access to filesystem for local files")
 
.option("-r, --blockRemote", "Disallow requests to remote servers")
 
.option("--allowedPath [allowedPaths]", "Only allow access to given filesystem paths, repeatable.", collect, [])
 
.option("--allowedDomain [allowedDomains]", "Only allow access to given remote domains, repeatable", collect, [])
.option("--outline-tags [tags]", "Specifies that an outline should be " +
.option("--outline-tags [tags]", "Specifies that an outline should be " +
"generated for the resulting PDF document. [tags] specifies which " +
"generated for the resulting PDF document. [tags] specifies which " +
"HTML tags should be considered for that outline. " +
"HTML tags should be considered for that outline. " +
@@ -35,13 +38,13 @@ program
@@ -35,13 +38,13 @@ 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")
.parse(process.argv);
.parse(process.argv);
function collect(value, previous) {
function collect(value, previous) {
return previous.concat(value);
return previous.concat(value);
}
}
let input = program.inputs || program.args[0];
let input = program.inputs || program.args[0];
let dir = process.cwd();
let dir = process.cwd();
@@ -49,7 +52,7 @@ let dir = process.cwd();
@@ -49,7 +52,7 @@ let dir = process.cwd();
let relativePath;
let relativePath;
let allowLocal;
let allowLocal;
try {
try {
input = new URL(input);
let uri = new URL(input);
allowLocal = false;
allowLocal = false;
} catch (error) {
} catch (error) {
relativePath = path.resolve(dir, input);
relativePath = path.resolve(dir, input);
@@ -104,7 +107,14 @@ if (typeof input === "string") {
@@ -104,7 +107,14 @@ if (typeof input === "string") {
}
}
(async () => {
(async () => {
let printer = new Printer(headless, allowLocal, program.additionalScript);
let printer = new Printer({
 
headless: headless,
 
allowLocal: allowLocal,
 
allowRemote: !program.blockRemote,
 
allowedPaths: program.allowedPaths,
 
allowedDomains: program.allowedDomains,
 
additionalScripts: program.additionalScript,
 
});
printer.on("page", (page) => {
printer.on("page", (page) => {
if (page.position === 0) {
if (page.position === 0) {