I’ve been using HeadlessChromium in my PHP project on Ubuntu Server 23.10. Until recently, this worked to set up a new browser:
$browserFactory = new HeadlessChromiumBrowserFactory();
$browser = $browserFactory->createBrowser
(
[
'windowSize' => [1024, 768],
'debugLogger' => 'php://stderr',
]
);
Today I upgraded Chrome to version 128.0.6613.84
The above code started giving this error:
PHP message: RuntimeException: Chrome process stopped before startup completed. Additional info: mkdir: cannot create directory ‘/var/www/.local’: Permission denied
So I created /var/www/.local and set its owner to www-data. Now I get this error:
PHP message: RuntimeException: Chrome process stopped before startup completed. Additional info: chrome_crashpad_handler: –database is required
I’ve tried adding a few more options to no avail:
$browser = $browserFactory->createBrowser
(
[
'windowSize' => [1024, 768],
'debugLogger' => 'php://stderr',
'args' =>
[
'--no-crashpad',
'--disable-dev-shm-usage',
'--disable-gpu',
'--headless',
'--disable-software-rasterizer',
'--no-sandbox',
],
]
);
As far a I can tell the ‘args’ array has no effect.
2
Answers
The problem, as identified by @MartinZeitler is that there are directories missing from the www-data home directory. This solved the problem on my server (Ubuntu 23.10):
In my case, the www-data home directory is /var/www
Mine issue was fixed by adding environment variables
XDG_CONFIG_HOME
andXDG_CACHE_HOME
: