Skip to content

Commit 3ba5bcc

Browse files
Add sync and async browser-use task examples
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 4c1d79e commit 3ba5bcc

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ Contributor workflow details are available in [CONTRIBUTING.md](CONTRIBUTING.md)
258258
Ready-to-run examples are available in `examples/`:
259259

260260
- `examples/async_batch_fetch.py`
261+
- `examples/async_browser_use_task.py`
261262
- `examples/async_crawl.py`
262263
- `examples/async_extension_create.py`
263264
- `examples/async_extension_list.py`
@@ -271,6 +272,7 @@ Ready-to-run examples are available in `examples/`:
271272
- `examples/async_web_fetch.py`
272273
- `examples/async_web_search.py`
273274
- `examples/sync_batch_fetch.py`
275+
- `examples/sync_browser_use_task.py`
274276
- `examples/sync_crawl.py`
275277
- `examples/sync_extension_create.py`
276278
- `examples/sync_extension_list.py`

examples/async_browser_use_task.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Asynchronous browser-use task example.
3+
4+
Run:
5+
export HYPERBROWSER_API_KEY="your_api_key"
6+
python3 examples/async_browser_use_task.py
7+
"""
8+
9+
import asyncio
10+
11+
from hyperbrowser import AsyncHyperbrowser
12+
from hyperbrowser.models.agents.browser_use import StartBrowserUseTaskParams
13+
14+
15+
async def main() -> None:
16+
async with AsyncHyperbrowser() as client:
17+
result = await client.agents.browser_use.start_and_wait(
18+
StartBrowserUseTaskParams(
19+
task="Open https://example.com and return the page title.",
20+
)
21+
)
22+
print(f"Job status: {result.status}")
23+
if result.output is not None:
24+
print(f"Task output: {result.output}")
25+
26+
27+
if __name__ == "__main__":
28+
asyncio.run(main())

examples/sync_browser_use_task.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Synchronous browser-use task example.
3+
4+
Run:
5+
export HYPERBROWSER_API_KEY="your_api_key"
6+
python3 examples/sync_browser_use_task.py
7+
"""
8+
9+
from hyperbrowser import Hyperbrowser
10+
from hyperbrowser.models.agents.browser_use import StartBrowserUseTaskParams
11+
12+
13+
def main() -> None:
14+
with Hyperbrowser() as client:
15+
result = client.agents.browser_use.start_and_wait(
16+
StartBrowserUseTaskParams(
17+
task="Open https://example.com and return the page title.",
18+
)
19+
)
20+
print(f"Job status: {result.status}")
21+
if result.output is not None:
22+
print(f"Task output: {result.output}")
23+
24+
25+
if __name__ == "__main__":
26+
main()

0 commit comments

Comments
 (0)