High severity intermediate · Fix: 5-10 min

ScreenshotEncodingError

browser_use.errors.ScreenshotEncodingError

What this error means
The browser-use SDK failed to encode the captured screenshot into the expected image format, causing the screenshot process to error out.

Stack trace

traceback
browser_use.errors.ScreenshotEncodingError: Failed to encode screenshot image: unsupported format or corrupted data
  File "/app/browser_use/capture.py", line 87, in capture_screenshot
    encoded_image = encode_image(raw_image, format='png')
  File "/app/browser_use/encoding.py", line 45, in encode_image
    raise ScreenshotEncodingError("Failed to encode screenshot image: unsupported format or corrupted data")
QUICK FIX
Ensure the screenshot encoding format is set to 'png' and Pillow is installed and up to date.

Why it happens

This error occurs when the raw screenshot data captured from the browser cannot be properly encoded into the target image format (e.g., PNG or JPEG). Causes include corrupted raw image data, unsupported image formats, or missing image encoding libraries.

Detection

Monitor screenshot capture logs for ScreenshotEncodingError exceptions and validate that raw image buffers are non-empty and in a supported format before encoding.

Causes & fixes

1

Raw screenshot data is corrupted or incomplete due to browser capture failure

✓ Fix

Add validation to check raw image data integrity before encoding and retry capture if data is invalid.

2

Unsupported image format requested for encoding (e.g., 'bmp' not supported)

✓ Fix

Use a supported image format like 'png' or 'jpeg' explicitly when calling the encoding function.

3

Required image encoding libraries (e.g., Pillow) are missing or outdated

✓ Fix

Install or upgrade the Pillow library with 'pip install --upgrade Pillow' to ensure encoding support.

Code: broken vs fixed

Broken - triggers the error
python
from browser_use import capture_screenshot

image_data = capture_screenshot(format='bmp')  # triggers ScreenshotEncodingError
print('Screenshot captured')
Fixed - works correctly
python
import os
from browser_use import capture_screenshot

os.environ['BROWSER_USE_API_KEY'] = os.getenv('BROWSER_USE_API_KEY')  # Use env var for API key

image_data = capture_screenshot(format='png')  # fixed format to supported 'png'
print('Screenshot captured successfully')
Changed the screenshot encoding format from unsupported 'bmp' to supported 'png' and ensured environment variable usage for API keys.

Workaround

Catch ScreenshotEncodingError exceptions, log the raw image data size and type, then retry the screenshot capture with a fallback format like 'png'.

Prevention

Always validate raw screenshot data before encoding and use supported image formats with up-to-date encoding libraries to avoid encoding failures.

Python 3.9+ · browser-use-sdk >=1.0.0 · tested on 1.5.2
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.