-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (27 loc) · 980 Bytes
/
main.py
File metadata and controls
37 lines (27 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from dotenv import load_dotenv
from playwright.sync_api import Playwright, sync_playwright
from browserbase import Browserbase
load_dotenv()
BROWSERBASE_API_KEY = os.environ["BROWSERBASE_API_KEY"]
bb = Browserbase(api_key=BROWSERBASE_API_KEY)
def run(playwright: Playwright) -> None:
# Create a session on Browserbase
session = bb.sessions.create()
print("Session replay URL:", f"https://browserbase.com/sessions/{session.id}")
# Connect to the remote session
chromium = playwright.chromium
browser = chromium.connect_over_cdp(session.connect_url)
context = browser.contexts[0]
page = context.pages[0]
# Execute Playwright actions on the remote browser tab
page.goto("https://browserbase.com/")
page_title = page.title()
print(page_title)
# Close the browser
page.close()
browser.close()
print("Done!")
if __name__ == "__main__":
with sync_playwright() as playwright:
run(playwright)