Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail on intialization #26

Open
pauloacosta opened this issue Sep 2, 2020 · 4 comments
Open

Fail on intialization #26

pauloacosta opened this issue Sep 2, 2020 · 4 comments

Comments

@pauloacosta
Copy link

pauloacosta commented Sep 2, 2020

Fatal error: Uncaught ChromeDevtoolsProtocol\Exception\RuntimeException: Executable [chrome] not found. in C:\xampp\htdocs\vendor\jakubkulhan\chrome-devtools-protocol\src\ChromeDevtoolsProtocol\Instance\Launcher.php:139 Stack trace: #0 C:\xampp\htdocs\index.php(17): ChromeDevtoolsProtocol\Instance\Launcher->launch(Object(ChromeDevtoolsProtocol\Context)) #1 {main} thrown in C:\xampp\htdocs\vendor\jakubkulhan\chrome-devtools-protocol\src\ChromeDevtoolsProtocol\Instance\Launcher.php on line 139 

Code:

`<?php

require "./vendor/autoload.php";

use ChromeDevtoolsProtocol\Context;
use ChromeDevtoolsProtocol\Instance\Launcher;
use ChromeDevtoolsProtocol\Model\Page\PrintToPDFRequest;
use ChromeDevtoolsProtocol\Model\Page\NavigateRequest;

@Unlink(DIR . '/test.pdf');

// context creates deadline for operations
$ctx = Context::withTimeout(Context::background(), 30 /* seconds */);

// launcher starts chrome process ($instance)
$launcher = new Launcher();
$instance = $launcher->launch($ctx);

try {
// work with new tab
$tab = $instance->open($ctx);
$tab->activate($ctx);

$devtools = $tab->devtools();
try {
	$devtools->page()->enable($ctx);
	$devtools->page()->navigate($ctx, NavigateRequest::builder()->setUrl("https://www.google.com/")->build());
	$devtools->page()->awaitLoadEventFired($ctx);
    $data = $devtools->page()->printToPDF($ctx, PrintToPDFRequest::fromJson((object) [
        'displayHeaderFooter' => false
    ]))->data;
    file_put_contents(__DIR__ . '/../test.pdf', base64_decode($data));
} finally {
	// devtools client needs to be closed
	$devtools->close();
}

} finally {
// process needs to be killed
$instance->close();
}`

Any idea what could be going on? Is there a place where I set the Chrome address? On my system it is installed at the default address.

@official-ymail-com
Copy link

You need to install Chrome

For example, I am using ubuntu 18
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo apt install ./google-chrome-stable_current_amd64.deb

@pauloacosta
Copy link
Author

pauloacosta commented Sep 3, 2020

I am using Windows 10 and Chrome is installed at default folder: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

Is there a file where I set up the Chrome address?

@official-ymail-com
Copy link

official-ymail-com commented Sep 16, 2020

You can specific Chrome path like this:

$launcher = new Launcher();
$launcher->setExecutable('/usr/bin/google-chrome-stable');
$instance = $launcher->launch();

@pauloacosta
Copy link
Author

pauloacosta commented Sep 19, 2020

Thank You! Worked like a charm!

I am a Windows user, then my code was:

// launcher starts chrome process ($instance)
$launcher = new Launcher();
$launcher->setExecutable('C:\Program Files (x86)\Google\Chrome\Application');
$instance = $launcher->launch($ctx);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants