diff --git a/.travis.yml b/.travis.yml
index be61212..ea05031 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,6 +4,7 @@ node_js:
addons:
chrome: stable
before_install:
+ - export CHROME_PATH="$(pwd)/chrome-linux/chrome"
- google-chrome-stable --no-sandbox --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
- |
until nc -z -v -w30 127.0.0.1 9222
diff --git a/README.md b/README.md
index 383ac44..68071ba 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ This is done with a `POST` request the the web server. We'll use some example HT
```sh
curl -X POST -H 'Authorization: Bearer PRIVATE_TOKEN_DEFINED_IN_SERVER_ENVIRONMENT' \
http://url-of-your-breezy-pdf-lite-server/render/html \
- -d '`curl https://raw.githubusercontent.com/danielwestendorf/breezy-pdf-lite/master/sample.html`' \
+ -d "`curl https://raw.githubusercontent.com/danielwestendorf/breezy-pdf-light/master/sample.html`" \
-o example.pdf
```
diff --git a/index.js b/index.js
index 675f9c5..69b684b 100644
--- a/index.js
+++ b/index.js
@@ -1,4 +1,28 @@
-const Server = require('./lib/server')
+const { spawn } = require('child_process')
+const Server = require('./lib/server')
+
+if (process.env.GOOGLE_CHROME_SHIM !== undefined) {
+ console.log('Starting Google Chrome')
+ const chrome = spawn(
+ process.env.GOOGLE_CHROME_SHIM,
+ [
+ '--disable-extensions',
+ '--disable-background-networking',
+ '--safebrowsing-disable-auto-update',
+ '--disable-sync',
+ '--metrics-recording-only',
+ '--disable-default-apps',
+ '--no-first-run',
+ '--mute-audio',
+ '--hide-scrollbars'
+ ]
+ )
+
+ chrome.on('close', async (code) => {
+ console.error(`Chrome process closed with code ${code}`);
+ process.exit(code);
+ });
+}
console.log('Starting web server...')
diff --git a/lib/render.js b/lib/render.js
index 0e247ab..c98ff4c 100644
--- a/lib/render.js
+++ b/lib/render.js
@@ -7,16 +7,9 @@ const CompletionTrigger = require('./pdf/completion-trigger')
module.exports = class Render {
constructor(htmlString, options) {
this.htmlString = htmlString
- this.options = options || {
- host: 'localhost',
- port: 9222
- }
-
- this.log = debug(this.options.log || 'breezy-pdf-lite:pdf')
+ this.options = options || {}
- if (process.env.GOOGLE_CHROME_SHIM !== undefined) {
- process.env.CHROME_PATH = process.env.GOOGLE_CHROME_SHIM
- }
+ this.log = debug(this.options.log || 'breezy-pdf-lite:pdf')
}
toPdf() {
@@ -25,6 +18,11 @@ module.exports = class Render {
printOptions: this.printOptions()
}
+ if (process.env.GOOGLE_CHROME_SHIM !== undefined) {
+ renderOptions.host = 'localhost'
+ renderOptions.port = 9222
+ }
+
this.log(`Generating PDF for HTML string with options: ${JSON.stringify(renderOptions)}`)
return htmlPdf.create(this.htmlString, renderOptions)
diff --git a/sample.html b/sample.html
index 3151bcd..869db57 100644
--- a/sample.html
+++ b/sample.html
@@ -6,7 +6,7 @@
-
+