symfony / panther

A browser testing and web crawling library for PHP and Symfony
MIT License
2.93k stars 220 forks source link

Chrome failed to start: exited abnormally. chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed #503

Open shubaivanqbee opened 2 years ago

shubaivanqbee commented 2 years ago

Some time ago everythig works fine, but after rebuild my image I faced with error

composer json

  "require-dev": {
    "dbrekelmans/bdi": "^0.3.0",
    "symfony/panther": "^1.1",
root@89ad49c92a69:/auth_service# /usr/lib/chromium/chrome --version
bash: /usr/lib/chromium/chrome: No such file or directory
root@89ad49c92a69:/auth_service# /usr/lib/chromium/                
chrome-sandbox  chromium        locales/        
root@89ad49c92a69:/auth_service# /usr/lib/chromium/chrom  
chrome-sandbox  chromium        
root@89ad49c92a69:/auth_service# /usr/lib/chromium/chromium --version
Chromium 90.0.4430.212 
root@89ad49c92a69:/auth_service# /usr/bin/chromedriver -v
ChromeDriver 90.0.4430.212 (e3cd97fc771b893b7fd1879196d1215b622c2bed-refs/branch-heads/4430@{#1429})
root@89ad49c92a69:/auth_service# drivers/chromedriver -v
ChromeDriver 90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430@{#429})
root@89ad49c92a69:/auth_service# vendor/bin/bdi detect drivers

 [OK] chromedriver 94.0.4606.61 installed to drivers/chromedriver                                                       

 [OK] chromedriver 90.0.4430.24 installed to drivers/chromedriver                                                       

root@89ad49c92a69:/auth_service# 

why two was detected two drivers and why in ./drivers directory present onky one ?

when I try to use

        $this->panterClient = Client::createChromeClient(
            'drivers/chromedriver', [ '--headless', '--disable-dev-shm-usage', '--no-sandbox' ]
        );

I faced with another problem

session not created: This version of ChromeDriver only supports Chrome version 90
Current browser version is 94.0.4606.71 with binary path /usr/bin/google-chrome

then I execute

root@89ad49c92a69:/auth_service# vendor/bin/bdi driver:chromedriver

 [OK] chromedriver 94.0.4606.61 installed to ./chromedriver 

and change code to

         $this->panterClient = Client::createChromeClient(
            'chromedriver',
            [
                '--remote-debugging-port=9222',
                '--no-sandbox'
            ],
            ['request_timeout_in_ms' => 20000000]
        );

and still faced

Facebook\WebDriver\Exception\UnknownErrorException: unknown error: Chrome failed to start: exited abnormally.
  (chrome not reachable)
  (The process started from chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

so my docker file

FROM php:7.4-fpm

# Install chrome, required for the symfony/panther library
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/chrome.deb
RUN dpkg -i /tmp/chrome.deb || apt-get install -yf
RUN rm /tmp/chrome.deb

ENV PANTHER_NO_SANDBOX 1
ENV PANTHER_CHROME_ARGUMENTS='--disable-dev-shm-usage --disable-gpu --disable-extensions --remote-debugging-port=9222'
    protected function setUp(): void
    {
        parent::setUp();
        $this->dm->getDocumentDatabase(Router::class)->drop();
        self::stopWebServer();
        $this->panterClient = static::createPantherClient([
            '--remote-debugging-port=9222',
            '--no-sandbox',
        ], [], ['request_timeout_in_ms' => 20000000]);

then try sent request

        $crawler = $this->panterClient->request('GET', '/yTTnzslr4HrXo27SeerFSPSiQTZO4S8sJpBPIw6jWI0Qn6VzbVUfO1m6GdC3CAln/admin/');

and faced with error

1) App\Tests\Application\Controller\Sonata\SubscriptionSonataControllerTest::testSubscriptionApproach
Facebook\WebDriver\Exception\UnknownErrorException: unknown error: Chrome failed to start: exited abnormally.
  (chrome not reachable)
  (The process started from chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

/auth_service/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:139
/auth_service/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:371
/auth_service/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:135
/auth_service/vendor/symfony/panther/src/ProcessManager/ChromeManager.php:75
/auth_service/vendor/symfony/panther/src/Client.php:120
/auth_service/vendor/symfony/panther/src/Client.php:524
/auth_service/vendor/symfony/panther/src/Client.php:276
/auth_service/tests/Application/Controller/Sonata/SubscriptionSonataControllerTest.php:57

ERRORS!
shubaivanqbee commented 2 years ago

I find out what it's goin on, my mistake, maybe this help for someone

For Panther

docker-compose exec fpm bash

for list command and need select what needed

vendor/bin/bdi lists


# 1. one of the case which I did use  manual way 

&& apt-get install -y chromium \ && apt-get install -y chromium-driver \


```bash
root@95c5c864abae:/auth_service# /usr/lib/chromium/chromium --version
Chromium 90.0.4430.212 

path where located drivers by default if installed it like manual way

root@95c5c864abae:/auth_service# /usr/bin/chromedriver --version
ChromeDriver 90.0.4430.212 (e3cd97fc771b893b7fd1879196d1215b622c2bed-refs/branch-heads/4430@{#1429})

2. custom way

Dockerfile

# Install chrome, required for the symfony/panther library
ENV PANTHER_NO_SANDBOX 1
# Not mandatory, but recommended
ENV PANTHER_CHROME_ARGUMENTS='--headless --no-sandbox --disable-infobars --disable-dev-shm-usage --disable-gpu --disable-extensions --remote-debugging-port=9222'
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/chrome.deb
RUN dpkg -i /tmp/chrome.deb || apt-get install -yf
RUN rm /tmp/chrome.deb

Chrome which was downloaded by wget, from Dockerfile located, did not have drivers by default

root@95c5c864abae:/auth_service# /usr/bin/google-chrome --version
Google Chrome 94.0.4606.71

Panther fetch driver by default from /usr/bin/chromedriver or in drivers dir, have a look please - \Symfony\Component\Panther\ProcessManager\ChromeManager::findChromeDriverBinary when client created like this

        $this->panterClient = static::createPantherClient([
            '--remote-debugging-port=9222',
            '--no-sandbox',
        ], [], ['request_timeout_in_ms'=>20000000]);

so for download driver we need use custom way and use for this dbrekelmans/bdi

root@c6ca94b09430:/auth_service# vendor/bin/bdi detect drivers                                                                                                
 [OK] chromedriver 94.0.4606.61 installed to drivers/chromedriver                                                                                                                                  

the in \Symfony\Component\Panther\ProcessManager\ChromeManager::findChromeDriverBinary will be fetched correct binary file from drivers/chromedriver

root@c6ca94b09430:/auth_service# drivers/chromedriver --version
ChromeDriver 94.0.4606.61 (418b78f5838ed0b1c69bb4e51ea0252171854915-refs/branch-heads/4606@{#1204})