Skip to content

Commit

Permalink
Support passing additional arguments to Chrome from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Oct 19, 2018
1 parent 9fbf68b commit 6b46a95
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ USER node
# https://github.com/jessfraz/dockerfiles/issues/65
# https://github.com/jessfraz/dockerfiles/issues/156
# https://github.com/jessfraz/dockerfiles/issues/341
ENTRYPOINT ["node", "/decktape/decktape.js", "--no-sandbox", "--executablePath", "chromium-browser"]
ENTRYPOINT ["node", "/decktape/decktape.js", "--chrome-path", "chromium-browser", "--chrome-arg=--no-sandbox"]

CMD ["-h"]
34 changes: 33 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ Options:
--screenshots-format <format> Screenshots image format, one of [jpg, png] [png]
--slides <range> Range of slides to be exported, a combination of slide indexes
and ranges (e.g. '1-3,5,8')
--chrome-path <path> Path to the Chromium or Chrome executable to run instead of the
bundled Chromium
--chrome-arg <arg> Additional argument to pass to the Chrome instance, can be repeated
Defaults to the automatic command.
Iterates over the available plugins, picks the compatible one for presentation at the
Expand Down Expand Up @@ -281,6 +284,8 @@ $ docker rm `docker ps -lq`

== FAQ

==== Install

* *_How to install prerequisites on Windows?_*
+
Open a Powershell prompt in _Run as administrator_ to install Visual Studio Build Tools and Python 2.7:
Expand All @@ -294,10 +299,37 @@ $ npm i -g --production windows-build-tools
+
Yes, it is available at https://aur.archlinux.org/packages/nodejs-decktape/.

* *_I'm getting an error: No usable sandbox!_*
==== Usage

* *_Is it possible to pass arguments to Chrome?_*
+
Yes, you can use the `--chrome-arg` option, e.g.:
+
[source,shell]
----
$ decktape ... \
--chrome-arg=--proxy-server="proxy:8080" \
--chrome-arg=--allow-file-access-from-files
----
+
The list of Chromium flags can be found https://peter.sh/experiments/chromium-command-line-switches/[here].

==== Errors

* *_No usable sandbox!_*
+
Arch Linux, among other Linux distributions may have the user namespace in the kernel disabled by default. You can verify this by accessing _chrome://sandbox_ in your chrom[e|ium] browser. You can find more about sandboxing, https://chromium.googlesource.com/chromium/src/+/master/docs/linux_sandboxing.md#User-namespaces-sandbox[here]. As a _temporary_ work-around, you can pass `--no-sandbox` as a CLI option.

* *_Failed to read the 'rules' property from 'CSSStyleSheet': Cannot access rules_*
+
Starting Chromium 64, accessing CSS rules in a stylesheet loaded from the local filesystem violates a CORS policy.
As some Decktape plugins tweak the CSS rules for better PDF printing, you need to allow access to local files by setting the `--allow-file-access-from-files` flag option, e.g.:
+
[source,shell]
----
$ decktape ... --chrome-arg=--allow-file-access-from-files
----

== Plugin API

{icon-edit}
41 changes: 15 additions & 26 deletions decktape.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ parser.script('decktape').options({
default : 'screenshots',
help : 'Screenshots output directory',
},
screenshotSize : {
screenshotSizes : {
full : 'screenshots-size',
metavar : '<size>',
type : 'string',
Expand All @@ -86,16 +86,18 @@ parser.script('decktape').options({
help : 'Range of slides to be exported, a combination of slide indexes and ranges (e.g. \'1-3,5,8\')',
},
// Chrome options
executablePath : {
full : '--executablePath',
chromePath : {
full : 'chrome-path',
metavar : '<path>',
hidden : true,
type : 'string',
help : 'Path to the Chromium or Chrome executable to run instead of the bundled Chromium',
},
noSandbox : {
full : '--no-sandbox',
hidden : true,
flag : true,
chromeArgs : {
full : 'chrome-arg',
metavar : '<arg>',
type : 'string',
list : true,
help : 'Additional argument to pass to the Chrome instance, can be repeated',
},
});

Expand Down Expand Up @@ -187,24 +189,11 @@ process.on('unhandledRejection', error => {
(async () => {

const browser = await puppeteer.launch({
headless : true,
headless : true,
// TODO: add a verbose option
// dumpio : true,
executablePath: options.executablePath,
args : Object.keys(options).reduce((args, option) => {
switch (option) {
case 'sandbox':
if (options.sandbox === false) args.push('--no-sandbox');
break;
}
return args;
},
[
'--disable-dev-shm-usage',
// Starting Chromium 64, accessing CSS rules in a stylesheet loaded from the local filesystem violates a CORS policy.
// Some Decktape plugins tweak the CSS rules for better PDF printing.
'--allow-file-access-from-files',
])
// dumpio : true,
executablePath : options.chromePath,
args : options.chromeArgs,
});
const page = await browser.newPage();
await page.emulateMedia('screen');
Expand Down Expand Up @@ -364,7 +353,7 @@ async function exportSlide(plugin, page, printer, context) {
context.exportedSlides++;

if (options.screenshots) {
for (let resolution of options.screenshotSize || [options.size]) {
for (let resolution of options.screenshotSizes || [options.size]) {
await page.setViewport(resolution);
// Delay page rendering to wait for the resize event to complete,
// e.g. for impress.js (may be needed to be configurable)
Expand Down

0 comments on commit 6b46a95

Please sign in to comment.