Search code examples
phplaravelselenium-webdriverlaravel-dusk

Chrome driver failing in Laravel Dusk - "Failed to open stream: HTTP request failed! 404 Not Found"


For the last day or so I've started seeing my Laravel Dusk tests fail on my CI/CD environment (GitHub Actions).

Suddenly, running the command that had been working fine all this time:

php artisan dusk:chrome-driver `/opt/google/chrome/chrome --version | cut -d " " -f3 | cut -d "." -f1`

..fails with the error:

file_get_contents(https://chromedriver.storage.googleapis.com/LATEST_RELEASE_116): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

Trying to get around this by forcing version 114:

php artisan install:chrome-driver 114

...fails with the error:

Facebook\WebDriver\Exception\SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 114

How can I fix this and get my tests to start passing again?


Solution

  • This issue is discussed upstream in detail here - in short, the 404 is caused by Google changing the source URLs for the Chrome binaries from version 115 onwards.

    Specifically for Laravel Dusk, this seems to have been fixed in this Dusk issue here, so theoretically all that's needed to fix this properly is a composer require laravel/dusk --with-all-dependencies, but at least in my case, this would update a lot of dependencies and seems highly likely to break my application. I've asked on that issue what the best course of action is for a legacy Laravel application (Laravel 8 in my case), but in the meantime: downgrading both the Chrome/Chromium browser and the Chrome driver to v114 should be a good enough workaround.

    This is easier said than done and it's taken me over a day to figure out how to do it successfully on GitHub Actions, but adding the following steps to your workflow file should be all that's needed to get the CI/CD pipeline running again:

      - name: Downgrade Chrome browser to v114
        uses: browser-actions/setup-chrome@v1
        with:
          chrome-version: 1134343 # Last commit number for Chrome v114
        id: setup-chrome
      - run: sudo ln -fs ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/google-chrome
      - name: Downgrade Chrome driver to v114
        run: php artisan dusk:chrome-driver `/usr/bin/google-chrome --version | cut -d " " -f3 | cut -d "." -f1`