{"record":{"id":"7fe9bbf8493b56ca","repo":"SeleniumHQ/selenium","slug":"origin-must-be-one-of-object-values-origin-re","errorCode":null,"errorMessage":"Origin must be one of ${Object.values(Origin)}. Received:'${origin}'","messagePattern":"Origin must be one of (.+?)\\. Received:'(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/captureScreenshotParameters.js","lineNumber":46,"sourceCode":"}\n\n/**\n * Represents the optional parameters for capturing a screenshot.\n * Described in https://w3c.github.io/webdriver-bidi/#command-browsingContext-captureScreenshot.\n */\nclass CaptureScreenshotParameters {\n  #map = new Map()\n\n  /**\n   * Sets the origin for capturing the screenshot.\n   *\n   * @param {Origin} origin - The origin for capturing the screenshot. Must be one of `Origin.VIEWPORT` or `Origin.DOCUMENT`.\n   * @returns {CaptureScreenshotParameters} - The current instance of the CaptureScreenshotParameters for chaining.\n   * @throws {Error} - If the provided origin is not valid.\n   */\n  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","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/captureScreenshotParameters.js#L28-L64","documentation":"CaptureScreenshotParameters.origin() validates that the origin argument is exactly Origin.VIEWPORT ('viewport') or Origin.DOCUMENT ('document') — the only two values defined in the Origin enum. Any other value (including typos like 'Viewport', 'document' with different casing handled, 'page', null, undefined, numbers) throws. The error message lists the valid enum values via Object.values(Origin).","triggerScenarios":"Calling origin('page') or origin('screen') with an unsupported value. Passing a typo or wrong-cased string. Passing null/undefined/number. Passing a computed value from config that does not match either enum constant.","commonSituations":"Assuming more origin types exist than the spec defines. Config-driven code passing an unconstrained string. Case-sensitivity mistakes (the enum values are lowercase).","solutions":["Use the Origin enum constants: Origin.VIEWPORT or Origin.DOCUMENT from captureScreenshotParameters.js.","If origin is optional for your use case, simply omit the .origin() call rather than passing a guess.","Validate/whitelist config values against [Origin.VIEWPORT, Origin.DOCUMENT] before forwarding.","Default to Origin.VIEWPORT when unsure."],"exampleFix":"// before\nparams.origin('page')\n\n// after\nconst { Origin } = require('selenium-webdriver/bidi/captureScreenshotParameters')\nparams.origin(Origin.VIEWPORT)","handlingStrategy":"type-guard","validationCode":"const VALID_ORIGINS = [Origin.VIEWPORT, Origin.DOCUMENT]\nif (!VALID_ORIGINS.includes(origin)) {\n  throw new TypeError('origin must be Origin.VIEWPORT or Origin.DOCUMENT')\n}","typeGuard":"function isValidOrigin(o) {\n  return o === Origin.VIEWPORT || o === Origin.DOCUMENT\n}","tryCatchPattern":null,"preventionTips":["Always reference the Origin enum constants, never raw guesses.","Omit .origin() if viewport default is acceptable.","Whitelist config values against the two enum constants.","Remember values are lowercase."],"tags":["bidi","screenshot","validation","enum","origin"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}