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

session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir #1155

Open
asterism612 opened this issue Jan 17, 2025 · 12 comments

Comments

@asterism612
Copy link

Dusk Version

10.48.25

Laravel Version

10.4

PHP Version

8.3.14

PHPUnit Version

10.0.1

Database Driver & Version

Mysql 8.0

Description

Error message : session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir

protected function driver(): RemoteWebDriver
{
$options = (new ChromeOptions)->addArguments(collect([
$this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
])->unless($this->hasHeadlessDisabled(), function (Collection $items) {
return $items->merge([
'--disable-gpu',
'--headless=new',
'--no-sandbox'
]);
})->all());

$server = RemoteWebDriver::create(
  $_ENV['DUSK_DRIVER_URL'] ?? 'http://localhost:9515',
  DesiredCapabilities::chrome()->setCapability(
    ChromeOptions::CAPABILITY,
    $options
  )
);

dd($server);

return $server;

}

Steps To Reproduce

  1. php artisan dusk
  2. Error message : session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
@crynobone
Copy link
Member

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@asterism612
Copy link
Author

asterism612 commented Jan 19, 2025

No matter how uniquely I regenerate --user-data-dir, I keep encountering an error saying "already in use" when making a POST request to http://localhost:9515/session.

chromedriver version : ChromeDriver 132.0.6834.84 (c1a6c2d428b5b484febdecda9475aba38de5a502-refs/branch-heads/6834@{#3391})
chrome version : Google Chrome 132.0.6834.84

When I run dusk:chrome-driver --detect, it installs version 83, and even after updating to the latest version, the issue persists.

but The same source works fine when run on another Mac machine.

chrom

Image

@crynobone
Copy link
Member

Can you try using Chrome for Testing: https://developer.chrome.com/blog/chrome-for-testing

It would be impossible to solve this without a reliable way to replicate the issue.

@3bood-kr
Copy link

I'm facing the same issue. Have you figured it out yet?

@3bood-kr
Copy link

Ok i solved it by adding 'no-sandbox' to the driver options:

# DuskTestCase.php
/**
     * Create the RemoteWebDriver instance.
     */
    protected function driver(): RemoteWebDriver
    {
        $options = (new ChromeOptions)->addArguments(collect([
            $this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
            '--disable-search-engine-choice-screen',
        ])->unless($this->hasHeadlessDisabled(), function (Collection $items) {
            return $items->merge([
                '--disable-gpu',
                '--headless=new',
                '--no-sandbox',
            ]);
        })->all());

        return RemoteWebDriver::create(
            $_ENV['DUSK_DRIVER_URL'] ?? env('DUSK_DRIVER_URL') ?? 'http://127.0.0.1:9515',
            DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY, $options
            )
        );
    }

@asterism612
Copy link
Author

The permission issue arose due to installing the Dracula theme for oh-my-zsh.

@footballencarta
Copy link

@asterism612 What permission issues did you have?

I'm facing the same issue trying to run dusk inside a Docker container using Laravel 11.

I've tried

  • using Chrome for Testing
  • setting both Chrome Driver and Chrome to permissions 777
  • adding on --no-sandbox

but still having the same problem.

@poly2it
Copy link

poly2it commented Feb 13, 2025

@asterism612 an update on this would be very helpful.

@HugoHeneault
Copy link

HugoHeneault commented Feb 20, 2025

We're also having that issue :(

Anyone got a chance to fix / workaround it?

Thanks alot

Edit : my colleague managed to get it working by using official chrome version instead of snap version (he uninstalled chromium from snap).

@footballencarta
Copy link

I've come back to this after a couple of weeks and managed to resolve the problem.

The issue is in the docker container, I'd installed Chrome as the root user (and given everyone else permissions to use it).

When I was using it as user 1000, as they didn't have a home directory, it failed.

I then updated to run the Dockerfile as the root user, and everything sprung to life.

For reference (if you're using Jenkins like I am):

docker {
    image '_docker_image_'
    args '-u root --privileged'
    reuseNode true
}

@jameswilddev
Copy link

Wanted to say we're having this issue across all developers across all projects using Dusk since maybe a month ago. We're not using Docker/etc. just Valet and a normal install of Chrome. I've already spent half a day poking around and found absolutely nothing to go on - as above, specifying your own user directory doesn't seem to make any difference. If there's anything you would need from us to find the root cause just say the word.

@crynobone
Copy link
Member

As someone who using Laravel Dusk daily I don't have any way to reproduce the issue. Appreciate any help to debug and/or fix the issue.

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

No branches or pull requests

7 participants