Skip to content

Commit aee0102

Browse files
committed
Support Modern Remote Chrome
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.
1 parent e249ed4 commit aee0102

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

library/Pdfexport/HeadlessChrome.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,20 @@ public function getVersion()
755755
protected function jsonVersion($host, $port)
756756
{
757757
$client = new \GuzzleHttp\Client();
758-
$response = $client->request('GET', sprintf('http://%s:%s/json/version', $host, $port));
758+
759+
try {
760+
$response = $client->request('GET', sprintf('http://%s:%s/json/version', $host, $port));
761+
} catch (\GuzzleHttp\Exception\ServerException $e) {
762+
// Check if we've run into the host header security change, and re-run the request with no host header.
763+
// ref: https://issues.chromium.org/issues/40090537
764+
if (strstr($e->getMessage(), 'Host header is specified and is not an IP address or localhost.')) {
765+
$response = $client->request(
766+
'GET', sprintf('http://%s:%s/json/version', $host, $port),
767+
['headers' => ['Host' => null]]);
768+
} else {
769+
throw $e;
770+
}
771+
}
759772

760773
if ($response->getStatusCode() !== 200) {
761774
return false;

0 commit comments

Comments
 (0)