0

So I'm writing a program with python-3.9 that's supposed to open the designated default browser on Windows. The problem is that every time I run the program, it always opens the Internet Explorer window and not the designated default browser. I use the webbrowser library and my code goes like this:

import webbrowser

browser = webbrowser.get('windows-default')
browser.open_new(link)

The link variable contains the url of the site I want to open. Based on the webbrowser documentation, the code above should open the Windows default browser but it doesn't do anything when I run it. I also tried changing 'windows-default' to 'chrome' or 'google-chrome' which was supposed to open Google Chrome but it just returns this error:

webbrowser.Error: could not locate runnable browser

I changed my code to webbrowser.open_new(link) and it opens the url in Internet Explorer but who would willingly use IE these days? I also tried this solution from almost 10 years ago as it was the only available solution I could find but still won't work.

Xim_Vyge
  • 11
  • 6

1 Answers1

0

Have you tried webbrowser.get() instead of webbrowser.get('windows-default')? According to the docs, that should return the default browser.

import webbrowser

browser = webbrowser.get()
browser.open_new(link)
Holden Rohrer
  • 586
  • 5
  • 16
  • Yep. I tried it already and it's doing nothing. The terminal says it's doing its job but there's nothing happening. – Xim_Vyge Feb 23 '21 at 05:32
  • What does it list for the result of `webbrowser.get()`? Also, for the solution that you linked, you tried the location of the chrome binary on your system, right? – Holden Rohrer Feb 23 '21 at 05:51
  • Yeah I tried it. I'm actually using the code as a part of a function called when you click a button. When I click it, there's no response from the "Run" window. No errors either but nothing's happening. – Xim_Vyge Feb 23 '21 at 06:07