mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
Add file saving option to screenshot action
When name parameter is provided, screenshot saves to file and returns path
instead of base64 data. This prevents huge MCP responses.
Usage: computer(action='screenshot', name='screen.png')
Returns: {path: '/tmp/screen.png', size: ...}
This commit is contained in:
@@ -922,6 +922,27 @@ Examples:
|
||||
# Screen actions
|
||||
elif action == "screenshot" or action == "screenshot_region":
|
||||
data = await run(NativeControl.screenshot_native, region)
|
||||
|
||||
# If name is provided, save to file instead of returning base64
|
||||
if name:
|
||||
# Expand ~ and make absolute path
|
||||
file_path = os.path.expanduser(name)
|
||||
if not os.path.isabs(file_path):
|
||||
file_path = os.path.join(tempfile.gettempdir(), name)
|
||||
if not file_path.endswith('.png'):
|
||||
file_path += '.png'
|
||||
|
||||
with open(file_path, 'wb') as f:
|
||||
f.write(data)
|
||||
|
||||
return json.dumps({
|
||||
"success": True,
|
||||
"format": "png",
|
||||
"size": len(data),
|
||||
"path": file_path,
|
||||
})
|
||||
|
||||
# Otherwise return base64 (large output warning)
|
||||
b64 = base64.b64encode(data).decode()
|
||||
return json.dumps({
|
||||
"success": True,
|
||||
|
||||
Reference in New Issue
Block a user