{"record":{"id":"688e6654e907f172","repo":"SeleniumHQ/selenium","slug":"unsupported-format-format-inspect","errorCode":null,"errorMessage":"unsupported format: #{format.inspect}","messagePattern":"unsupported format: #(.+?)","errorType":"exception","errorClass":"Error::UnsupportedOperationError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/takes_screenshot.rb","lineNumber":63,"sourceCode":"      #\n      # @param [:base64, :png] format\n      # @param [Boolean] full_page allows taking full page screenshots if supported\n      # @return String screenshot\n      #\n      # @api public\n\n      def screenshot_as(format, full_page: false)\n        if full_page && !respond_to?(:save_full_page_screenshot)\n          raise Error::UnsupportedOperationError, \"Full Page Screenshots are not supported for #{inspect}\"\n        end\n\n        case format\n        when :base64\n          full_page ? full_screenshot : screenshot\n        when :png\n          screenshot_as(:base64, full_page: full_page).unpack1('m')\n        else\n          raise Error::UnsupportedOperationError, \"unsupported format: #{format.inspect}\"\n        end\n      end\n    end # TakesScreenshot\n  end # WebDriver\nend # Selenium\n","sourceCodeStart":45,"sourceCodeEnd":69,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/takes_screenshot.rb#L45-L69","documentation":"Raised by TakesScreenshot#screenshot_as when the format argument is neither :base64 nor :png. The method uses a case statement on format; only these two symbols are handled. Any other value (a string, an integer, nil, another symbol) falls through to the else branch raising UnsupportedOperationError.","triggerScenarios":"Calling driver.screenshot_as('png') with a string instead of a symbol. Calling driver.screenshot_as(:jpeg) or :jpg (JPEG is not supported; Selenium screenshots are always PNG). Calling driver.screenshot_as(nil) due to a variable that wasn't set.","commonSituations":"Passing a file extension string like 'png' or 'jpg' instead of the symbol :png. Assuming JPEG output is available. Variable-based format that defaults to nil or a string.","solutions":["Use :png or :base64 as the format argument.","Prefer driver.save_screenshot(path) for file output — it handles the format internally.","If accepting format from user input, validate against [:base64, :png] before calling."],"exampleFix":"// before\nscreenshot = driver.screenshot_as('png')  # string, not symbol\ndata = driver.screenshot_as(:jpeg)          # unsupported format\n\n// after\nscreenshot = driver.screenshot_as(:png)\n# or for base64:\nscreenshot = driver.screenshot_as(:base64)","handlingStrategy":"validation","validationCode":"VALID_FORMATS = %i[base64 png].freeze\n\ndef screenshot_safe(driver, format)\n  format = format.to_sym\n  raise ArgumentError, \"Unsupported screenshot format: #{format}. Use :base64 or :png.\" unless VALID_FORMATS.include?(format)\n  driver.screenshot_as(format)\nend","typeGuard":"def valid_screenshot_format?(format)\n  %i[base64 png].include?(format.to_sym)\nend","tryCatchPattern":"begin\n  data = driver.screenshot_as(format)\nrescue Selenium::WebDriver::Error::UnsupportedOperationError => e\n  raise unless e.message.include?('unsupported format')\n  data = driver.screenshot_as(:png)  # safe default\nend","preventionTips":["Always pass symbols (:base64 or :png), never strings.","Prefer driver.save_screenshot(path) for file output — it handles format internally.","If format comes from user/config input, validate against [:base64, :png] before calling."],"tags":["screenshot","format","argument-error","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}