Here is a two step solution:
- Get the class name of the browser object by running:
type(a).__class__
- Create a dictionary where you map a browser class name to a browser type name.
Details:
When you run a = webbrowser.get('windows-default')
, you can get the class name of a by: browser_class = type(a).__class__
.
Based on below picture, you can code the method highlighted in 2 as follows:
def which_browser(browser_class):
return{
'Mozilla': 'firefox',
'Chrome' : 'google-chrome'
}.get(browser_class,'firefox')
This method returns the browser type name depending on the browser class name you get in browser_class
above. Note that I set the method to return, by default mozilla but that is not necessarily for a simple test. I mean, you can simply run:
def which_browser(browser_class):
return{
'Mozilla': 'firefox',
'Chrome' : 'google-chrome'
}
You can then call which_browser()
method to get the browser type name:
browser_name = which_browser(browser_class)
browser_name is of type str
as you want it.
You may need this information linked to above:

Full program:
I tested the following code according to what I have on my Linux machine where I have installed only 2 browsers:
import webbrowser
a = webbrowser.get('windows-default')
def which_browser(b):
return{
'Mozilla': 'firefox',
'Chrome' : 'google-chrome'
}.get(b,'firefox')
print which_browser(type(a).__class__)
After running the program, I get this output: firefox
.