Reputation: 21
I am using the below code to open a new chrome browser window.When i run the code it is always opening a new page in the existing tab.
import webbrowser
import pyautogui
url = 'google.com'
chrome_path = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path))
webbrowser.get('chrome').open_new(url)
print(pyautogui.position())
Could any one suggest how to open a new tab instead?
Upvotes: 2
Views: 6640
Reputation: 970
It should be as simple as:
webbrowser.get('chrome').open_new_tab(url)
In the docs it says:
webbrowser.open_new_tab(url): Open url in a new page (“tab”) of the default browser, if possible, otherwise equivalent to open_new().
And just for reference:
webbrowser.open_new(url): Open url in a new window of the default browser, if possible, otherwise, open url in the only browser window.
Source: https://docs.python.org/3/library/webbrowser.html
Upvotes: 5