|
5 | 5 | import json |
6 | 6 | import os |
7 | 7 | import time |
8 | | -from typing import Any |
| 8 | +from typing import Any, Optional |
9 | 9 |
|
10 | 10 | import requests |
11 | 11 |
|
@@ -41,41 +41,33 @@ def _save_trace_to_file(raw_elements: list[dict[str, Any]], trace_path: str | No |
41 | 41 |
|
42 | 42 | def snapshot( |
43 | 43 | browser: SentienceBrowser, |
44 | | - screenshot: bool | None = None, |
45 | | - limit: int | None = None, |
46 | | - filter: dict[str, Any] | None = None, |
47 | | - use_api: bool | None = None, |
48 | | - save_trace: bool = False, |
49 | | - trace_path: str | None = None, |
50 | | - show_overlay: bool = False, |
| 44 | + options: Optional[SnapshotOptions] = None, |
51 | 45 | ) -> Snapshot: |
52 | 46 | """ |
53 | 47 | Take a snapshot of the current page |
54 | 48 |
|
55 | 49 | Args: |
56 | 50 | browser: SentienceBrowser instance |
57 | | - screenshot: Whether to capture screenshot (bool or dict with format/quality) |
58 | | - limit: Limit number of elements returned |
59 | | - filter: Filter options (min_area, allowed_roles, min_z_index) |
60 | | - use_api: Force use of server-side API if True, local extension if False. |
61 | | - If None, uses API if api_key is set, otherwise uses local extension. |
62 | | - save_trace: Whether to save raw_elements to JSON for benchmarking/training |
63 | | - trace_path: Path to save trace file. If None, uses "trace_{timestamp}.json" |
64 | | - show_overlay: Show visual overlay highlighting elements in browser |
| 51 | + options: Snapshot options (screenshot, limit, filter, etc.) |
| 52 | + If None, uses default options. |
65 | 53 |
|
66 | 54 | Returns: |
67 | 55 | Snapshot object |
| 56 | +
|
| 57 | + Example: |
| 58 | + # Basic snapshot with defaults |
| 59 | + snap = snapshot(browser) |
| 60 | +
|
| 61 | + # With options |
| 62 | + snap = snapshot(browser, SnapshotOptions( |
| 63 | + screenshot=True, |
| 64 | + limit=100, |
| 65 | + show_overlay=True |
| 66 | + )) |
68 | 67 | """ |
69 | | - # Build SnapshotOptions from individual parameters |
70 | | - options = SnapshotOptions( |
71 | | - screenshot=screenshot if screenshot is not None else False, |
72 | | - limit=limit if limit is not None else 50, |
73 | | - filter=filter, |
74 | | - use_api=use_api, |
75 | | - save_trace=save_trace, |
76 | | - trace_path=trace_path, |
77 | | - show_overlay=show_overlay, |
78 | | - ) |
| 68 | + # Use default options if none provided |
| 69 | + if options is None: |
| 70 | + options = SnapshotOptions() |
79 | 71 |
|
80 | 72 | # Determine if we should use server-side API |
81 | 73 | should_use_api = ( |
|
0 commit comments