BrowserWindow preload does not work


I am having trouble with making “preload” working in my BrowserWindow.

I create it as (browser/agent.js)

window.test = 'preload';
console.log('preload started');

Than I call it as

BrowserWindow = remote.require 'browser-window'

preload = path.resolve __dirname, 'browser'
preload = 'file://' + path.join preload, 'agent.js'

@win = new BrowserWindow(
  width: 1000
  height: 1000
  show: false
  preload: preload
@win.loadUrl ''

I get my new window, but dev tools Console does not have expected message. And “window.test” object is undefined. No errors either. The “agent.js” file is not in the dev tools Sources window. I’ve checked location of the file, and it does exist.

Any clues how could I debug it?
P.S. version 0.194.0, linux, from the official .deb package


It sounds like you’re using Atom (from the version number) … but you’re using the Electron API (BrowserWindow) to do things. The method is generally how one would use the Atom API to open a new window.

Another issue is that a new window is a new process. So one generally can’t communicate between the old window and the new window like what you’re trying to do.


Ah, I see. I thought that if Atom is based on Electron, than Electon API is available in Atom.