11"""Utilities to handle redirection to browser UI."""
22
3- import time
4- import webbrowser
5-
63from reflex import constants
7- from reflex .utils import net
8-
9- from . import console
4+ from reflex .utils import console
105
116
127def open_browser (target_url : str ) -> None :
@@ -15,6 +10,8 @@ def open_browser(target_url: str) -> None:
1510 Args:
1611 target_url: The URL to open in the browser.
1712 """
13+ import webbrowser
14+
1815 if not webbrowser .open (target_url ):
1916 console .warn (
2017 f"Unable to automatically open the browser. Please navigate to { target_url } in your browser."
@@ -23,32 +20,6 @@ def open_browser(target_url: str) -> None:
2320 console .info (f"Opening browser to { target_url } ." )
2421
2522
26- def open_browser_and_wait (target_url : str , poll_url : str , interval : int = 2 ):
27- """Open a browser window to target_url and request poll_url until it returns successfully.
28-
29- Args:
30- target_url: The URL to open in the browser.
31- poll_url: The URL to poll for success.
32- interval: The interval in seconds to wait between polling.
33-
34- Returns:
35- The response from the poll_url.
36- """
37- import httpx
38-
39- open_browser (target_url )
40- console .info ("[b]Complete the workflow in the browser to continue.[/b]" )
41- while True :
42- try :
43- response = net .get (poll_url , follow_redirects = True )
44- if response .is_success :
45- break
46- except httpx .RequestError as err :
47- console .info (f"Will retry after error occurred while polling: { err } ." )
48- time .sleep (interval )
49- return response
50-
51-
5223def reflex_build_redirect () -> None :
5324 """Open the browser window to reflex.build."""
5425 open_browser (constants .Templates .REFLEX_BUILD_FRONTEND )
0 commit comments