Skip to content

Commit f9ce816

Browse files
committed
why are these headers necessary
1 parent eb6e5be commit f9ce816

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/selenium_basic.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ class BrowserbaseConnection(RemoteConnection):
1111
"""
1212

1313
browserbase_session: SessionCreateResponse
14+
session_id: str
1415

15-
def __init__(self, *args, **kwargs):
16-
self.browserbase_session = bb.sessions.create(project_id=BROWSERBASE_PROJECT_ID)
16+
def __init__(self, session_id: str, *args, **kwargs):
1717
super().__init__(*args, **kwargs)
18+
self.session_id = session_id
1819

1920
def get_remote_connection_headers(self, parsed_url, keep_alive=False):
2021
headers = super().get_remote_connection_headers(parsed_url, keep_alive)
2122

2223
# Update headers to include the Browserbase required information
2324
headers["x-bb-api-key"] = BROWSERBASE_API_KEY
24-
headers["session-id"] = self.browserbase_session.id
25+
headers["session-id"] = self.session_id
2526

2627
return headers
2728

@@ -37,7 +38,8 @@ def run(driver: WebDriver):
3738

3839

3940
# Use the custom class to create and connect to a new browser session
40-
connection = BrowserbaseConnection("http://connect.browserbase.com/webdriver")
41+
session = bb.sessions.create(project_id=BROWSERBASE_PROJECT_ID)
42+
connection = BrowserbaseConnection(session.id, session.selenium_remote_url)
4143
driver = webdriver.Remote(connection, options=webdriver.ChromeOptions())
4244

4345
# Print a bit of info about the browser we've connected to

0 commit comments

Comments
 (0)