Skip to content

Commit 98bb9e2

Browse files
Add CHROME_NO_SANDBOX env var
1 parent c119b1c commit 98bb9e2

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@ jobs:
9696
run: vendor/bin/phpunit
9797
env:
9898
CHROME_PATH: /opt/hostedtoolcache/setup-chrome/chromium/122.0.6261.128/x64/chrome
99+
CHROME_NO_SANDBOX: true

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* Add PHP 8.5 support
77
* Add support for using Symfony 8 components
88
* Remove support for Symfony 4 components
9+
* Merge options with defaults in factory
10+
* Add `CHROME_NO_SANDBOX` env var
911

1012

1113
## 1.14.0 (2025-05-28)

src/AutoDiscover.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,21 @@ private static function shellExec(string $command): ?string
6969
return null;
7070
}
7171
}
72+
73+
/**
74+
* Get default browser options from environment variables.
75+
*
76+
* @return array<string, mixed>
77+
*/
78+
public function getDefaultOptions(): array
79+
{
80+
$options = [];
81+
82+
if (\array_key_exists('CHROME_NO_SANDBOX', $_SERVER)
83+
&& \filter_var($_SERVER['CHROME_NO_SANDBOX'], \FILTER_VALIDATE_BOOLEAN)) {
84+
$options['noSandbox'] = true;
85+
}
86+
87+
return $options;
88+
}
7289
}

src/BrowserFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class BrowserFactory
5252

5353
public function __construct(?string $chromeBinary = null)
5454
{
55-
$this->chromeBinary = $chromeBinary ?? (new AutoDiscover())->guessChromeBinaryPath();
55+
$autoDiscover = new AutoDiscover();
56+
$this->chromeBinary = $chromeBinary ?? $autoDiscover->guessChromeBinaryPath();
57+
$this->options = \array_merge($this->options, $autoDiscover->getDefaultOptions());
5658
}
5759

5860
/**
@@ -66,7 +68,7 @@ public function __construct(?string $chromeBinary = null)
6668
*/
6769
public function createBrowser(?array $options = null): ProcessAwareBrowser
6870
{
69-
$options ??= $this->options;
71+
$options = \array_merge($this->options, $options ?? []);
7072

7173
// create logger from options
7274
$logger = self::createLogger($options);

0 commit comments

Comments
 (0)