1

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?

Sergey Shubin
  • 3,040
  • 4
  • 24
  • 36
Prabhu Rajan
  • 11
  • 1
  • 2

1 Answers1

4

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

Philip Petrov
  • 975
  • 4
  • 8
  • Hi, Thanks for the solution.Actually i am looking for a solution to open a new tab in new browser window.Appreciate your help on this. – Prabhu Rajan Jun 05 '20 at 09:10