Web browser chrome, can't open URL in new window, keeps opening URL as a tab
Asked Answered
B

2

2

I'm trying to open a URL in a new window. I can't use selenium because it wouldn't be signed into Google.

My default browser is Chrome using Windows 10 and I already have 3 Chrome windows open each with multiple tabs.

here is my code on Python 3.6:

import webbrowser

url = 'https://google.com'

open_google = webbrowser.open('https://google.com', new=1)
open_google = webbrowser.open_new('https://google.com')

Both of these give me a new tab in my current window instead of a new window. Why is this happening? is it a setting in Chrome?

Bluhm answered 22/11, 2019 at 14:4 Comment(2)
After doing a bit of reading, it seems that there isn't a way around this without using SeleniumCalque
maybe try webbrowser.open('https://google.com --new-window'). OR simply use subprocess or os.system() instead of webbrowserLandfall
K
1

How about opening a new window using os.system or subprocess and then using webbrowser to get the urls/apps to open there.

Something like:

import subprocess
command = "cmd /c start chrome http://www.google.com --new-window"
subprocess.Popen(command, shell=True)

and then doing:

open_google = webbrowser.open('https://google.com', new=1)
Kwasi answered 22/11, 2019 at 14:20 Comment(0)
C
0

I want to be able to launch different browsers, because they have a different default theme and their displays look different on my computer.

Here is an approach that parameterizes the URL string to dynamically create the URL with the browser name "on the fly".

import subprocess

browser_type = "chrome"  # Replace the value with "edge" or "firefox"

location_url = "https://mcmap.net/q/270829/-how-to-open-a-new-default-browser-window-in-python-when-the-default-is-chrome{browser_type}"

command_fstring = f"cmd /c start firefox {location_url} --new-window"

subprocess.Popen(command_string, shell=True)

To give credit where it is due, this is based on the answer by @Sharath on this page: Web browser chrome, can't open URL in new window, keeps opening URL as a tab

Citronellal answered 21/1, 2023 at 1:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.