{"record":{"id":"0fdccf2cc55581a7","repo":"SeleniumHQ/selenium","slug":"username-must-be-a-string-received-username","errorCode":null,"errorMessage":"Username must be a string. Received:'${username}'","messagePattern":"Username must be a string\\. Received:'(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/continueResponseParameters.js","lineNumber":61,"sourceCode":"      }\n      cookies.push(Object.fromEntries(header.asMap()))\n    })\n\n    this.#map.set('cookies', cookies)\n    return this\n  }\n\n  /**\n   * Sets the credentials for authentication.\n   *\n   * @param {string} username - The username for authentication.\n   * @param {string} password - The password for authentication.\n   * @returns {ContinueResponseParameters} The current instance of the ContinueResponseParameters for chaining.\n   * @throws {Error} If username or password is not a string.\n   */\n  credentials(username, password) {\n    if (typeof username !== 'string') {\n      throw new Error(`Username must be a string. Received:'${username}'`)\n    }\n\n    if (typeof password !== 'string') {\n      throw new Error(`Password must be a string. Received:'${password}'`)\n    }\n\n    this.#map.set('credentials', { type: 'password', username: username, password: password })\n\n    return this\n  }\n\n  /**\n   * Sets the headers for the response.\n   *\n   * @param {Header[]} headers - An array of Header objects representing the headers.\n   * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.\n   * @throws {Error} - If the header value is not an instance of Header.\n   */","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/continueResponseParameters.js#L43-L79","documentation":"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.","triggerScenarios":"Calling `params.credentials(undefined, 'pass')`, `params.credentials(123, 'pass')`, or passing a credentials object instead of two positional string arguments.","commonSituations":"Username sourced from env/config that is undefined or a non-string; passing a credentials object `{user, pass}` instead of two args.","solutions":["Pass two string arguments: `params.credentials('user', 'pass')`","Ensure the username variable is a defined string"],"exampleFix":"// before\nparams.credentials(config.user, config.pass) // config.user is undefined\n// after\nparams.credentials(String(config.user), String(config.pass))","handlingStrategy":"validation","validationCode":"if (typeof username === 'string' && typeof password === 'string') {\n  params.credentials(username, password)\n}","typeGuard":"const areCredentials = (u, p) => typeof u === 'string' && typeof p === 'string'","tryCatchPattern":null,"preventionTips":["credentials() takes two string positional args, not an object","Guard env-sourced values with typeof checks"],"tags":["bidi","network-interception","validation","string","credentials"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}