{"record":{"id":"0580839e6b3f5361","repo":"SeleniumHQ/selenium","slug":"background-must-be-boolean-received-background","errorCode":null,"errorMessage":"Background must be boolean. Received:'${background}'","messagePattern":"Background must be boolean\\. Received:'(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/createContextParameters.js","lineNumber":48,"sourceCode":"   */\n  referenceContext(id) {\n    if (typeof id !== 'string') {\n      throw new Error(`ReferenceContext must be string. Received:'${id}'`)\n    }\n    this.#map.set('referenceContext', id)\n    return this\n  }\n\n  /**\n   * Sets the background parameter.\n   *\n   * @param {boolean} background - The background value to set.\n   * @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining.\n   * @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  }","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/createContextParameters.js#L30-L66","documentation":"Thrown by `CreateContextParameters.background()` when the argument is not a boolean (`typeof background !== 'boolean'`). This is a strict boolean check, so truthy/falsy values like 0, 1, and 'true' are all rejected — only literal `true`/`false` pass.","triggerScenarios":"Calling `params.background(1)`, `params.background('true')`, or `params.background(undefined)`.","commonSituations":"Boolean sourced from config/env as a string ('true'/'false'); passing a numeric 0/1 from a flag.","solutions":["Pass a literal `true` or `false`","If sourced from config, convert explicitly: `String(val).toLowerCase() === 'true'`"],"exampleFix":"// before\nparams.background('true')\n// after\nparams.background(true)","handlingStrategy":"validation","validationCode":"if (typeof bg === 'boolean') params.background(bg)","typeGuard":"const isBoolean = (v) => typeof v === 'boolean'","tryCatchPattern":null,"preventionTips":["background() requires a real boolean, not 'true' or 1","Coerce config/env strings explicitly before passing"],"tags":["bidi","browsing-context","validation","boolean"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}