ScreenshotToolError
computer_use.screenshot.ScreenshotToolError
Stack trace
Traceback (most recent call last):
File "capture.py", line 42, in capture_screenshot
screenshot = screenshot_tool.capture()
computer_use.screenshot.ScreenshotToolError: Failed to capture screenshot: Permission denied or unsupported platform Why it happens
Screenshot tools require OS-level permissions and compatible drivers to capture the screen. This error occurs when the tool lacks permissions, the OS is unsupported, or the graphics driver is incompatible or outdated.
Detection
Check for ScreenshotToolError exceptions during capture calls and log detailed error messages including OS and permission status before retrying or alerting the user.
Causes & fixes
The application lacks OS-level permission to capture the screen.
Grant the application screen capture permissions in the OS security settings or run the app with elevated privileges.
The screenshot tool does not support the current operating system or desktop environment.
Use a screenshot tool version compatible with the OS or switch to a cross-platform library that supports your environment.
Graphics drivers are outdated or incompatible, preventing screen capture.
Update the graphics drivers to the latest version supported by your hardware and OS.
The screenshot tool dependency is missing or improperly installed.
Ensure all required screenshot tool dependencies are installed correctly and match the expected versions.
Code: broken vs fixed
from computer_use.screenshot import ScreenshotTool
screenshot_tool = ScreenshotTool()
screenshot = screenshot_tool.capture() # This line raises ScreenshotToolError
print('Screenshot captured:', screenshot) import os
from computer_use.screenshot import ScreenshotTool, ScreenshotToolError
# Ensure environment variable or OS permission is set before capture
os.environ['SCREENSHOT_PERMISSION'] = 'granted'
screenshot_tool = ScreenshotTool()
try:
screenshot = screenshot_tool.capture() # Fixed: handle permissions and exceptions
print('Screenshot captured:', screenshot)
except ScreenshotToolError as e:
print('Failed to capture screenshot:', e) Workaround
Wrap the screenshot capture call in a try/except block catching ScreenshotToolError, then fallback to prompting the user to manually grant permissions or retry later.
Prevention
Design your application to check and request screen capture permissions at startup and use cross-platform screenshot libraries that handle OS differences gracefully.