Home > Back-end >  close chrome browser via script
close chrome browser via script

Time:05-07

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).

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")

CodePudding user response:

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')

CodePudding user response:

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

  • Related