{"record":{"id":"37faf70ffa865fd8","repo":"SeleniumHQ/selenium","slug":"quality-must-be-a-number-received-quality","errorCode":null,"errorMessage":"Quality must be a number. Received:'${quality}'","messagePattern":"Quality must be a number\\. Received:'(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/captureScreenshotParameters.js","lineNumber":69,"sourceCode":"\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.\n   * @returns {CaptureScreenshotParameters} - The current instance of the CaptureScreenshotParameters for chaining.\n   */\n  clipRectangle(clipRectangle) {\n    if (!(clipRectangle instanceof BoxClipRectangle || clipRectangle instanceof ElementClipRectangle)) {\n      throw new Error(`ClipRectangle must be an instance of ClipRectangle. Received:'${clipRectangle}'`)\n    }\n    this.#map.set('clip', Object.fromEntries(clipRectangle.asMap()))","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/captureScreenshotParameters.js#L51-L87","documentation":"CaptureScreenshotParameters.imageFormat() optionally accepts a quality number as its second argument. When quality is not undefined, it validates typeof quality === 'number'. Passing a string (e.g. '80'), a boolean, null, an object, or NaN-equivalent fails the check. Quality is meaningful only for lossy formats (jpeg); it represents compression quality, conventionally 0–100.","triggerScenarios":"Calling imageFormat('jpeg', '80') with a string quality. Passing null as quality (null is not undefined, typeof 'object'). Passing a boolean. Passing quality from config as a string. Passing NaN.","commonSituations":"Config/CLI values arriving as strings (e.g. env vars, JSON parsed loosely). Forgetting to Number()-convert. Passing null to mean 'default' instead of omitting the argument.","solutions":["Pass a primitive number for quality, or omit it entirely: imageFormat('jpeg', 80) or imageFormat('png').","Convert string config values with Number() and verify isFinite() before passing.","Use undefined (omit) rather than null when you want the default.","Keep quality within [0,100] to avoid downstream server rejection."],"exampleFix":"// before\nparams.imageFormat('jpeg', '80')\n\n// after\nparams.imageFormat('jpeg', Number(qualityStr))","handlingStrategy":"type-guard","validationCode":"if (quality !== undefined && (typeof quality !== 'number' || !isFinite(quality))) {\n  throw new TypeError('imageFormat quality must be a finite number')\n}","typeGuard":"function isValidQuality(q) {\n  return q === undefined || (typeof q === 'number' && isFinite(q))\n}","tryCatchPattern":null,"preventionTips":["Pass a primitive number for quality or omit it.","Number()-convert and isFinite()-check config strings.","Use undefined (omit) rather than null for the default.","Keep quality in [0,100]."],"tags":["bidi","screenshot","validation","number","image-format"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}