@@ -45,9 +45,10 @@ def is_wsl():
4545 return platform_name == 'linux' and 'microsoft' in release
4646
4747
48- def _browse (auth_uri ): # throws ImportError, possibly webbrowser.Error in future
48+ def _browse (auth_uri , browser_name = None ): # throws ImportError, webbrowser.Error
49+ """Browse uri with named browser. Default browser is customizable by $BROWSER"""
4950 import webbrowser # Lazy import. Some distro may not have this.
50- browser_opened = webbrowser .open (auth_uri ) # Use default browser. Customizable by $BROWSER
51+ browser_opened = webbrowser .get ( browser_name ). open (auth_uri )
5152
5253 # In WSL which doesn't have www-browser, try launching browser with PowerShell
5354 if not browser_opened and is_wsl ():
@@ -147,6 +148,7 @@ def get_port(self):
147148 def get_auth_response (self , auth_uri = None , timeout = None , state = None ,
148149 welcome_template = None , success_template = None , error_template = None ,
149150 auth_uri_callback = None ,
151+ browser_name = None ,
150152 ):
151153 """Wait and return the auth response. Raise RuntimeError when timeout.
152154
@@ -173,6 +175,12 @@ def get_auth_response(self, auth_uri=None, timeout=None, state=None,
173175 A function with the shape of lambda auth_uri: ...
174176 When a browser was unable to be launch, this function will be called,
175177 so that the app could tell user to manually visit the auth_uri.
178+ :param str browser_name:
179+ If you did
180+ ``webbrowser.register("xyz", None, BackgroundBrowser("/path/to/browser"))``
181+ beforehand, you can pass in the name "xyz" to use that browser.
182+ The default value ``None`` means using default browser,
183+ which is customizable by env var $BROWSER.
176184 :return:
177185 The auth response of the first leg of Auth Code flow,
178186 typically {"code": "...", "state": "..."} or {"error": "...", ...}
@@ -190,7 +198,7 @@ def get_auth_response(self, auth_uri=None, timeout=None, state=None,
190198 logger .info ("Open a browser on this device to visit: %s" % _uri )
191199 browser_opened = False
192200 try :
193- browser_opened = _browse (_uri )
201+ browser_opened = _browse (_uri , browser_name = browser_name )
194202 except : # Had to use broad except, because the potential
195203 # webbrowser.Error is purposely undefined outside of _browse().
196204 # Absorb and proceed. Because browser could be manually run elsewhere.
0 commit comments