{"record":{"id":"5ea33c2a2dd7fc82","repo":"SeleniumHQ/selenium","slug":"usercontext-must-be-string-received-usercontex","errorCode":null,"errorMessage":"UserContext must be string. Received:'${userContext}'","messagePattern":"UserContext must be string\\. Received:'(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/createContextParameters.js","lineNumber":62,"sourceCode":"   * @throws {Error} - If the background parameter is not a boolean.\n   */\n  background(background) {\n    if (typeof background !== 'boolean') {\n      throw new Error(`Background must be boolean. Received:'${background}'`)\n    }\n    this.#map.set('background', background)\n    return this\n  }\n\n  /**\n   * Sets the user context.\n   * @param {string} userContext - The user context to set.\n   * @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining.\n   * @throws {Error} - If the userContext parameter is not a string.\n   */\n  userContext(userContext) {\n    if (typeof userContext !== 'string') {\n      throw new Error(`UserContext must be string. Received:'${userContext}'`)\n    }\n    this.#map.set('userContext', userContext)\n    return this\n  }\n\n  asMap() {\n    return this.#map\n  }\n}\n\nmodule.exports = { CreateContextParameters }\n","sourceCodeStart":44,"sourceCodeEnd":74,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/createContextParameters.js#L44-L74","documentation":"Thrown by `CreateContextParameters.userContext()` when the argument is not a string (`typeof userContext !== 'string'`). The user context must be a string id.","triggerScenarios":"Calling `params.userContext(undefined)`, `params.userContext(0)`, or passing an object.","commonSituations":"Undefined user context when none was intended (it is optional); passing a numeric or object value.","solutions":["Pass a string user-context id","If you do not need a user context, omit the call entirely — it is optional"],"exampleFix":"// before\nparams.userContext()\n// after\nparams.userContext('default') // or omit the call","handlingStrategy":"validation","validationCode":"if (typeof ctx === 'string') params.userContext(ctx)","typeGuard":"const isUserContext = (v) => typeof v === 'string'","tryCatchPattern":null,"preventionTips":["userContext() is optional — skip it if unused","typeof-check before calling"],"tags":["bidi","browsing-context","validation","string","user-context"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}