Permalink
Browse files

Adds option for customizing the chromium executable used by puppeteer (

  • Loading branch information...
matthiasharrer authored and webpro committed Oct 15, 2018
1 parent 357406d commit 4242a4857c8db3089447136326fe46d73127773e
Showing with 25 additions and 4 deletions.
  1. +8 −1 bin/cli.js
  2. +1 −1 lib/featured-slide.js
  3. +15 −1 lib/options.js
  4. +1 −1 lib/print.js
@@ -43,7 +43,14 @@ program
' --absolute-url <url>',
'Define url used for hosting static build. This is included in OpenGraph metadata. Only used with --static.'
)
.option(' --puppeteer-launch-args <args>', 'Customize how Puppeteer launches Chromium. Needed for some CI setups.')
.option(
' --puppeteer-launch-args <args>',
'Customize how Puppeteer launches Chromium. The arguments are specified as a space separated list (for example "--no-sandbox --disable-dev-shm-usage"). Needed for some CI setups.'
)
.option(
' --puppeteer-chromium-executable <path>',
'Customize which Chromium executable puppeteer will launch. Allows to use a globally installed version of Chromium.'
)
.parse(process.argv);

if (program.args.length > 2) {
@@ -46,7 +46,7 @@ module.exports = function snapshot(options) {
const url = `http://${options.host}:${options.port}/${initialPath}${getSlideAnchor()}`;

return puppeteer
.launch(options.puppeteerLaunchArgs ? { args: options.puppeteerLaunchArgs.split(' ') } : {})
.launch(options.puppeteerLaunchConfig)
.then(browser =>
browser
.newPage()
@@ -30,7 +30,8 @@ const optionList = [
'noPhantom',
'featuredSlide',
'absoluteUrl',
'puppeteerLaunchArgs'
'puppeteerLaunchArgs',
'puppeteerChromiumExecutable'
];

const getAssetPath = (asset, assetsDir = getOptions().assetsDir) => `${assetsDir}/${asset}`;
@@ -75,6 +76,7 @@ defaults.revealOptionsStr = () => JSON.stringify(revealOptions);
defaults.themeUrl = 'css/theme/' + defaults.theme + '.css';
defaults.highlightThemeUrl = '/css/highlight/' + defaults.highlightTheme + '.css';
defaults.preprocessorFn = markdown => Promise.resolve(markdown);
defaults.puppeteerLaunchConfig = {};

const revealThemes = glob.sync('css/theme/*.css', { cwd: defaults.revealBasePath });

@@ -141,6 +143,18 @@ function parseOptions(options) {
options.cssPaths = getAssetPaths(options.css, options.assetsDir);
options.cssSources = getAssetSourcePaths(options.css);
}
if (options.puppeteerLaunchArgs) {
options.puppeteerLaunchConfig = {
...options.puppeteerLaunchConfig,
args: options.puppeteerLaunchArgs.split(' ')
};
}
if (options.puppeteerChromiumExecutable) {
options.puppeteerLaunchConfig = {
...options.puppeteerLaunchConfig,
executablePath: options.puppeteerChromiumExecutable
};
}
return options;
}

@@ -33,7 +33,7 @@ module.exports = function print(options) {
console.log(`Attempting to print "${initialPath}?print-pdf" to filename "${pdfFilename}.pdf" as PDF.`);

return puppeteer
.launch(options.puppeteerLaunchArgs ? { args: options.puppeteerLaunchArgs.split(' ') } : {})
.launch(options.puppeteerLaunchConfig)
.then(browser =>
browser.newPage().then(page => {
return page.goto(`${url}?print-pdf`, { waitUntil: 'load' }).then(() => {

0 comments on commit 4242a48

Please sign in to comment.