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

Timeout #644

Open
jazz265 opened this issue Aug 2, 2024 · 5 comments
Open

Timeout #644

jazz265 opened this issue Aug 2, 2024 · 5 comments

Comments

@jazz265
Copy link

jazz265 commented Aug 2, 2024

require_once __DIR__ . '/vendor/autoload.php';
use HeadlessChromium\BrowserFactory;

$browserFactory = new BrowserFactory();

// starts headless Chrome
$browser = $browserFactory->createBrowser([
    'headless' => false, 
]);

try {
    // creates a new page and navigate to an URL
    $page = $browser->createPage();
    $page->navigate('http://example.com')->waitForNavigation();

    // get page title
    $pageTitle = $page->evaluate('document.title')->getReturnValue();

    // screenshot - Say "Cheese"! ??
    $page->screenshot()->saveToFile('/foo/bar.png');

    // pdf
    $page->pdf(['printBackground' => false])->saveToFile('/foo/bar.pdf');
} finally {
    // bye
    $browser->close();
}

PHP Fatal error: Uncaught HeadlessChromium\Exception\OperationTimedOut: Operation timed out (5sec) in C:\xampp\htdocs\x\sc\vendor\chrome-php\chrome\src\Utils.php:71
Stack trace:
#0 C:\xampp\htdocs\x\sc\vendor\chrome-php\chrome\src\Communication\ResponseReader.php(115): HeadlessChromium\Utils::tryWithTimeout(5000000, Object(Generator))
#1 C:\xampp\htdocs\x\sc\vendor\chrome-php\chrome\src\Communication\Connection.php(247): HeadlessChromium\Communication\ResponseReader->waitForResponse(5000)
#2 C:\xampp\htdocs\x\sc\vendor\chrome-php\chrome\src\Browser.php(77): HeadlessChromium\Communication\Connection->sendMessageSync(Object(HeadlessChromium\Communication\Message))
#3 C:\xampp\htdocs\x\sc\vendor\chrome-php\chrome\src\Browser\ProcessAwareBrowser.php(26): HeadlessChromium\Browser->__construct(Object(HeadlessChromium\Communication\Connection))
#4 C:\xampp\htdocs\x\sc\vendor\chrome-php\chrome\src\Browser\BrowserProcess.php(157): HeadlessChromium\Browser\ProcessAwareBrowser->__construct(Object(HeadlessChromium\Communication\Connection), Object(HeadlessChromium\Browser\BrowserProcess))
#5 C:\xampp\htdocs\x\sc\vendor\chrome-php\chrome\src\BrowserFactory.php(71): HeadlessChromium\Browser\BrowserProcess->start('C:\Program File...', Array)
#6 C:\xampp\htdocs\x\sc\test2.php(16): HeadlessChromium\BrowserFactory->createBrowser(Array)
#7 {main}
thrown in C:\xampp\htdocs\x\sc\vendor\chrome-php\chrome\src\Utils.php on line 71

The browser starts up, but it doesn't work and times out, closes, and gives the above error. Please let me know how to solve this.

@cliffordvickrey
Copy link

cliffordvickrey commented Aug 5, 2024

Getting the same issue with Chrome >= 128 when A) running PHP for Windows in B) SAPI mode (e.g. Apache). In the logs, everything looks good (in my use case, I successfully invoke Page.printToPDF and see that DevTools logs "firstMeaningfulPaintCandidate"), except Chrome never writes a response to the web socket.

A workaround for me was disabling sandbox mode, e.g.:

$browserFactory->createBrowser(['headless' => true, 'noSandbox' => true]);

This may have security implications, depending on what you're using Chrome for; these can be mitigated by running Chrome inside a container.

@jazz265
Copy link
Author

jazz265 commented Aug 7, 2024

Thank you for answering! I tried it, but it didn't work. Is there any other way?

@Issei0804-ie
Copy link

In my environment, that error occurred when CPU resources were insufficient.
I think too long time to process

@jimfm29
Copy link

jimfm29 commented Aug 23, 2024

Chrome was updated on our production server yesterday eve to 128.0.6613.85. Now, chrome-php times out. Running on Windows IIS with php 8.2.20; tested with php 8.3.10 with same results.

HeadlessChromium\Exception\OperationTimedOut: Operation timed out after 240s. in \chrome-php\chrome\src\Exception\OperationTimedOut.php:18
Stack trace:
#0 \chrome-php\chrome\src\Utils.php(67): HeadlessChromium\Exception\OperationTimedOut::createFromTimeout(240000000)
#1 \chrome-php\chrome\src\Communication\ResponseReader.php(114): HeadlessChromium\Utils::tryWithTimeout(240000000, Object(Generator))
#2 \chrome-php\chrome\src\PageUtils\AbstractBinaryInput.php(67): HeadlessChromium\Communication\ResponseReader->waitForResponse(240000)
#3 \our_project_library\Export.php(249): HeadlessChromium\PageUtils\AbstractBinaryInput->saveToFile('C:\Windows\Temp...', 240000)

@andrewsauder
Copy link

andrewsauder commented Aug 29, 2024

Also experiencing this issue with Windows PHP 8.1 nts x64 and PHP 8.2 nts x64. Issue occurs using php-cgi.exe with IIS and php.exe from command line. Disabling sandbox mode has resolved the issue for now.
$browserFactory->createBrowser(['headless' => true, 'noSandbox' => true]);

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

No branches or pull requests

5 participants