{"record":{"id":"a237bd11f7047b18","repo":"SeleniumHQ/selenium","slug":"type-must-be-an-instance-of-string-received-ty","errorCode":null,"errorMessage":"Type must be an instance of String. Received:'${type}'","messagePattern":"Type must be an instance of String\\. Received:'(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/captureScreenshotParameters.js","lineNumber":62,"sourceCode":"  origin(origin) {\n    if (origin !== Origin.VIEWPORT && origin !== Origin.DOCUMENT) {\n      throw new Error(`Origin must be one of ${Object.values(Origin)}. Received:'${origin}'`)\n    }\n    this.#map.set('origin', origin)\n    return this\n  }\n\n  /**\n   * Sets the image format and quality for capturing a screenshot.\n   *\n   * @param {string} type - The image format type.\n   * @param {number} [quality] - The image quality (optional).\n   * @throws {Error} If the type is not a string or if the quality is not a number.\n   * @returns {CaptureScreenshotParameters} - The current instance of the CaptureScreenshotParameters for chaining.\n   */\n  imageFormat(type, quality = undefined) {\n    if (typeof type !== 'string') {\n      throw new Error(`Type must be an instance of String. Received:'${type}'`)\n    }\n\n    this.#map.set('type', type)\n\n    if (quality !== undefined) {\n      if (typeof quality !== 'number') {\n        throw new Error(`Quality must be a number. Received:'${quality}'`)\n      }\n      this.#map.set('quality', quality)\n    }\n    return this\n  }\n\n  /**\n   * Sets the clip rectangle for capturing a screenshot.\n   *\n   * @param {BoxClipRectangle|ElementClipRectangle} clipRectangle - The clip rectangle to set.\n   * @throws {Error} If the clipRectangle is not an instance of ClipRectangle.","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/captureScreenshotParameters.js#L44-L80","documentation":"CaptureScreenshotParameters.imageFormat() validates the first argument (type) is a primitive string (typeof === 'string') before setting it as the image format. This is the format/codec selector (e.g. 'png', 'jpeg'). Passing a number, object, null, undefined, or a String wrapper object fails the typeof check. Note this only validates that type is a string, not that it is a supported format — unsupported formats are caught later server-side (error [15]).","triggerScenarios":"Calling imageFormat(undefined) or imageFormat(null) for the type. Passing a numeric or object value. Passing a String object wrapper (typeof 'object'). Forgetting the type argument when also wanting to set quality.","commonSituations":"Calling imageFormat(quality) positionally (passing quality where type belongs). Config code forwarding a non-string. Building the call dynamically and omitting the type.","solutions":["Pass a primitive string format as the first argument: imageFormat('png') or imageFormat('jpeg', 80).","If you only want to set quality, you must still supply a type string first.","Use lowercase canonical format names ('png', 'jpeg').","Validate config values are strings before forwarding."],"exampleFix":"// before\nparams.imageFormat(80) // number where type string expected\n\n// after\nparams.imageFormat('jpeg', 80)","handlingStrategy":"type-guard","validationCode":"if (typeof type !== 'string') {\n  throw new TypeError('imageFormat type must be a string (e.g. png, jpeg)')\n}","typeGuard":"function isImageFormatType(t) {\n  return typeof t === 'string'\n}","tryCatchPattern":null,"preventionTips":["Always pass the format string as the first argument.","Use canonical lowercase names ('png','jpeg').","Validate config values are strings before forwarding.","Avoid String object wrappers."],"tags":["bidi","screenshot","validation","string","image-format"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}