chrome-php / chrome

Instrument headless chrome/chromium instances from PHP
MIT License
2.28k stars 278 forks source link

Malformed UTF-8 characters, possibly correctly encoded -> Hard time finding the root of this error? #533

Open rodolforjunior opened 1 year ago

rodolforjunior commented 1 year ago

Hello. I'm building a Laravel project trying to capture screenshots and create PDF of specific parts of my app. I've tried running different libraries like Browsershot and Snappy, but the error of malformed characters persist on all of them. It could be a problem with specific characters of the pages I'm trying to screen, however testing on public url's like google returns the same response error.

Is there anyone else who at least had or managed to resolve this issue? I tried running a new project only to test the libraries and the problem persists. Another coworker of mine tried running the project and libraries on his machine and had different, but very confusing and unclear errors.

Below is a sample:

    $browserFactory = new BrowserFactory(); //A DD statement here returns the right path of my chrome browser.
    $browser = $browserFactory->createBrowser(); //The error occurs here. I've tried specifying paths like 'chrome-selenium' and the situation keeps occurring.

The error in question:

{ "message": "Malformed UTF-8 characters, possibly incorrectly encoded", "exception": "InvalidArgumentException", "file": "path\vendor\laravel\framework\src\Illuminate\Http\JsonResponse.php", "line": 91, "trace": [ { "file": "path\vendor\symfony\http-foundation\JsonResponse.php", "line": 51, "function": "setData", "class": "Illuminate\Http\JsonResponse", "type": "->" }, }

enricodias commented 1 year ago

So, the error is in your project and not in the library?

rodolforjunior commented 1 year ago

So, the error is in your project and not in the library?

It definitely must be.

I'm asking since the results I've found on forums and other related sources are mostly vague.

Any clues what this might be related?

enricodias commented 1 year ago

It's a bad character in a json. Dump the data used to generate the json or check it using a debugger in real time.

divinity76 commented 11 months ago

... so you're telling me that this line:

$browser = $browserFactory->createBrowser(); 

causes

(...)
 "file": "path\vendor\symfony\http-foundation\JsonResponse.php",
"line": 51,
"function": "setData",
"class": "Illuminate\Http\JsonResponse",
"type": "->"

? I find that hard to believe, but can you make a small reproducible script?

Does this script reproduce the crash for you?

<?php
require_once __DIR__ . "/vendor/autoload.php";
$browserFactory = new \HeadlessChromium\BrowserFactory();
$browser = $browserFactory->createBrowser();
die("end of script");
stale[bot] commented 6 months ago

This issue has been automatically marked as stale because there has been no recent activity. It will be closed after 30 days if no further activity occurs. Thank you for your contributions.