python-eel / Eel

A little Python library for making simple Electron-like HTML/JS GUI apps
MIT License
6.37k stars 583 forks source link

Get PID of Chrome process #302

Open kleutzinger opened 4 years ago

kleutzinger commented 4 years ago

Describe the problem Is there a way to get the PID of the chrome tab/process that eel opens? We're making a crossplatform app, and we'd like to be able to manage focus/know what's running via PID. Maybe if python can't get it, maybe there's a way for javascript to get it? Thanks

Code snippet(s)

import eel

eel.start(HTMLFILE, size=(800, 600), port=PORT,
          cmdline_args=['--auto-open-devtools-for-tabs'])

# possible?
# chrome_pid = eel.getChromePID()

Desktop (please complete the following information):

RahulBadenkal commented 4 years ago

Just gave to quick glance to eel source code, could not see any variable/function already there that might help you here. The maintainers maybe able to help you more on this.

An indirect way would be to use python's 'psutil' library to to check if your application (hopefully your app has a name or someway to be identified) is open already and if yes, then get it's pid. This method is a bit messy but you can try it if you want.

ChrisKnott commented 4 years ago

I looked into this previously and I think Chrome can be quite flexible with how it uses processes between tabs etc. For example, if you have Chrome running, then launch Eel using Chrome, I think it is allowed to reuse that process if it wants.

I will leave this issue open to remind me to look into it again.