22from typing import Any , Dict
33
44from playwright .sync_api import Page , Playwright , sync_playwright
5+ from pydantic import TypeAdapter
56
67from examples import (
78 BROWSERBASE_API_KEY ,
2021
2122
2223def check_proxy_bytes (session_id : str ) -> None :
24+ bb .sessions .update (
25+ id = session_id , project_id = BROWSERBASE_PROJECT_ID , status = "REQUEST_RELEASE"
26+ )
2327 time .sleep (GRACEFUL_SHUTDOWN_TIMEOUT / 1000 )
2428 updated_session = bb .sessions .retrieve (id = session_id )
29+ print ("UPDATED SESSION" , updated_session )
2530 assert (
2631 updated_session .proxy_bytes is not None and updated_session .proxy_bytes > 0
2732 ), f"Proxy bytes: { updated_session .proxy_bytes } "
@@ -35,7 +40,7 @@ def generate_proxy_config(proxy_data: Dict[str, Any]) -> ProxiesUnionMember1:
3540 :return: An instance of ProxiesUnionMember1
3641 """
3742 if proxy_data .get ("type" ) == "browserbase" :
38- for key in ["geolocation" , "domainPattern" ]:
43+ for key in ["geolocation" ]:
3944 if proxy_data .get (key ) is None :
4045 raise ValueError (f"Missing required key in proxy config: { key } " )
4146
@@ -53,7 +58,7 @@ def generate_proxy_config(proxy_data: Dict[str, Any]) -> ProxiesUnionMember1:
5358 ),
5459 )
5560 elif proxy_data .get ("type" ) == "external" :
56- for key in ["server" , "domainPattern" , " username" , "password" ]:
61+ for key in ["server" , "username" , "password" ]:
5762 if proxy_data .get (key ) is None :
5863 raise ValueError (f"Missing required key in proxy config: { key } " )
5964 return ProxiesUnionMember1ExternalProxyConfig (
@@ -121,12 +126,11 @@ def run_geolocation_country(playwright: Playwright) -> None:
121126 session = bb .sessions .create (
122127 project_id = BROWSERBASE_PROJECT_ID ,
123128 proxies = [
124- generate_proxy_config (
129+ TypeAdapter ( ProxiesUnionMember1 ). validate_python (
125130 {
126- "geolocation" : {
127- "country" : "CA" ,
128- },
131+ "geolocation" : {"country" : "CA" },
129132 "type" : "browserbase" ,
133+ "test" : "swag" ,
130134 }
131135 )
132136 ],
@@ -244,8 +248,8 @@ def run_geolocation_non_american_city(playwright: Playwright) -> None:
244248if __name__ == "__main__" :
245249 with sync_playwright () as playwright :
246250 run_enable_via_create_session (playwright )
247- run_enable_via_querystring_with_created_session (playwright )
248- run_geolocation_country (playwright )
249- run_geolocation_state (playwright )
250- run_geolocation_american_city (playwright )
251- run_geolocation_non_american_city (playwright )
251+ # run_enable_via_querystring_with_created_session(playwright)
252+ # run_geolocation_country(playwright)
253+ # run_geolocation_state(playwright)
254+ # run_geolocation_american_city(playwright)
255+ # run_geolocation_non_american_city(playwright)
0 commit comments