Requests for webbrowser module

MRAB python at mrabarnett.plus.com
Wed Sep 14 14:33:07 EDT 2016


On 2016-09-14 17:53, Jamie wrote:
> Hi,
>
> I am not sure if this is an intended consequence but when using the
> webbrowser module to open a new blank browser tab in chrome it opens it
> in a new browser window instead of using the current window. Providing
> any complete url provides different behaviour, it opening a new tab in
> the current browser window. Below is some code that produces the
> different behaviours.
>
> blank tab code:
> import webbrowser
>
> chrome = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
> url = "chrome://newtab"
> webbrowser.get(chrome).open_new_tab(url)
> webbrowser.get(chrome).open_new_tab(url)
>
> normal tab code:
> import webbrowser
>
> chrome = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
> url = "http://google.com"
> webbrowser.get(chrome).open_new_tab(url)
> webbrowser.get(chrome).open_new_tab(url)
>
> I would like to be able to open new blank tabs in the current browser
> window if possible. If you know of a way to do this with the webbrowser
> module I would appreciate your help. Also is there any chance that the
> ability to close browser tabs will be added to the webbrowser module soon?
>
If you want a new blank tab, try giving it the URL "about:blank".

All the module does is call the browser application with the appropriate 
command line arguments, so the module could close a tab only if the 
browser itself let you do so by calling it with some argument, which 
probably won't happen...

A workaround is to select the browser window and then send it a Ctrl+F4 
keypress. Have a look at the 3rd party "pywin32" package.



More information about the Python-list mailing list