meyergre
meyergre

Reputation: 191

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:

Upvotes: 9

Views: 6886

Answers (1)

meyergre
meyergre

Reputation: 191

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.

Upvotes: 10

Related Questions