SeleniumHQ/selenium · error · Error

Username must be a string. Received:'${username}'

Error message

Username must be a string. Received:'${username}'

What it means

Thrown by `ContinueResponseParameters.credentials()` when the first argument (username) is not a string. Both username and password are validated before the credentials object is stored; username is checked first.

Source

Thrown at javascript/selenium-webdriver/bidi/continueResponseParameters.js:61

      }
      cookies.push(Object.fromEntries(header.asMap()))
    })

    this.#map.set('cookies', cookies)
    return this
  }

  /**
   * Sets the credentials for authentication.
   *
   * @param {string} username - The username for authentication.
   * @param {string} password - The password for authentication.
   * @returns {ContinueResponseParameters} The current instance of the ContinueResponseParameters for chaining.
   * @throws {Error} If username or password is not a string.
   */
  credentials(username, password) {
    if (typeof username !== 'string') {
      throw new Error(`Username must be a string. Received:'${username}'`)
    }

    if (typeof password !== 'string') {
      throw new Error(`Password must be a string. Received:'${password}'`)
    }

    this.#map.set('credentials', { type: 'password', username: username, password: password })

    return this
  }

  /**
   * Sets the headers for the response.
   *
   * @param {Header[]} headers - An array of Header objects representing the headers.
   * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.
   * @throws {Error} - If the header value is not an instance of Header.
   */

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Pass two string arguments: `params.credentials('user', 'pass')`
  2. Ensure the username variable is a defined string

Example fix

// before
params.credentials(config.user, config.pass) // config.user is undefined
// after
params.credentials(String(config.user), String(config.pass))
Defensive patterns

Strategy: validation

Validate before calling

if (typeof username === 'string' && typeof password === 'string') {
  params.credentials(username, password)
}

Type guard

const areCredentials = (u, p) => typeof u === 'string' && typeof p === 'string'

Prevention

When it happens

Trigger: Calling `params.credentials(undefined, 'pass')`, `params.credentials(123, 'pass')`, or passing a credentials object instead of two positional string arguments.

Common situations: Username sourced from env/config that is undefined or a non-string; passing a credentials object `{user, pass}` instead of two args.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/0fdccf2cc55581a7. Report an issue: GitHub.