How to detect if a URL is open in Chrome?

Viewed 419

I am writing an application where I am checking for a condition to be true every second. If the condition is true, a specific url needs to get opened in Chrome but only if that URL isn't already opened in chrome. Otherwise if the condition is true, every second a new tab will be opened. How do I check that? I know below code is used to check if chrome is running but how do I check which URL is running in Chrome?

import psutil as psutil

for proc in psutil.process_iter():
    proc_name = proc.name()
    if proc_name == 'chrome.exe':
        print('chrome is running now.')

        # open your program in this position

    else:
        print(proc_name)

My current code is below:

def workflow_chilled_water_trigger():
    threading.Timer(1.0, workflow_chilled_water_trigger).start()
    flow=float(flow_main_chiller())
    supply_temp=float(inlet_temp_main_chiller())
    return_temp=float(outlet_temp_main_chiller())

    if ((flow > 0) or ((return_temp-supply_temp)<5)):
    
        os.system('start chrome "https://www.youtube.com"')
    


        
        
workflow_chilled_water_trigger()
1 Answers

Unless you're using selenium or any similar solution to run the web browser first of all, then you'll have a hard time getting into the chrome window then getting the address bar and perform any other actions

I'd suggest either using selenium or similar tools and launch the web browser from there, then you'll have more control over the actions, address bar etc.

If it doesn't fits your needs it probably would be easier to create a chrome extension instead.

Related