{"record":{"id":"a77bf9c50499f84d","repo":"SeleniumHQ/selenium","slug":"referencecontext-must-be-string-received-id","errorCode":null,"errorMessage":"ReferenceContext must be string. Received:'${id}'","messagePattern":"ReferenceContext must be string\\. Received:'(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/createContextParameters.js","lineNumber":33,"sourceCode":"// specific language governing permissions and limitations\n// under the License.\n\n/**\n * Represents a set of parameters for creating a context.\n * Described in https://w3c.github.io/webdriver-bidi/#command-browsingContext-create.\n */\nclass CreateContextParameters {\n  #map = new Map()\n\n  /**\n   * Sets the reference context.\n   * @param {string} id - The ID of the reference context.\n   * @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining.\n   * @throws {Error} - If the provided ID is not a string.\n   */\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","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/createContextParameters.js#L15-L51","documentation":"Thrown by `CreateContextParameters.referenceContext()` when the argument is not a string (`typeof id !== 'string'`). The reference context id must be the string id of an existing browsing context.","triggerScenarios":"Calling `params.referenceContext(undefined)`, `params.referenceContext(123)`, or passing a window/context object instead of its id string.","commonSituations":"Passing a context object or numeric id instead of the BiDi context id string; undefined when no parent context was chosen.","solutions":["Pass the string browsing-context id returned by a create/open context command","Ensure the id variable is a defined string"],"exampleFix":"// before\nparams.referenceContext(driver.getWindowHandle()) // may be non-string in BiDi\n// after\nparams.referenceContext(contextId) // contextId is a string from bidi","handlingStrategy":"validation","validationCode":"if (typeof id === 'string') params.referenceContext(id)","typeGuard":"const isContextId = (id) => typeof id === 'string'","tryCatchPattern":null,"preventionTips":["BiDi context ids are strings — pass the id, not a handle object","typeof-check before calling when the source is dynamic"],"tags":["bidi","browsing-context","validation","string","reference-context"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}