From 54e23f0197ff182cb586bcf4cd33cff4727a937f Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Thu, 20 May 2021 12:29:52 +0200 Subject: [PATCH] Allows disabling the sandbox mode. --- .../lib/web-crawler/index.js | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/ckeditor5-dev-docs/lib/web-crawler/index.js b/packages/ckeditor5-dev-docs/lib/web-crawler/index.js index 353433a09..3f0d5819f 100644 --- a/packages/ckeditor5-dev-docs/lib/web-crawler/index.js +++ b/packages/ckeditor5-dev-docs/lib/web-crawler/index.js @@ -36,16 +36,17 @@ const { * @param {Array.} options.exclusions An array of patterns to exclude links. Empty array by default to not exclude anything. * @param {Number} options.concurrency Number of concurrent pages (browser tabs) to be used during crawling. One by default. * @param {Boolean} options.quit Terminates the scan as soon as an error is found. False (off) by default. + * @param {Boolean} [options.disableBrowserSandbox] Whether the browser should be created with the `--no-sandbox` flag. * @returns {Promise} Promise is resolved, when the crawler has finished the whole crawling procedure. */ -module.exports = async function verify( { url, depth, exclusions, concurrency, quit } ) { +module.exports = async function verify( options ) { + const { url, depth, exclusions, concurrency, quit, disableBrowserSandbox } = options; + console.log( chalk.bold( '\n🔎 Starting the Crawler\n' ) ); const spinner = createSpinner(); - const errors = new Map(); - - const browser = await createBrowser(); + const browser = await createBrowser( { disableBrowserSandbox } ); spinner.start( 'Checking pages…' ); @@ -83,10 +84,22 @@ module.exports = async function verify( { url, depth, exclusions, concurrency, q /** * Creates a new browser instance and closes the default blank page. * + * @param {Object} options + * @param {Boolean} [options.disableBrowserSandbox] Whether the browser should be created with the `--no-sandbox` flag. + * * @returns {Promise.} A promise, which resolves to the Puppeteer browser instance. */ -async function createBrowser() { - const browser = await puppeteer.launch(); +async function createBrowser( options ) { + const browserOptions = { + args: [] + }; + + if ( options.disableBrowserSandbox ) { + browserOptions.args.push( '--no-sandbox' ); + browserOptions.args.push( '--disable-setuid-sandbox' ); + } + + const browser = await puppeteer.launch( browserOptions ); const [ defaultBlankPage ] = await browser.pages();