Laravel 7(Ubuntu 20.04环境)下Dusk可打开浏览器但无法控制的问题求助
I’ve run into nearly identical issues with Dusk on Ubuntu 20.04 before, so here are practical, step-by-step fixes to try based on my experience:
1. Verify ChromeDriver and Chrome Version Compatibility
Dusk is extremely strict about matching Chrome and ChromeDriver versions—this is the #1 culprit for unresponsive browsers.
- Check your Chrome version first:
google-chrome --version - Check the ChromeDriver version bundled with Dusk:
./vendor/laravel/dusk/bin/chromedriver --version - If versions don’t align, update ChromeDriver to match your browser:
# Replace "118" with your Chrome major version php artisan dusk:chrome-driver 118
2. Fix DuskTestCase Configuration
Even though you disabled headless mode, double-check your driver() method for missing critical settings:
protected function driver() { $options = (new ChromeOptions)->addArguments([ // Keep your existing arguments, but add these: '--no-sandbox', '--disable-dev-shm-usage', ]); // Explicitly set Chrome's binary path (critical for Ubuntu) $options->setBinary('/usr/bin/google-chrome'); return RemoteWebDriver::create( 'http://localhost:9515', DesiredCapabilities::chrome()->setCapability( ChromeOptions::CAPABILITY, $options ) ); }
The --no-sandbox and --disable-dev-shm-usage flags fix common Ubuntu-specific permission/resource issues.
3. Install Missing System Dependencies
Chrome on Ubuntu requires some libraries to run properly, even with a desktop environment. Install them with:
sudo apt-get install libxss1 libappindicator1 libindicator7 libgbm-dev
4. Enable Verbose Logging to Uncover Hidden Errors
Since you’re not seeing explicit errors, force Chrome to log details:
Add this to your driver() method before returning the RemoteWebDriver:
$options->addArguments(['--log-path=/tmp/dusk_chrome.log']);
Run your test again, then check the log for clues:
cat /tmp/dusk_chrome.log
Look for lines about failed extensions, permission denied, or missing resources.
5. Test with a Minimal, Isolated Example
Rule out custom test code issues by running this stripped-down test:
<?php namespace Tests\Browser; use Laravel\Dusk\Browser; use Tests\DuskTestCase; class MinimalTest extends DuskTestCase { public function testBasicNavigation() { $this->browse(function (Browser $browser) { $browser->visit('https://google.com') ->assertSee('Google'); }); } }
If this still fails, the problem is definitely environment-related, not your test logic.
6. Check Virtual Display (For Server/Headless Desktop Environments)
If you’re running on a server without a physical desktop (even though you disabled headless mode), you need a virtual display to render Chrome:
- Install Xvfb:
sudo apt-get install xvfb - Start a virtual display session:
Xvfb :99 -ac & export DISPLAY=:99 - Run your Dusk test again in the same terminal session.
内容的提问来源于stack exchange,提问作者NoahCorlew

