You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While you can provide an `api_key` keyword argument,
45
-
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
46
-
to add `BROWSERBASE_API_KEY="My API Key"` to your `.env` file
47
-
so that your API Key is not stored in source control.
52
+
# Execute Playwright actions on the remote browser tab
53
+
page.goto("https://news.ycombinator.com/")
54
+
page_title = page.title()
55
+
assert (
56
+
page_title =="Hacker News"
57
+
), f"Page title is not 'Hacker News', it is '{page_title}'"
58
+
page.screenshot(path="screenshot.png")
59
+
60
+
page.close()
61
+
browser.close()
62
+
print("Done!")
63
+
64
+
65
+
if__name__=="__main__":
66
+
with sync_playwright() as playwright:
67
+
run(playwright)
68
+
69
+
```
48
70
49
71
## Examples
50
72
@@ -63,33 +85,6 @@ rye run example playwright_basic # replace with the example you want to run
63
85
> [!NOTE]
64
86
> Make sure you have a `.env` file that matches the [.env.example](.env.example) file in the root of this repository.
65
87
66
-
## Async usage
67
-
68
-
Simply import `AsyncBrowserbase` instead of `Browserbase` and use `await` with each API call:
69
-
70
-
```python
71
-
import os
72
-
import asyncio
73
-
from browserbase import AsyncBrowserbase
74
-
75
-
client = AsyncBrowserbase(
76
-
# This is the default and can be omitted
77
-
api_key=os.environ.get("BROWSERBASE_API_KEY"),
78
-
)
79
-
80
-
81
-
asyncdefmain() -> None:
82
-
context =await client.contexts.create(
83
-
project_id="projectId",
84
-
)
85
-
print(context.id)
86
-
87
-
88
-
asyncio.run(main())
89
-
```
90
-
91
-
Functionality between the synchronous and asynchronous clients is otherwise identical.
92
-
93
88
## Using types
94
89
95
90
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
0 commit comments