Skip to content

Commit

Permalink
fix(core): fix Puppeteer launching issue on Linux
Browse files Browse the repository at this point in the history
Chrome Headless fails to launch on some platforms due to sandbox issues.
See also https://github.com/GoogleChrome/puppeteer/blob/v1.0.0/docs/troubleshooting.md#chrome-headless-fails-due-to-sandbox-issues

We now launch Puppeteer with the `--no-sandbox` arg on any platform which
is not `win32` or `darwin`.
  • Loading branch information
rdeltour committed Jan 18, 2018
1 parent 942a8f2 commit bd95b20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/ace-core/src/checker/checker-chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs');
const path = require('path');
const pMap = require('p-map');
const puppeteer = require('puppeteer');
const os = require('os');
const winston = require('winston');

const axe2ace = require('@daisy/ace-report-axe');
Expand Down Expand Up @@ -80,7 +81,11 @@ async function checkSingle(spineItem, epub, browser) {
}

module.exports.check = async (epub) => {
const browser = await puppeteer.launch();
const args = [];
if (os.platform() !== 'win32' && os.platform() !== 'darwin') {
args.push('--no-sandbox')
}
const browser = await puppeteer.launch({ args });
winston.info('Checking documents...');
return pMap(epub.contentDocs, doc => checkSingle(doc, epub, browser), { concurrency: 4 })
.then(async (results) => {
Expand Down
7 changes: 6 additions & 1 deletion packages/jest-env-puppeteer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

const NodeEnvironment = require('jest-environment-node');
const puppeteer = require('puppeteer');
const os = require('os');

class HeadlessChromeEnvironment extends NodeEnvironment {

setup() {
const args = [];
if (os.platform() !== 'win32' && os.platform() !== 'darwin') {
args.push('--no-sandbox')
}
return super.setup().then(() =>
puppeteer.launch().then((browser) => {
puppeteer.launch({ args }).then((browser) => {
this.global.browser = browser;
}));
}
Expand Down

0 comments on commit bd95b20

Please sign in to comment.