Detecting headless mode not working correctly for (new) headless chromium 133 (when using printToPdf)
Related to #138 but registering it's own issue in order to supply a merge request
How to reproduce:
- Use Chromium 133 and chrome-mink-driver 2.9.3
- in my case it's
Chromium 133.0.6943.98 built on Debian GNU/Linux 12 (bookworm)
- in my case it's
- Start chromium in using the "new" headless mode (
--headless) - Run a behat test with a step that uses
printToPDF()(which is only allowed in headless mode)
Expected behaviour
-
printToPdf()is able to execute and print the current page
Actual behaviour
-
printToPdf()throws the exception:Page.printToPDF is only available in headless mode.
Notes:
Based on the error and some debugging I found that chrome-mink-driver is not detecting correctly that chromium is running in headless mode, and as a result it's blocking the use of printToPdf in this example.
From debugging, I found that $versionInfo (which is used to detect headless mode) contains different values than expected by the detection mechanism. In my case it holds:
object(stdClass)#3296 (6) {
["Browser"]=>
string(20) "Chrome/133.0.6943.98"
["Protocol-Version"]=>
string(3) "1.3"
["User-Agent"]=>
string(109) "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/133.0.0.0 Safari/537.36"
["V8-Version"]=>
string(11) "13.3.415.21"
["WebKit-Version"]=>
string(50) "537.36 (@da53563ceb66412e2637507c8724bd0cab05e453)"
["webSocketDebuggerUrl"]=>
string(75) "ws://172.18.0.19:9223/devtools/browser/0725ac4a-9dee-47f9-b2df-f74e32356898"
}
(where the "Headless" information is part of User-Agent, while the detection mechanism is currently looking in the Browser field:
// Detect if Chrome has been started in Headless Mode
if (property_exists($versionInfo, 'Browser') && strpos($versionInfo->Browser, 'Headless') === false) {
$this->headless = false;
}
Also, previously I was using --headless=old which was a different headless implementation, and that did work correctly. However, this old implementation is now no longer supported by chromium.