Skip to content

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

@htho

Description

@htho

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛help wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions