How can I run javascript code in a created webContents?


I have the following code that I’m running (note that this code itself is running on the renderer process):

  const prefStore = PreferenceSingleton.instance;
  const { BrowserWindow } = require('electron').remote;

  let win = new BrowserWindow({width: 800,
    height: 600


What I’d like to do is communicate with (and run code on) the renderer process for the newly created window (not my main window). I’ve tried doing the following:

  win.webContents.on('did-finish-load', () => {
    win.webContents.send("jwir3-com-finished-loading", "Hey There!");

And then in app.js (I’m using electron-boilerplate), adding the following:

ipcRenderer.on('jwir3-com-finished-loading', (event, message) => {

But this latter event never seems to get triggered. I know that I can use win.webContents.executeJavaScript(), but I’d rather avoid this, since it seems like it’s meant for small scripts, and what I’m looking to do is interact with the content in a way that uses jQuery (and thus will be a slightly larger and more interactive script than I think the embedded method is designed for).

So, how can I achieve this? Is there some special thing I can pass when I create a new renderer process that tells it what javascript to run on that process?