Skip to content

Commit

Permalink
Support Modern Remote Chrome (#71)
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 setting the header to
“lcoalhost” when fetching the version endpoint.
  • Loading branch information
srvrguy authored Nov 27, 2024
1 parent af12566 commit c85de46
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion library/Pdfexport/HeadlessChrome.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,22 @@ 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 c85de46

Please sign in to comment.