Skip to content

Commit

Permalink
Support Modern Remote Chrome
Browse files Browse the repository at this point in the history
Starting in version 66, Chrome DevTools requires the host header to be “localhost” or an IP address. Work around this by re-running the request without a host header if we get the security error.
  • Loading branch information
srvrguy committed Nov 21, 2024
1 parent e249ed4 commit aee0102
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion library/Pdfexport/HeadlessChrome.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,20 @@ public function getVersion()
protected function jsonVersion($host, $port)
{
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', sprintf('http://%s:%s/json/version', $host, $port));

try {
$response = $client->request('GET', sprintf('http://%s:%s/json/version', $host, $port));
} catch (\GuzzleHttp\Exception\ServerException $e) {
// Check if we've run into the host header security change, and re-run the request with no host header.
// ref: https://issues.chromium.org/issues/40090537
if (strstr($e->getMessage(), 'Host header is specified and is not an IP address or localhost.')) {
$response = $client->request(
'GET', sprintf('http://%s:%s/json/version', $host, $port),
['headers' => ['Host' => null]]);
} else {
throw $e;
}
}

if ($response->getStatusCode() !== 200) {
return false;
Expand Down

0 comments on commit aee0102

Please sign in to comment.