ScreenResolutionMismatchError
computer_use.errors.ScreenResolutionMismatchError
Stack trace
Traceback (most recent call last):
File "app.py", line 42, in main
screen.setup_resolution(expected_width, expected_height)
File "computer_use/screen.py", line 88, in setup_resolution
raise ScreenResolutionMismatchError(f"Expected {expected_width}x{expected_height}, but got {actual_width}x{actual_height}")
computer_use.errors.ScreenResolutionMismatchError: Expected 1920x1080, but got 1366x768 Why it happens
This error occurs when the software expects a specific screen resolution for proper UI layout or rendering, but the actual display resolution differs. It often happens when the system display settings or connected monitor do not match the configured or required resolution in the application.
Detection
Check the screen resolution values returned by the system API before applying UI layouts, and log any discrepancies between expected and actual resolutions to catch this error early.
Causes & fixes
The system display resolution is set lower than the application expects.
Adjust the system display settings to match the expected resolution or update the application configuration to accept the current resolution.
The application hardcodes a fixed resolution incompatible with the user's monitor.
Modify the application to dynamically detect and adapt to the current screen resolution instead of using hardcoded values.
Multiple monitors with different resolutions cause inconsistent resolution detection.
Implement multi-monitor support in the application to detect and handle each monitor's resolution separately.
Code: broken vs fixed
from computer_use.screen import Screen
screen = Screen()
expected_width, expected_height = 1920, 1080
screen.setup_resolution(expected_width, expected_height) # This line raises ScreenResolutionMismatchError import os
from computer_use.screen import Screen
screen = Screen()
expected_width, expected_height = 1920, 1080
actual_width, actual_height = screen.get_current_resolution()
# Fix: dynamically check and adapt to actual resolution
if (actual_width, actual_height) != (expected_width, expected_height):
print(f"Warning: Expected {expected_width}x{expected_height}, but got {actual_width}x{actual_height}. Adjusting settings.")
screen.setup_resolution(actual_width, actual_height) # Use actual resolution
else:
screen.setup_resolution(expected_width, expected_height)
print("Screen resolution setup complete.") Workaround
Catch the ScreenResolutionMismatchError exception, log the actual resolution, and fallback to a safe default resolution or prompt the user to adjust their display settings.
Prevention
Design the application to always query the current screen resolution dynamically and support multiple resolutions and monitors to avoid hardcoded assumptions.