Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access electron app's current browserWindow?

I'm stuck on a particular point with my Electron app:

When I open the devTools, I call mainWindow.webContents.openDevTools() from the app's menu. It's working fine on mainWindow.

The problem appears on child windows, opened by window.open(): the app menu is still working on every window, but it always call mainWindow's devtools (which is normal, since I told it to do so), where I would like to get current window's ones.

So I wonder if there is a way to call something like currentWindow.webContents.openDevTools() ? I found nothing in the documentation nor on SO nor by googling, so I guess I might haev missed something.

Let me precise a few things:

  • I'm still a newbie with Electron
  • I have no control on the pages that are called in the app, I'm trying to use electron as a kind of "restricted browser" to ship with a PHP-based application
like image 818
meyergre Avatar asked Jan 04 '17 10:01

meyergre


1 Answers

After a bit more reading, I just found out that BrowserWindow.getFocusedWindow() is exactly what I was looking for.

So in my app menu, I juste call BrowserWindow.getFocusedWindow().webContents.openDevTools(), and it works as I expected.

like image 105
meyergre Avatar answered Sep 19 '22 00:09

meyergre