Skip to content

feat: web screenshot tool and file-download support#288

Open
philipph-askui wants to merge 2 commits into
mainfrom
feat/web-tools
Open

feat: web screenshot tool and file-download support#288
philipph-askui wants to merge 2 commits into
mainfrom
feat/web-tools

Conversation

@philipph-askui

Copy link
Copy Markdown
Contributor

Summary

Adds two web-automation capabilities to the SDK:

  1. WebSaveScreenshotTool — importable from askui.tools.store.web. Saves a screenshot of the currently active browser page to disk as a PNG. Analogous to ComputerSaveScreenshotTool, but extends PlaywrightBaseTool so the capture comes from the Playwright page.

  2. Automatic downloads — a new download_dir parameter on WebAgent / PlaywrightAgentOs. When set, every file the browser downloads is automatically copied into that directory once it finishes, under its browser-suggested filename, auto-renamed on collision (report (1).pdf, …) so nothing is overwritten. A downloaded_files property exposes the saved paths.

Why this design for downloads

  • The click that triggers a download and the save are decoupled across the agent's tool calls, so page.expect_download() (which wraps the click) doesn't fit. Instead a persistent download event listener registered in connect() captures every download.
  • Playwright deletes its temporary download files when the browser context closes, so files are copied while the context is still open, inside the event handler (verified that save_as() works there and auto-creates parent dirs).
  • Save failures are reported but never propagated — a failed download cannot break an automation run.
  • The server-suggested filename is reduced to its basename to guard against path traversal.

When download_dir is None (default), behaviour is unchanged.

Tests

  • tests/unit/tools/playwright/test_agent_os.py — unit tests for the collision-aware unique-path helper.
  • tests/e2e/tools/playwright/test_download.py — real headless-Chromium tests: download copied into download_dir, collision auto-rename leaves the original intact, and download_dir=None leaves nothing behind.

pdm run qa:fix is clean (typecheck, lint, format); unit + e2e download tests pass.

Known limitation

The download listener is attached to the main page only; downloads triggered in a popup/new tab are not captured yet. Can extend to context-level page tracking if needed.

🤖 Generated with Claude Code

philipph-askui and others added 2 commits June 25, 2026 18:46
Add a WebSaveScreenshotTool, importable from askui.tools.store.web, that
saves a screenshot of the currently active browser page to disk as a PNG.
It mirrors ComputerSaveScreenshotTool but extends PlaywrightBaseTool so the
screenshot is captured from the Playwright page.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a `download_dir` parameter to `WebAgent` and `PlaywrightAgentOs`. When
set, every file downloaded by the browser is automatically copied into that
directory once it finishes, saved under its browser-suggested filename and
auto-renamed on collision (e.g. `report (1).pdf`) so nothing is overwritten.

This is implemented via a persistent page `download` event listener rather
than `expect_download`, because the click that triggers a download and the
save are decoupled across the agent's tool calls. Files are copied while the
browser context is still open, since Playwright deletes the temporary
download files when the context closes. Save failures are reported but never
propagated, so a failed download cannot break an automation run.

A `downloaded_files` property exposes the saved paths for programmatic use.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@philipph-askui philipph-askui changed the title feat: web screenshot tool and auto-download support feat: web screenshot tool and file-download support Jun 25, 2026
@programminx-askui programminx-askui self-requested a review June 25, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants