webdriverio: [🐛 Bug]: Chrome on Linux: `session not created: probably user data directory is already in use` despite `--no-sandbox`

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.14.0

Node.js Version

22.15.1

Mode

Standalone Mode

Which capabilities are you using?

{
    capabilities: {
        browserName: "chrome",
        'goog:chromeOptions': {
            args: [
                // https://github.com/webdriverio/webdriverio/issues/14168
                "--no-sandbox",
                "--headless",
            ]
        }
    },
    logLevel: 'info',
    connectionRetryCount: 1,
}

What happened?

I can not run chrome standalone on my Linux agent. The error is: Error: Failed to create session. 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

This is basically the same as in #14168 . But the solution to add --no-sandbox does not fix the issue for me.

I tried

  • --no-sandbox
  • set --user-data-dir
  • There is only one agent on the machine, and the machine is reset regularly - no other instance is using the user-data-dir

What is your expected behavior?

I should be able to use the browser.

How to reproduce the bug.

I created an MRE:

// raw.js
import { remote } from "webdriverio";

const browser = await remote({
    capabilities: {
        browserName: "chrome",
        'goog:chromeOptions': {
            args: [
                // https://github.com/webdriverio/webdriverio/issues/14168
                "--no-sandbox",
                "--headless",
            ]
        }
    },
    logLevel: 'info',
    connectionRetryCount: 1,
});

await browser.url(`about:blank`);
const expected = "";
const value = await browser.getTitle();
if(value !== expected) console.error(`Wrong value! Expected "${expected}", actual "${value}"!`);

// Now we need to close the browser window, because it stays open after this
// program exits
// This is a different topic.
try {
	// Throws: "TypeError: Cannot read properties of undefined (reading 'length')"
	// window is closed
	await browser.closeWindow();
} catch (error) {
	console.log(error);
} finally {
	process.exit();
}

Relevant log output

Starting: run tests
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.250.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
node raw.js
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /agent/_work/_temp/7366d1a3-1966-41e2-811d-84ba4c8ee769.sh
2025-05-21T06:16:11.317Z INFO webdriver: Initiate new session using the WebDriver protocol
2025-05-21T06:16:11.519Z INFO webdriver: Setting up chrome v136.0.7103.94
2025-05-21T06:16:18.852Z INFO webdriver: Downloading Chromedriver v136.0.7103.94
2025-05-21T06:16:19.113Z INFO webdriver: Download of Chromedriver v136.0.7103.94 was successful
2025-05-21T06:16:19.120Z INFO chromedriver: Starting ChromeDriver 136.0.7103.94 (fa0be0b33debeb378a8e6ad9c599be34e2dc3b37-refs/branch-heads/7103@{#1842}) on port 46587
2025-05-21T06:16:19.121Z INFO chromedriver: Remote connections are allowed by an allowlist (0.0.0.0).
2025-05-21T06:16:19.121Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
2025-05-21T06:16:19.136Z INFO chromedriver: ChromeDriver was started successfully on port 46587.
2025-05-21T06:16:20.137Z INFO @wdio/utils: Started Chromedriver v136.0.7103.94 with params --port=46587 --allowed-origins=* --allowed-ips=0.0.0.0 in 8817ms on port 46587
2025-05-21T06:16:20.139Z INFO webdriver: [POST] http://localhost:46587/session
2025-05-21T06:16:20.139Z INFO webdriver: DATA {
  capabilities: {
    alwaysMatch: {
      browserName: 'chrome',
      'goog:chromeOptions': [Object],
      webSocketUrl: true
    },
    firstMatch: [ {} ]
  },
  desiredCapabilities: {
    browserName: 'chrome',
    'goog:chromeOptions': {
      binary: '/tmp/chrome/linux-136.0.7103.94/chrome-linux64/chrome',
      args: [Array]
    },
    webSocketUrl: true
  }
}
2025-05-21T06:16:20.216Z WARN webdriver: Request failed with status 500 due to 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
2025-05-21T06:16:20.216Z INFO webdriver: Retrying 1/1
2025-05-21T06:16:20.216Z INFO webdriver: [POST] http://localhost:46587/session
2025-05-21T06:16:20.216Z INFO webdriver: DATA {
  capabilities: {
    alwaysMatch: {
      browserName: 'chrome',
      'goog:chromeOptions': [Object],
      webSocketUrl: true
    },
    firstMatch: [ {} ]
  },
  desiredCapabilities: {
    browserName: 'chrome',
    'goog:chromeOptions': {
      binary: '/tmp/chrome/linux-136.0.7103.94/chrome-linux64/chrome',
      args: [Array]
    },
    webSocketUrl: true
  }
}
2025-05-21T06:16:20.277Z ERROR webdriver: Request failed with status 500 due to session not created: 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
2025-05-21T06:16:20.278Z ERROR webdriver: session not created: 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
    at getErrorFromResponseBody (file:///agent/_work/1/s/node_modules/webdriver/build/index.js:1002:10)
    at FetchRequest._request (file:///agent/_work/1/s/node_modules/webdriver/build/index.js:1310:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async startWebDriverSession (file:///agent/_work/1/s/node_modules/webdriver/build/index.js:895:16)
    at async _WebDriver.newSession (file:///agent/_work/1/s/node_modules/webdriver/build/index.js:1508:41)
    at async remote (file:///agent/_work/1/s/node_modules/webdriverio/build/index.js:7187:20)
    at async file:///agent/_work/1/s/raw.js:3:17
file:///agent/_work/1/s/node_modules/webdriver/build/index.js:899
    throw new Error("Failed to create session.\n" + message);
          ^

Error: Failed to create session.
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
    at startWebDriverSession (file:///agent/_work/1/s/node_modules/webdriver/build/index.js:899:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async _WebDriver.newSession (file:///agent/_work/1/s/node_modules/webdriver/build/index.js:1508:41)
    at async remote (file:///agent/_work/1/s/node_modules/webdriverio/build/index.js:7187:20)
    at async file:///agent/_work/1/s/raw.js:3:17

Node.js v22.15.1

##[error]Bash exited with code '1'.
Finishing: run tests

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 2
  • Comments: 24 (18 by maintainers)

Commits related to this issue

Most upvoted comments

I can attest that Chrome’s error messages don’t rely indicate the actual reason, especially session not created: probably user data directory is already in use.

I think my issue with the Zubridge package tests is unrelated, despite having the same error message on Linux. The issue with these kinds of errors is there are many different things that can cause them and the message in this case is less than helpful. At least with DevToolsActivePort file doesn't exist the message is merely confusing and incomprehensible. This user data dir error is totally misleading.

For Zubridge I’m now getting different errors depending on the OS, which I suspect all have the same root cause:

Linux: WebDriverError: session not created: probably user data directory is already in use - Log MacOS: WebDriverError: Request failed with error code UND_ERR_HEADERS_TIMEOUT when running "http://localhost:49239/session" - Log Windows: WebDriverError: session not created: Failed to create Chrome process. - Log

The package tests in the Electron service itself pass (with just one issue - probably vite-related - on windows), and they are using a similar isolated setup with electron-vite apps.

I’m now getting this with the electron service on all OSs in the Zubridge package tests, for which we are using appEntryPoint… appEntryPoint uses the electron binary from node_modules with a --path flag, I’m hoping this isn’t colliding with the new CDP bridge (which uses --inspect=) in some way.

More investigation required. To start with, I’ll fix the duplicate flags (--no-sandbox appearing twice). This doesn’t stop a @wdio/xvfb from being useful for fixing certain instances of this issue and also DevToolsActivePort file doesn't exist, on Linux.

Let’s track it here.