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

OperationTimedOut in waitForStartup #1

Closed
andrew-s opened this issue Dec 4, 2017 · 16 comments
Closed

OperationTimedOut in waitForStartup #1

andrew-s opened this issue Dec 4, 2017 · 16 comments
Labels

Comments

@andrew-s
Copy link
Contributor

andrew-s commented Dec 4, 2017

I've been trying to utilise this, I've defined "chromium-browser" as the headless browser in the factory, like so;

       $browserFactory = new BrowserFactory('chromium-browser');

        // starts headless chrome
        $browser = $browserFactory->createBrowser();

        try {
            // creates a new page and navigate to an url
            $page = $browser->createPage($payload->uri);
            $page->navigate($payload->uri);
        } catch(NoResponseAvailable $exception) {
            dd($exception);
        } 

        $browser->close();

However, I'm getting OperationTimedOut in waitForStartup, it seems like the regex does match and does get back a DevTools ws URL. A process does get started (and not removed interestingly) - I'm unsure how to debug this further. Any advice would be greatly appreciated.

Thanks!

@gsouf
Copy link
Member

gsouf commented Dec 4, 2017

Hi @andrew-s,

Thanks for your insterest. First know that the project is in very early stage (actually I didnt even expect that someone would use it for now!)

Concerning your issue, what version of chromium are you using?

@andrew-s
Copy link
Contributor Author

andrew-s commented Dec 5, 2017

@gsouf I had a feeling that might be the case. I was using PhantomJS but I'm seeing lots of odd issues with angular apps - I thought that using headless chrome might be a better choice.

My version is;

Package: chromium-browser
Architecture: amd64
Version: 49.0.2623.108-0ubuntu1.1233

If there's any way I can help/contribute where/when I can then let me know.

Thanks!

@gsouf
Copy link
Member

gsouf commented Dec 5, 2017

@andrew-s that's the reason I switched to headless chrome as well. PhantomJs developement has been aborted and it has too many bugs.

Concerning your version you have to upgrade chrome. I think that as of version 60 you should be fine. Headless chrome started to ship with version 59/60 and I noticed bugs with version 59 of chrome as well. The best is still to go with the latest version (62 as of I'm writting)

Let me know if it works.

Of course you can contribute. There are many ways to do that. If you feel that some features are missing, or that the API could be improved in some ways you can open an issue and discuss it and if you now how to do it you can send pull requests that implement what was discussed.
You can also help to improve the documentation by adding examples, fixing typoes, ect...

@andrew-s
Copy link
Contributor Author

andrew-s commented Dec 5, 2017

@gsouf Ah sorry, I was doing apt-cache show chromium-browser but apparently, that's showing a different version, the installed version is; Version 62.0.3202.94 (Official Build) Built on Ubuntu , running on elementary 0.4.1 (64-bit)

That would suggest the time out lies elsewhere.

Do you have a feature/todo list? Could be a good place to start.

Thanks!

@gsouf
Copy link
Member

gsouf commented Dec 5, 2017

Thanks for the details. I will add a debug feature to have an output of what is actually happening.

As regards the todo list. I don't have such a thing for the moment, but I can do it if it can help people to contribute!

Stay tunned

@gsouf
Copy link
Member

gsouf commented Dec 5, 2017

Just a side question, is the installed version running with the commande "chromium-browser" as well? You can check version from command line with the command: chromium-browser --version

@andrew-s
Copy link
Contributor Author

andrew-s commented Dec 5, 2017

I can give you the output from the socket, but I'm not sure it'll be too useful from what/where I'm outputting.

It is the same version from the CLI that the browser lists.

@andrew-s
Copy link
Contributor Author

andrew-s commented Dec 5, 2017

So, I debugged this a little more, looks like an issue in Utils::tryWithTimeout();

It does get a socket but, doesn't seem to then leave the foreach - shouldn't it yield the matched socket?

@gsouf
Copy link
Member

gsouf commented Dec 5, 2017

@andrew-s Let me know what version of php you are using?

I'll try to dive in the issue as of tomorrow

@andrew-s
Copy link
Contributor Author

andrew-s commented Dec 5, 2017

Running PHP 7.0, I noticed you used Symfony process - would it perhaps simplify things to utilise their commands for real-time output reading? and then jump out once the websocket has been returned?

Unless there's an easy fix in that generator, unfortunately my experience of them is non-existent, let me know if I can help in any way. Thanks!

@gsouf
Copy link
Member

gsouf commented Dec 6, 2017

@andrew-s

Please, can you pull down last changes from master and run the browser factory using this option:

$browserFactory->createBrowser([
        'debugLogger'     => 'php://stdout'
    ]);

This will output some info in the console, can you copy and paste this output alongside you next response please?

@andrew-s
Copy link
Contributor Author

andrew-s commented Dec 6, 2017

@gsouf Appreciate the work on this, here's the output;

[2017-12-06 10:35:42] DEBUG process: initializing
[2017-12-06 10:35:42] DEBUG process: using directory: /tmp/chromium-php-CycVEP
[2017-12-06 10:35:42] DEBUG process: starting process: chromium-browser --remote-debugging-port=0 --disable-background-networking --disable-background-timer-throttling --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-translate --metrics-recording-only --no-first-run --safebrowsing-disable-auto-update --enable-automation --password-store=basic --use-mock-keychain --headless --disable-gpu --hide-scrollbars --mute-audio --user-data-dir=/tmp/chromium-php-CycVEP
[2017-12-06 10:35:42] DEBUG process: waiting for 30 seconds for startup
[2017-12-06 10:35:42] DEBUG process: chrome output:
DevTools listening on ws://127.0.0.1:46771/devtools/browser/b264603a-a5f6-461b-aed0-5019467fc137

[2017-12-06 10:35:42] DEBUG process: ✓ accepted output
[2017-12-06 10:35:42] DEBUG process: connecting using ws://127.0.0.1:46771/devtools/browser/b264603a-a5f6-461b-aed0-5019467fc137
[2017-12-06 10:35:42] DEBUG socket: connecting
[2017-12-06 10:35:42] DEBUG socket: ✓ connected
[2017-12-06 10:35:42] DEBUG socket: |=> sending data:{"id":1,"method":"Target.createTarget","params":{"url":"http:\/\/google.com\/"}}
[2017-12-06 10:35:42] DEBUG socket: <=| receiving data:{"id":1,"result":{"targetId":"e4070095-d19e-49c3-af9b-835525aff064"}}
[2017-12-06 10:35:42] DEBUG socket: |=> sending data:{"id":2,"method":"Target.attachToTarget","params":{"targetId":"e4070095-d19e-49c3-af9b-835525aff064"}}
[2017-12-06 10:35:42] DEBUG socket: <=| receiving data:{"method":"Target.attachedToTarget","params":{"sessionId":"e4070095-d19e-49c3-af9b-835525aff064:1","targetInfo":{"targetId":"e4070095-d19e-49c3-af9b-835525aff064","type":"page","title":"","url":"http://google.com/","attached":true},"waitingForDebugger":false}}
[2017-12-06 10:35:42] DEBUG socket: <=| receiving data:{"id":2,"result":{"sessionId":"e4070095-d19e-49c3-af9b-835525aff064:1"}}
[2017-12-06 10:35:42] DEBUG socket: |=> sending data:{"id":4,"method":"Target.sendMessageToTarget","params":{"message":"{\"id\":3,\"method\":\"Page.navigate\",\"params\":{\"url\":\"http:\\\/\\\/google.com\\\/\"}}","sessionId":"e4070095-d19e-49c3-af9b-835525aff064:1"}}
[2017-12-06 10:35:42] DEBUG socket: <=| receiving data:{"id":4,"result":{}}
[2017-12-06 10:35:42] DEBUG process: killing chrome
[2017-12-06 10:35:42] DEBUG process: trying to close chrome gracefully
[2017-12-06 10:35:42] DEBUG socket: |=> sending data:{"id":5,"method":"Browser.close","params":[]}
[2017-12-06 10:35:42] DEBUG socket: <=| receiving data:{"error":{"code":-32601,"message":"'Browser.close' wasn't found"},"id":5}
[2017-12-06 10:35:42] DEBUG process: ✗ could not close gracefully
[2017-12-06 10:35:42] DEBUG process: closing chrome gracefully - compatibility
[2017-12-06 10:35:42] DEBUG socket: |=> sending data:{"id":6,"method":"Target.getTargets","params":[]}
[2017-12-06 10:35:42] DEBUG socket: <=| receiving data:{"id":6,"result":{"targetInfos":[{"targetId":"e4070095-d19e-49c3-af9b-835525aff064","type":"page","title":"","url":"http://google.com/","attached":true},{"targetId":"fceef7c3-b401-49e4-8998-6710ac58c8c5","type":"page","title":"","url":"about:blank","attached":false}]}}
[2017-12-06 10:35:42] DEBUG socket: |=> sending data:{"id":7,"method":"Target.closeTarget","params":{"targetId":"e4070095-d19e-49c3-af9b-835525aff064"}}
[2017-12-06 10:35:42] DEBUG socket: <=| receiving data:{"method":"Target.detachedFromTarget","params":{"sessionId":"e4070095-d19e-49c3-af9b-835525aff064:1","targetId":"e4070095-d19e-49c3-af9b-835525aff064"}}
[2017-12-06 10:35:42] DEBUG socket: <=| receiving data:{"id":7,"result":{"success":true}}
[2017-12-06 10:35:42] DEBUG socket: |=> sending data:{"id":8,"method":"Target.closeTarget","params":{"targetId":"fceef7c3-b401-49e4-8998-6710ac58c8c5"}}
[2017-12-06 10:35:42] DEBUG socket: <=| receiving data:{"id":8,"result":{"success":true}}
[2017-12-06 10:35:42] DEBUG socket: disconnecting
[2017-12-06 10:35:42] DEBUG socket: ✓ disconnected
[2017-12-06 10:35:42] DEBUG process: waiting for process to close
[2017-12-06 10:35:57] DEBUG process: killing chrome
[2017-12-06 10:35:57] DEBUG process: chrome already killed, ignoring
PHP 7.0.22-0ubuntu0.16.04.1 Development Server started at Wed Dec  6 10:35:32 2017

@gsouf
Copy link
Member

gsouf commented Dec 6, 2017

The good news is that it actually appears to be working correctly. Looking at the log I would guess that the error happens while closing chrome. The second good news is that I could reproduce the error and figured out that chrome wont close when running in headless mode (I disabled headless mode in my previous tests).

@andrew-s
Copy link
Contributor Author

andrew-s commented Dec 6, 2017

Ah yeah, disabled headless mode and it worked. At least we both got the same result there.

gsouf added a commit that referenced this issue Dec 6, 2017
@gsouf
Copy link
Member

gsouf commented Dec 6, 2017

I pushed a fix. Hopefully the shutdown of chrome should be better as of chrome 63 (didn't test yet) because they added a method to close the browser gracefully that I couldn't find in chrome 62

@gsouf gsouf added the bug label Dec 6, 2017
@gsouf
Copy link
Member

gsouf commented Dec 6, 2017

I'm closing the issue, feel free to open it again in case it reproduces or to open a new one for any other features

divinity76 added a commit to divinity76/chrome that referenced this issue May 3, 2023
for a split second, documentElement might be missing, causing getHtml() to crash.
I had a program that was doing page stuff and calling getHtml() like every 10 milliseconds (100 times per second), and got an unexpected crash. Was able to create a small reproducible sample:
```php
<?php

declare(strict_types=1);
require_once('vendor/autoload.php');
$chromeBinary = "/snap/bin/chromium";
$browser_factory = new \HeadlessChromium\BrowserFactory($chromeBinary);
$browser_factory->setOptions([
    "headless" => true,
    "noSandbox" => true,
    'windowSize'   => [1000, 1000]
]);
$browser = $browser_factory->createBrowser();
$page = $browser->createPage();
for ($i = 0; $i < 100; ++$i) {
    $page->navigate("http://example.com");
    $html = $page->getHtml();
    $page->navigate("http://example.org");
    $html = $page->getHtml();
}
```
consistently crash with:
```
PHP Fatal error:  Uncaught HeadlessChromium\Exception\JavascriptException: Error during javascript evaluation: TypeError: Cannot read properties of null (reading 'outerHTML')
    at <anonymous>:1:26 in /home/hans/projects/ibkr/vendor/chrome-php/chrome/src/PageUtils/PageEvaluation.php:89
Stack trace:
#0 /home/hans/projects/ibkr/vendor/chrome-php/chrome/src/PageUtils/PageEvaluation.php(108): HeadlessChromium\PageUtils\PageEvaluation->waitForResponse()
chrome-php#1 /home/hans/projects/ibkr/vendor/chrome-php/chrome/src/Page.php(894): HeadlessChromium\PageUtils\PageEvaluation->getReturnValue()
chrome-php#2 /home/hans/projects/ibkr/test_crash.php(16): HeadlessChromium\Page->getHtml()
chrome-php#3 {main}
  thrown in /home/hans/projects/ibkr/vendor/chrome-php/chrome/src/PageUtils/PageEvaluation.php on line 89
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants