3

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
  • 3,833
  • 1
  • 24
  • 39
Freddy Daniel
  • 492
  • 7
  • 21

1 Answers1

5

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
  • 66
  • 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