title: How can I access the BrowserWindow JavaScript global from the main process in Electron?
body: <p>I want a menu, defined in the main process to call JavaScript code inside the current browser window in an <a href="https://en.wikipedia.org/wiki/Atom_(text_editor)" rel="nofollow noreferrer">Atom</a> or <a href="https://en.wikipedia.org/wiki/Electron_(software_framework)" rel="nofollow noreferrer">Electron</a> application.</p>
  <p>Getting main process globals from the browser window is</p>
  <pre><code>const remote = require('remote')
  const foo    = remote.getGlobal('foo')
  </code></pre>
  <p>What is the equivalent for the main process (AKA get the current window globals)? This is what I want to do in pseudocode</p>
  <pre><code>// JavaScript inside the main process
  const BrowserWindow = require('browser-window')
  //...
  // Inside the menu callback
  let window    = BrowserWindow.getFocusedWindow()
  let commander = window.global('commander') /// &lt;---- Pseudocode!!!
  commander.handleCommand('File.Save')
  </code></pre>