Can websites opened with BrowserWindow use electron functionality?


#1

Hi everyone.

Backstory:
A few years ago I developed a GWT web application and together with it a XULRunner browser that´s pointing only to this GWT web application. Since 2015 XULRunner is not longer in development. Now I´m searching for an alternative browser solution(with current browser technology) for my project.

Electron seemed promising and all my required features and more seemed possible to realize with it. I made a little hello world app with electron and added all the features(e.g. folder selection dialog or file handling). After I checked all that I created a BrowserWindow in my main.js that points directly to my web application. But now I don´t know how to call my electron functions through my web application.

Can somebody tell me if it´s even possible to call electron functionality through a web application opened in a BrowserWindow?


#2

Hello,

Your web application must be in a webview with a “nodeintegration” attribute.
<webview id="mywebapp" class="active" nodeintegration src="http://mypage.html"></webview>

In your webApp your can communicate in your electron app

webApp -> Electron app
To send

  • in main process with
    ipcRenderer.send(...
  • in renderer process with
    ipcRenderer.sendToHost(...

To listen
with renderer process
ipcRenderer.on(...

Electron app -> webApp
To send

  • If send from main process, send to renderer process and after send from renderer to webview
    ipcMain.send(...
  • in renderer process with
    webview[0].send(...

To listen
with renderer process
webview[0].addEventListener('ipc-message'...