{"record":{"id":"040478aa2ed571ef","repo":"SeleniumHQ/selenium","slug":"capability-keys-must-be-strings-typeof-key","errorCode":null,"errorMessage":"Capability keys must be strings: ${typeof key}","messagePattern":"Capability keys must be strings: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/lib/capabilities.js","lineNumber":365,"sourceCode":"\n  /**\n   * Deletes an entry from this set of capabilities.\n   *\n   * @param {string} key the capability key to delete.\n   */\n  delete(key) {\n    this.map_.delete(key)\n  }\n\n  /**\n   * @param {string} key The capability key.\n   * @param {*} value The capability value.\n   * @return {!Capabilities} A self reference.\n   * @throws {TypeError} If the `key` is not a string.\n   */\n  set(key, value) {\n    if (typeof key !== 'string') {\n      throw new TypeError('Capability keys must be strings: ' + typeof key)\n    }\n    this.map_.set(key, value)\n    return this\n  }\n\n  /**\n   * Sets whether a WebDriver session should implicitly accept self-signed, or\n   * other untrusted TLS certificates on navigation.\n   *\n   * @param {boolean} accept whether to accept insecure certs.\n   * @return {!Capabilities} a self reference.\n   */\n  setAcceptInsecureCerts(accept) {\n    return this.set(Capability.ACCEPT_INSECURE_TLS_CERTS, accept)\n  }\n\n  /**\n   * @return {boolean} whether the session is configured to accept insecure","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/lib/capabilities.js#L347-L383","documentation":"Thrown by Capabilities.set() when the key is not a string (typeof key !== 'string'). All WebDriver capability keys must be strings per the W3C spec. The method enforces this at the type level and rejects numeric, object, symbol, or boolean keys.","triggerScenarios":"Calling set(123, value) with a numeric key. Using a key from dynamically parsed data that isn't a string. Passing an object or symbol as a key. Iterating over a structure that yields non-string keys.","commonSituations":"Using numeric IDs as capability keys; keys derived from JSON with unexpected types; symbol keys from iterators; object references accidentally used as keys.","solutions":["Convert the key to a string: caps.set(String(key), value).","Validate typeof key === 'string' before calling set().","Ensure config data sources yield string keys (e.g., via Object.entries on a plain object)."],"exampleFix":"// before\ncaps.set(123, 'value')\n// after\ncaps.set(String(123), 'value')","handlingStrategy":"type-guard","validationCode":"if (typeof key !== 'string') {\n  throw new TypeError(`Capability key must be a string, got ${typeof key}`)\n}\ncaps.set(key, value)","typeGuard":"/**\n * @param {*} k\n * @returns {k is string}\n */\nfunction isStringKey(k) {\n  return typeof k === 'string'\n}","tryCatchPattern":null,"preventionTips":["Convert keys with String() when sourcing from dynamic data.","Use Object.entries() on plain objects to guarantee string keys.","Validate typeof key === 'string' before calling set()."],"tags":["capabilities","validation","type","configuration"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}