4

I want to know the current URL of the browser-window. Is there any way to access window.location.href property of BrowserWindow or any other way to get it?

G07cha
  • 4,009
  • 2
  • 22
  • 39
Freddy Daniel
  • 602
  • 11
  • 25

1 Answers1

8

From the main process, use the window's webContents.getURL() method:

[...]
win = new BrowserWindow({ /* options */});
win.loadFile('index.html');
console.log (win.webContents.getURL();)

See: How to get the url of the BrowserWindow?

Cart Biya
  • 96
  • 1
  • This answer is acceptable. I've created this question to detect error URL( see this [question](https://stackoverflow.com/questions/56000178/win-reload-showing-showing-blank-white-window-in-electron) for more details). But `win.webContents.getURL()` showing the wrong URL to me – Freddy Daniel May 07 '19 at 04:26