From d4c78c5ba8d3993a75362ce2429172369331e772 Mon Sep 17 00:00:00 2001 From: divinity76 Date: Tue, 29 Jul 2025 09:32:47 +0200 Subject: [PATCH 1/3] add json error message while looking into https://github.com/chrome-php/chrome/issues/666 i got > PHP Fatal error: Uncaught HeadlessChromium\Exception\CommunicationException\CannotReadResponse: Response from chrome remote interface is not a valid json response. JSON error: 10 in /home/hans/projects/misc/vendor/chrome-php/chrome/src/Communication/Connection.php:382 --- src/Communication/Connection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Communication/Connection.php b/src/Communication/Connection.php index de97c87..e4a654d 100644 --- a/src/Communication/Connection.php +++ b/src/Communication/Connection.php @@ -376,10 +376,10 @@ private function dispatchMessage(string $message, ?Session $session = null) $response = \json_decode($message, true); // if json not valid throw exception - $jsonError = \json_last_error(); - if (\JSON_ERROR_NONE !== $jsonError) { + $jsonErrorId = \json_last_error(); + if (\JSON_ERROR_NONE !== $jsonErrorId) { if ($this->isStrict()) { - throw new CannotReadResponse(\sprintf('Response from chrome remote interface is not a valid json response. JSON error: %s', $jsonError)); + throw new CannotReadResponse(\sprintf('Response from chrome remote interface is not a valid json response. JSON error: %d: %s', $jsonErrorId, json_last_error_msg()); } return false; From 80a4dd1ad25d15e2bf800ff241eda90e90289b67 Mon Sep 17 00:00:00 2001 From: divinity76 Date: Tue, 29 Jul 2025 09:35:09 +0200 Subject: [PATCH 2/3] oops --- src/Communication/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Communication/Connection.php b/src/Communication/Connection.php index e4a654d..4216472 100644 --- a/src/Communication/Connection.php +++ b/src/Communication/Connection.php @@ -379,7 +379,7 @@ private function dispatchMessage(string $message, ?Session $session = null) $jsonErrorId = \json_last_error(); if (\JSON_ERROR_NONE !== $jsonErrorId) { if ($this->isStrict()) { - throw new CannotReadResponse(\sprintf('Response from chrome remote interface is not a valid json response. JSON error: %d: %s', $jsonErrorId, json_last_error_msg()); + throw new CannotReadResponse(\sprintf('Response from chrome remote interface is not a valid json response. JSON error: %d: %s', $jsonErrorId, json_last_error_msg())); } return false; From 3ee76b1d6885ae96391ce1e30c8233552e1c0577 Mon Sep 17 00:00:00 2001 From: divinity76 Date: Tue, 29 Jul 2025 09:37:17 +0200 Subject: [PATCH 3/3] StyleCI --- src/Communication/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Communication/Connection.php b/src/Communication/Connection.php index 4216472..d7bc727 100644 --- a/src/Communication/Connection.php +++ b/src/Communication/Connection.php @@ -379,7 +379,7 @@ private function dispatchMessage(string $message, ?Session $session = null) $jsonErrorId = \json_last_error(); if (\JSON_ERROR_NONE !== $jsonErrorId) { if ($this->isStrict()) { - throw new CannotReadResponse(\sprintf('Response from chrome remote interface is not a valid json response. JSON error: %d: %s', $jsonErrorId, json_last_error_msg())); + throw new CannotReadResponse(\sprintf('Response from chrome remote interface is not a valid json response. JSON error: %d: %s', $jsonErrorId, \json_last_error_msg())); } return false;