Skip to content

Commit

Permalink
use puppeteer-core with chrome-launcher instead of puppeteer (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
andriyor authored and Nikolay Govorov committed Dec 3, 2019
1 parent 5ea176c commit dc44400
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 36 deletions.
10 changes: 8 additions & 2 deletions core/command/pdf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const chalk = require('chalk')
const puppeteer = require('puppeteer')
const puppeteer = require('puppeteer-core')
const { getPlatform } = require('chrome-launcher/dist/utils.js')
const chromeFinder = require('chrome-launcher/dist/chrome-finder.js')

function evalCalcExpression (value) {
const expression = value
Expand All @@ -11,7 +13,11 @@ function evalCalcExpression (value) {
}

async function handler ({ cwd, output }) {
let browser = await puppeteer.launch()
const executablePath = process.env.PUPPETEER_EXECUTABLE_PATH || (await (chromeFinder)[getPlatform()]())[0]
if (!executablePath) {
throw new Error('Chrome / Chromium is not installed or environment variable PUPPETEER_EXECUTABLE_PATH is not set')
}
let browser = await puppeteer.launch({ executablePath })
let page = await browser.newPage()

await page.goto(`file://${cwd}/index.html`)
Expand Down
133 changes: 100 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"dependencies": {
"browser-sync": "^2.26.5",
"chalk": "^2.4.2",
"chrome-launcher": "^0.12.0",
"del": "^3.0.0",
"execa": "^1.0.0",
"gh-pages": "^2.0.1",
Expand All @@ -56,7 +57,7 @@
"inquirer": "^6.3.1",
"listr": "^0.14.3",
"merge-stream": "^1.0.1",
"puppeteer": "^1.15.0",
"puppeteer-core": "^2.0.0",
"semver": "^5.7.0",
"tmp": "0.0.33",
"update-notifier": "^2.5.0",
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Options:

**`$ shower pdf` - Converts the presentation to PDF**

The browser that [implements the Chrome Debugging Protocol](https://github.com/cyrus-and/chrome-remote-interface/#implementations) is required.
If you installed Chrome / Chromium to the custom path or use another browser, set PUPPETEER_EXECUTABLE_PATH environment variable.

```
Options:
--output, -o File name [string] [default: "index.pdf"]
Expand Down

0 comments on commit dc44400

Please sign in to comment.