From a1894caf272b7906062fe2d908aceff65e3275c5 Mon Sep 17 00:00:00 2001 From: Soufiane Ghzal Date: Tue, 2 Oct 2018 11:31:38 +0200 Subject: [PATCH] add option customFlags --- CHANGELOG.md | 1 + README.md | 29 +++++++++++++++-------------- src/Browser/BrowserProcess.php | 5 +++++ src/BrowserFactory.php | 1 + 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccfbe781..b7138415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ * Added option ``"nosandbox"`` for browser factory * Added option ``"sendSyncDefaultTimeout"`` for browser factory * Added option ``"ignoreCertificateErrors"`` for browser factory + * Added option ``"customFlags"`` for browser factory * Bug fixes: * Fixed user agent string for browser factory diff --git a/README.md b/README.md index c190dfeb..51234729 100644 --- a/README.md +++ b/README.md @@ -127,20 +127,21 @@ API Here are the options available for the browser factory: -| Option name | Default | Description | -|--------------------|-----------------------|-----------------------------------------------------------------------------------| -| connectionDelay | 0 | Delay to apply between each operation for debugging purposes | -| debug | false | Allows to enable debug mode | -| debugLogger | null | A string (e.g "php://stdout"), or resource, or PSR-3 logger instance to print debug messages | -| enableImages | true | Toggles loading of images | -| headless | true | Enable or disable headless mode | -| ignoreCertificateErrors | false | Set chrome to ignore ssl errors | -| noSandbox | false | Useful to run in a docker container | -| sendSyncDefaultTimeout | 3000 | Default timeout (ms) for sending sync messages | -| startupTimeout | 30 | Maximum time in seconds to wait for chrome to start | -| userAgent | none | User agent to use for the whole browser (see page api for alternative) | -| userDataDir | none | chrome user data dir (default: a new empty dir is generated temporarily) | -| windowSize | none | Size of the window. usage: ``[$width, $height]`` - see also Page::setViewportSize | +| Option name | Default | Description | +|--------------------|---------------|--------------------------------------------------------------------------------------------------| +| connectionDelay | 0 | Delay to apply between each operation for debugging purposes | +| customFlags | none | Array of flags to pass to the command line. Eg: ``['--option1', '--option2=someValue']`` | +| debug | false | Allows to enable debug mode | +| debugLogger | null | A string (e.g "php://stdout"), or resource, or PSR-3 logger instance to print debug messages | +| enableImages | true | Toggles loading of images | +| headless | true | Enable or disable headless mode | +| ignoreCertificateErrors | false | Set chrome to ignore ssl errors | +| noSandbox | false | Useful to run in a docker container | +| sendSyncDefaultTimeout | 3000 | Default timeout (ms) for sending sync messages | +| startupTimeout | 30 | Maximum time in seconds to wait for chrome to start | +| userAgent | none | User agent to use for the whole browser (see page api for alternative) | +| userDataDir | none | chrome user data dir (default: a new empty dir is generated temporarily) | +| windowSize | none | Size of the window. usage: ``[$width, $height]`` - see also Page::setViewportSize | ### Browser API diff --git a/src/Browser/BrowserProcess.php b/src/Browser/BrowserProcess.php index 646fec96..fdbc2949 100644 --- a/src/Browser/BrowserProcess.php +++ b/src/Browser/BrowserProcess.php @@ -333,6 +333,11 @@ private function getArgsFromOptions(array $options) $args[] = '--ignore-certificate-errors'; } + // add custom flags + if (array_key_exists('customFlags', $options) && is_array($options['customFlags'])) { + $args = array_merge($args, $options['customFlags']); + } + // add user data dir to args $args[] = '--user-data-dir=' . $options['userDataDir']; diff --git a/src/BrowserFactory.php b/src/BrowserFactory.php index eb5d328b..cf6fa526 100644 --- a/src/BrowserFactory.php +++ b/src/BrowserFactory.php @@ -35,6 +35,7 @@ public function __construct(string $chromeBinaries = null) * * @param array $options options for browser creation: * - connectionDelay: amount of time in seconds to slows down connection for debugging purposes (default: none) + * - customFlags: array of custom flag to flags to pass to the command line * - debug: toggles the debug mode that allows to print additional details (default: false) * - debugLogger: resource string ("php://stdout"), resource or psr-3 logger instance (default: none) * enabling debug logger will also enable debug mode.