2

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?

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.