'close chrome browser via script
I want to make a program that when started quits Chrome (if it's open) and the link won't work, it just asks me to look for an app in the Microsoft store, please help me with my code or just give me a link that will crash the latest version of Chrome. It must be in Python (the latest version). Don't worry, it says edge but it just opens your default browser
import webbrowser
import time
def open_edge():
url = 'chrome://kill'
browser = 'C:/Program Files (x86)/Edge/Application/chrome.exe %s'
webbrowser.open(url)
open_edge()
print ("Complete")
Solution 1:[1]
It looks like this is impossible. Doing some testing, it appears only http:// and other related prefixes will actually cause the chrome browser to open. Other prefixes will trigger other programs to open. Basically, it seems to come down to how Windows handles requests to open hyperlinks.
I know this sucks, but I think you're just gonna have to find another way to achieve your goal.
I'd reccomend trying something like:
import os
os.system('taskkill/im chrome.exe')
Solution 2:[2]
Try this:
import webbrowser, pyautogui
def open_tab(url): # Url must be a string
webbrowser.open(url)
return "Tab Opened"
def close_tab():
pyautogui.hotkey('ctrl', 'w')
return "Tab Closed"
pyautogui documentation: link
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Kuba Sobolewski |
