Skip to content

Commit c85de46

Browse files
authored
Support Modern Remote Chrome (#71)
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.
1 parent af12566 commit c85de46

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

library/Pdfexport/HeadlessChrome.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,22 @@ 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',
767+
sprintf('http://%s:%s/json/version', $host, $port),
768+
['headers' => ['Host' => null]]
769+
);
770+
} else {
771+
throw $e;
772+
}
773+
}
759774

760775
if ($response->getStatusCode() !== 200) {
761776
return false;

0 commit comments

Comments
 (0)