Closed jeffreymoelands closed 3 months ago
Presistent browser should work even if the uri points to another host.
Presistent browser should work even if the uri points to another host.
Thx for your answer, probably I don't understand but even when I create a Persistent Browser I get the next error:
Unknown socket scheme: http
For example the url to the other host is: http://127.0.0.1:30000
You need to use the chrome DevTools uri. It's a websocket address that starts with ws://
. The chrome process gives you that uri in the output when starting with the flag --remote-debugging-port=0
I found how to make it work:
$client = new Client(['base_uri' => 'http://127.0.0.1:30000']);
$response = $client->put('/json/new');
$body = $response->getBody()->getContents();
$data = json_decode($body, true);
$webSocketDebuggerUrl = $data['webSocketDebuggerUrl'];
$browser = \HeadlessChromium\BrowserFactory::connectToBrowser($webSocketDebuggerUrl, $options);
Thx for your help!
Hi @jeffreymoelands!
I'm experiencing the same Unknown socket scheme: http
issue you reported in your previous comment. My hosting provider doesn't allow the ws://
scheme endpoint.
Could you please expand a bit further how you construct the Client
object?
Your code sample doesn't seem to match the definition for the Wrench\Client class constructor used by this project (which expects a string URI as an argument, and not array).
Also, the Client
class doesn't implement a put
method.
Thanks in advance!
Could you please expand a bit further how you construct the Client object?
After examining the code closer, I was able to figure out you are using a Guzzle client, I was sidetracked by the class of the same name in chrome-php/wrench project.
In case someone else bumps into the same issue, this is an expanded example of how to make the solution work:
$client = new \GuzzleHttp\Client(['base_uri' => $uri]);
// It may be needed to include the Host header with the IP and port of the chrome service:
$request_options = [
'headers' => [
'Host' => "{$YOUR_IP}:{$YOUR_PORT}"
],
];
$response = $client->put('/json/new', $request_options);
$body = $response->getBody()->getContents();
$data = json_decode($body, true);
$webSocketDebuggerUrl = $data['webSocketDebuggerUrl'];
$browser = \HeadlessChromium\BrowserFactory::connectToBrowser($webSocketDebuggerUrl, $options);
@bmunslow you are right, I used the Guzzle Client to get the webSocketDebuggerUrl
. Sorry for my late response, I hadn't seen your comment yet.
On our hosting enviroment we can spinup a Headless Chrome container. We get a url to connect with this container, is there a way we can use this library?
For example with de node package
puppeteer
you can connect with a browser url: