pythonfocuspython-webbrowser

webbrowser.open steals focus, how to avoid


On Windows, calling webbrowser.open steals the e.g. keyboard input focus, and sets it to the newly opened webbrowser tab.

Is there a way to avoid this, that is: to open the page in the background ?


Solution

  • The open method has a parameter autoraise=True. If you set this to False,

    webbrowser.open('https://example.com', autoraise=False)
    

    it will try to not steal focus, with the heads-up

    note that under many window managers this will occur regardless of the setting of this variable.