From 27b0d37c8bbc64d6de7b1ba8d1855c266bfdd75a Mon Sep 17 00:00:00 2001
From: Fred Chasen <fchasen@gmail.com>
Date: Mon, 17 May 2021 22:54:52 -0700
Subject: [PATCH] Bring in changes from MR #18

---
 README.md      | 1 +
 bin/paged      | 6 ++++++
 src/printer.js | 5 +++++
 3 files changed, 12 insertions(+)

diff --git a/README.md b/README.md
index 9cbf31f..4fedaa0 100644
--- a/README.md
+++ b/README.md
@@ -39,6 +39,7 @@ pagedjs-cli ./path/to/index.html -o result.pdf
                                   rendering. This is useful for adding custom pagedjs handlers. The option
                                   can be repeated. (default: [])
 --browserEndpoint                 Use a remote Chrome server with browserWSEndpoint
+--browserArgs <browserArgs>       Additional comma separated flags for browser
 ```
 
 ## Hyphenation
diff --git a/bin/paged b/bin/paged
index 8871f42..55858b2 100755
--- a/bin/paged
+++ b/bin/paged
@@ -8,6 +8,10 @@ const fs = require("fs");
 // const writeFileAsync = promisify(fs.writeFile);
 const replaceExt = require("replace-ext");
 
+function commaSeparatedList(value) {
+  return value.split(',');
+}
+
 program
   .version(require("../package.json").version)
   .arguments("[inputPath]")
@@ -40,6 +44,7 @@ program
           "adding custom pagedjs handlers. The option can be repeated.",
           collect, [])
   .option("--browserEndpoint <browserEndpoint>", "Use a remote Chrome server with browserWSEndpoint")
+  .option("--browserArgs <browserArgs>", "Launch Chrome with comma separated args", commaSeparatedList)
   .parse(process.argv);
 
 function collect(value, previous) {
@@ -117,6 +122,7 @@ if (typeof input === "string") {
     additionalScripts: program.additionalScript,
     browserEndpoint: program.browserEndpoint,
     timeout: program.timeout,
+    browserArgs: program.browserArgs
   };
 
   if (program.forceTransparentBackground) {
diff --git a/src/printer.js b/src/printer.js
index b880d4e..e3e690d 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -26,6 +26,7 @@ class Printer extends EventEmitter {
     this.allowedDomains = options.allowedDomains || [];
     this.ignoreHTTPSErrors = options.ignoreHTTPSErrors;
     this.browserWSEndpoint = options.browserEndpoint;
+    this.browserArgs = options.browserArgs;
     this.overrideDefaultBackgroundColor = options.overrideDefaultBackgroundColor;
     this.timeout = options.timeout;
 
@@ -43,6 +44,10 @@ class Printer extends EventEmitter {
       puppeteerOptions.args.push("--allow-file-access-from-files");
     }
 
+    if (this.browserArgs) {
+      puppeteerOptions.args.push(...this.browserArgs);
+    }
+
     if (this.browserWSEndpoint) {
       puppeteerOptions.browserWSEndpoint = this.browserWSEndpoint;
       this.browser = await puppeteer.connect(puppeteerOptions);
-- 
GitLab