BrowserWindow Preload doesn't run


I’m trying to run the JS behind a browser extension that I built within Electron. To do that I know I’ll need to stub out a bunch of chrome APIs, which is fine.

I’ve built a system for loading my extension down from the website it’s hosted on, and I can access the files, and load them into BrowserWindows, but I’m now at the point where I need to start stubbing.

It looks to me like the preload functionality is perfect for this. But no matter what I do it doesn’t seem to run and there’s no error.

Here’s the code I’m using to open the browser window:

And here’s the preload script at the moment:

Both and window.yup_loaded are undefined when I look at dev tools.

And process.argv doesn’t even seem to contain a preload script at all.

["/Users/kevin/desktop-for-ynab/node_modules/electron-prebuilt/dist/ Helper", "--type=renderer", "--no-sandbox", "--primordial-pipe-token=6A13E99ACDDD0E19F0144D7E142A003A", "--lang=en-US", "--node-integration=true", "--enable-pinch", "--num-raster-threads=2", "--enable-zero-copy", "--disable-partial-raster", "--enable-gpu-memory-buffer-compositor-resources", "--content-image-texture-target=3553,3553,3553,3553,3553,34037,3553,3553,3553,3553,34037,3553,34037,34037", "--video-image-texture-target=3553,3553,3553,3553,3553,34037,3553,3553,3553,3553,34037,3553,34037,34037", "--channel=846.3.1832410827"]

How do I get the preload script to run before other scripts on the page I’m loading run?


Specify the --enable-logging command-line switch when launching Electron, and check the console for errors.


Alrighty, that settles it.

I was passing a file URL in instead of an actual path. So I changed:



path.join(__dirname, 'chrome-api.js')

and it’s loading correctly now. Thanks for your help!