Skip to content
Advertisement

How to get the current foreground application in electron(Javascript)

How can I detect if, for example, a browser is currently open? I need this in my electron-application. ty 🙂

I’ve found nothing like this online. I’ve only found how I can check which window is open from the windows I have in my own application, but I need to know, what else is opened.

It should be something like this:

if(Application.isOpen('Google Chrome'){}

Advertisement

Answer

Unless someone has built a specific electron api to do this (which I can’t find), then from electron…no. However, the beauty of electron being built with node.js, means that any node module should be able to do the job for you.

For example, ps-list should be able to get you all currently running processes.

psList().then(processes => {
  console.log(processes)
})

Which gives a list for me, including:

chrome process

Just be aware that you need node access from the electron thread attempting to use this lib.

This can easily be abstracted to do a name search in the list for you to get your desired functionality.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement