flaskwebgui icon indicating copy to clipboard operation
flaskwebgui copied to clipboard

Edge browser preferred on windows

Open sv3 opened this issue 1 year ago • 2 comments

This may be more of a personal preference than a bug, but I noticed that on my Windows computer, FlaskUI would open the Edge browser. I was able to override this behavior by reordering this list of browsers to put chrome at the top:

windows_browser_paths = [
    r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
    r"C:\Program Files\Microsoft\Edge\Application\msedge.exe",
    r"C:\Program Files\Google\Chrome\Application\chrome.exe",
    r"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe",
]

It may be notable that when I run webbrowser.get().name on my system it returns an empty string. webbrowser.open('google.com') opens Edge but webbrowser.open('https:\google.com') opens Chrome. Not sure if this is abnormal behavior. I did confirm that Google Chrome is set as the default browser and the default handler for HTTP and HTTPS protocols, but not for the "URL:microsoft-edge" protocol. This seems to be the normal state when Chrome is set as the default browser.

sv3 avatar Oct 15 '24 23:10 sv3

Interesting. It seems webbrowser.get().name is flaky and doesn't return the default browser all the time. If you know another alternative to find default browser on the OS please tell me.

You force it to use chrome if you provide your own func that finds browser path exe:

browser_path: str = func_that_finds_browser_path_return_str()

Checkout the source code, you can remove the other browser paths and keep just chrome.

ClimenteA avatar Oct 18 '24 06:10 ClimenteA

I got hit by this too; Found some suggestions here on checking default browser via the registry:

https://stackoverflow.com/questions/19037216/how-to-get-a-name-of-default-browser-using-python

Hunting around the registry, this seems like a possibly promising approach to checking which browser is assocaited with https links: Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice

..which on my machine gives me:

Image

...whereas I get this from webbrowser:

Python 3.13.1 (tags/v3.13.1:0671451, Dec  3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> webbrowser.get().name
''

...and one other thing to look for is some people don't have programfiles on drive C:\ but you can work around that with the %ProgramFiles% environment variable.

joncage avatar Feb 03 '25 23:02 joncage

I've set chrome as first option in newer version.

ClimenteA avatar Oct 04 '25 18:10 ClimenteA