SeleniumHQ/selenium · error · Error
UserContext must be string. Received:'${userContext}'
Error message
UserContext must be string. Received:'${userContext}' What it means
Thrown by `CreateContextParameters.userContext()` when the argument is not a string (`typeof userContext !== 'string'`). The user context must be a string id.
Source
Thrown at javascript/selenium-webdriver/bidi/createContextParameters.js:62
* @throws {Error} - If the background parameter is not a boolean.
*/
background(background) {
if (typeof background !== 'boolean') {
throw new Error(`Background must be boolean. Received:'${background}'`)
}
this.#map.set('background', background)
return this
}
/**
* Sets the user context.
* @param {string} userContext - The user context to set.
* @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining.
* @throws {Error} - If the userContext parameter is not a string.
*/
userContext(userContext) {
if (typeof userContext !== 'string') {
throw new Error(`UserContext must be string. Received:'${userContext}'`)
}
this.#map.set('userContext', userContext)
return this
}
asMap() {
return this.#map
}
}
module.exports = { CreateContextParameters }
View on GitHub (pinned to aa36b38e69)
Solutions
- Pass a string user-context id
- If you do not need a user context, omit the call entirely — it is optional
Example fix
// before
params.userContext()
// after
params.userContext('default') // or omit the call Defensive patterns
Strategy: validation
Validate before calling
if (typeof ctx === 'string') params.userContext(ctx)
Type guard
const isUserContext = (v) => typeof v === 'string'
Prevention
- userContext() is optional — skip it if unused
- typeof-check before calling
When it happens
Trigger: Calling `params.userContext(undefined)`, `params.userContext(0)`, or passing an object.
Common situations: Undefined user context when none was intended (it is optional); passing a numeric or object value.
Related errors
- ReferenceContext must be string. Received:'${id}'
- Type must be an instance of String. Received:'${type}'
- Http method must be a string. Received: '${method})'
- Url must be a string. Received:'${url}'
- Username must be a string. Received:'${username}'
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/5ea33c2a2dd7fc82.
Report an issue: GitHub.