Preload script path from the renderer process


I’m having an issue while specifying the preload script path (within my webPreferences) while opening the BrowserWindow from the renderer process.

  • My __dirname from the main process points to the root directory of where my app lives (i.e. where i run npm from).


  • Somehow, __dirname from a renderer process points to “/” (i.e. root of my machine!!) This is a problem because while specifying the preload script path i end up having to give the full absolute path!


  • I tried using but end up getting a path that looks like this


Few questions around this:-

  1. Firstly how do i get my app root directory from within the renderer process?
  2. Whats the best practice around this?