Capture Components¶
The capture module provides screenshot capture capabilities for web pages and batch processing of multiple URLs.
Capture¶
- class layoutlens.capture.Capture(output_dir: str | Path = 'screenshots', timeout: int = 30000)[source]¶
Bases:
objectSimple screenshot capture system using Playwright.
One method handles everything - single URLs are just lists of 1 item.
- VIEWPORTS = {'desktop': ViewportConfig(name='desktop', width=1920, height=1080, device_scale_factor=1.0, is_mobile=False, has_touch=False, user_agent=None), 'laptop': ViewportConfig(name='laptop', width=1366, height=768, device_scale_factor=1.0, is_mobile=False, has_touch=False, user_agent=None), 'mobile': ViewportConfig(name='mobile', width=375, height=667, device_scale_factor=2.0, is_mobile=True, has_touch=True, user_agent=None), 'mobile_landscape': ViewportConfig(name='mobile_landscape', width=667, height=375, device_scale_factor=2.0, is_mobile=True, has_touch=True, user_agent=None), 'mobile_portrait': ViewportConfig(name='mobile_portrait', width=375, height=667, device_scale_factor=2.0, is_mobile=True, has_touch=True, user_agent=None), 'tablet': ViewportConfig(name='tablet', width=768, height=1024, device_scale_factor=2.0, is_mobile=True, has_touch=True, user_agent=None)}¶
- __init__(output_dir: str | Path = 'screenshots', timeout: int = 30000)[source]¶
Initialize capture system.
- async screenshots(urls: list[str], viewport: str = 'desktop', max_concurrent: int = 3, wait_for_selector: str | None = None, wait_time: int | None = None) list[str][source]¶
Capture screenshots from URLs.
Simple interface: give it URLs, get back screenshot paths. Single URL? Pass a list with 1 item. Multiple URLs? Pass a list.
- Parameters:
urls – List of URLs to capture (can be single URL in list)
viewport – Viewport name (desktop, mobile, etc.)
max_concurrent – Maximum concurrent captures
wait_for_selector – CSS selector to wait for
wait_time – Additional wait time in milliseconds
- Returns:
List of screenshot paths in same order as input URLs
Examples
# Single URL paths = await capture.screenshots([”https://example.com”]) # Returns: [“/path/to/screenshot.png”]
# Multiple URLs paths = await capture.screenshots([“url1”, “url2”]) # Returns: [“/path1.png”, “/path2.png”]