diff --git a/src/Communication/Connection.php b/src/Communication/Connection.php index de97c87..d307e8e 100644 --- a/src/Communication/Connection.php +++ b/src/Communication/Connection.php @@ -372,14 +372,11 @@ public function processAllEvents(): void */ private function dispatchMessage(string $message, ?Session $session = null) { - // responses come as json string - $response = \json_decode($message, true); - - // if json not valid throw exception - $jsonError = \json_last_error(); - if (\JSON_ERROR_NONE !== $jsonError) { + try { + $response = \json_decode($message, true, 512, \JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { 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('Response from chrome remote interface is not a valid JSON response', 0, $e); } return false;