Call function in focused electron-tab from mainmenu.js


I’m using electron-tabs and I want to have a save action in my menu with a keybind that triggers a function located in the currently focused electron-tab when CmdOrCtrl+S is hit or when selected from the menu.

{ label: “Save”, accelerator: “CmdOrCtrl+S”, selector: “save:”, click: function() {
// How to call function in currently focused electron-tab from here?
} },

It is my understanding that an electron-tab is essentially a webview and that it has a send method but I am unclear how to utilize that to trigger the function located inside of the electron-tab from the callback in the menu item. Is this possible? If so, how?


In the end I got it to work like this:

  { label: "Save", accelerator: "CmdOrCtrl+S", selector: "save:", click: function() {
    var focusedWindow = BrowserWindow.getFocusedWindow();
    web_contents = focusedWindow.webContents;
      "var webview = document.getElementsByClassName('etabs-view visible'); " +
      "webview = webview[0]; " +
      "webview.executeJavaScript('save_file();'); "
  } },