SeleniumHQ/selenium · error · Error
Origin must be one of ${Object.values(Origin)}. Received:'${
Error message
Origin must be one of ${Object.values(Origin)}. Received:'${origin}' What it means
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).
Source
Thrown at javascript/selenium-webdriver/bidi/captureScreenshotParameters.js:46
}
/**
* Represents the optional parameters for capturing a screenshot.
* Described in https://w3c.github.io/webdriver-bidi/#command-browsingContext-captureScreenshot.
*/
class CaptureScreenshotParameters {
#map = new Map()
/**
* Sets the origin for capturing the screenshot.
*
* @param {Origin} origin - The origin for capturing the screenshot. Must be one of `Origin.VIEWPORT` or `Origin.DOCUMENT`.
* @returns {CaptureScreenshotParameters} - The current instance of the CaptureScreenshotParameters for chaining.
* @throws {Error} - If the provided origin is not valid.
*/
origin(origin) {
if (origin !== Origin.VIEWPORT && origin !== Origin.DOCUMENT) {
throw new Error(`Origin must be one of ${Object.values(Origin)}. Received:'${origin}'`)
}
this.#map.set('origin', origin)
return this
}
/**
* Sets the image format and quality for capturing a screenshot.
*
* @param {string} type - The image format type.
* @param {number} [quality] - The image quality (optional).
* @throws {Error} If the type is not a string or if the quality is not a number.
* @returns {CaptureScreenshotParameters} - The current instance of the CaptureScreenshotParameters for chaining.
*/
imageFormat(type, quality = undefined) {
if (typeof type !== 'string') {
throw new Error(`Type must be an instance of String. Received:'${type}'`)
}
View on GitHub (pinned to aa36b38e69)
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.
Example fix
// before
params.origin('page')
// after
const { Origin } = require('selenium-webdriver/bidi/captureScreenshotParameters')
params.origin(Origin.VIEWPORT) Defensive patterns
Strategy: type-guard
Validate before calling
const VALID_ORIGINS = [Origin.VIEWPORT, Origin.DOCUMENT]
if (!VALID_ORIGINS.includes(origin)) {
throw new TypeError('origin must be Origin.VIEWPORT or Origin.DOCUMENT')
} Type guard
function isValidOrigin(o) {
return o === Origin.VIEWPORT || o === Origin.DOCUMENT
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Assuming more origin types exist than the spec defines. Config-driven code passing an unconstrained string. Case-sensitivity mistakes (the enum values are lowercase).
Related errors
- Type must be an instance of String. Received:'${type}'
- Quality must be a number. Received:'${quality}'
- ClipRectangle must be an instance of ClipRectangle. Received
- Params must be a value in SameSite. Received:'${sameSite}'
- Invalid permission state. Must be one of: ${Object.values(Pe
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/7fe9bbf8493b56ca.
Report an issue: GitHub.