From 6289364ff4b7e927b255ed0cd0f83ab43066e30e Mon Sep 17 00:00:00 2001
From: Nick Budak <nbudak@princeton.edu>
Date: Wed, 28 Oct 2020 15:39:30 -0400
Subject: [PATCH] Implement --timeout option

Passes the -t/--timeout option from the command line to the
printer, and uses it to set the timeout when puppeteer is
loading pages.

See #28, #37
---
 bin/paged      | 1 +
 src/printer.js | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/bin/paged b/bin/paged
index cd81407..f72ad8d 100755
--- a/bin/paged
+++ b/bin/paged
@@ -115,6 +115,7 @@ if (typeof input === "string") {
     allowedPaths: program.allowedPaths,
     allowedDomains: program.allowedDomains,
     additionalScripts: program.additionalScript,
+    timeout: program.timeout,
   };
 
   if (program.forceTransparentBackground) {
diff --git a/src/printer.js b/src/printer.js
index 0036ff1..948e478 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -26,6 +26,7 @@ class Printer extends EventEmitter {
     this.ignoreHTTPSErrors = options.ignoreHTTPSErrors;
     this.browserWSEndpoint = options.browserEndpoint;
     this.overrideDefaultBackgroundColor = options.overrideDefaultBackgroundColor;
+    this.timeout = options.timeout;
 
     this.pages = [];
   }
@@ -63,6 +64,9 @@ class Printer extends EventEmitter {
     }
 
     const page = await this.browser.newPage();
+    if (this.timeout) {
+      page.setDefaultTimeout(this.timeout);
+    }
 
     if (this.overrideDefaultBackgroundColor) {
       page._client.send('Emulation.setDefaultBackgroundColorOverride', { color: this.overrideDefaultBackgroundColor });
-- 
GitLab