Can we use electron functions within external web app?


#1

Scenario

  1. We are loading the external web by using this
    mainWindow.loadURL('http://127.0.0.1:4200');
  2. This is a separate angular app actually.
  3. We are hosting the angular app in the electron app.
  4. The angular app working great when sitting in electron app.

Question

  1. Can we use the electron function in the external web? Something like we do in electron app.
    const { shell } = require('electron');
    shell.openExternal('file://D:/test.docx');
    const SerialPort = require('serialport');
  2. If we do can, what is the syntax for TypeScript?

Thanks in advance.


#2

I’m new to Electron (actually to web dev too) so take this with a grain of salt. I am using Vue.js and in many of the Vue JS files I do have access to the main.js in “node”.

const electron = require(‘electron’)
const remote = require(‘electron’).remote;
const ipcRenderer = require(‘electron’).ipcRenderer

Review the ipcRenderer and Electron.remote in the doc’s.


#3

Thanks johnf for your response. I do can access the node module when I load the web via file:/.

The question is regarding the mainWindow.loadURL(‘http://127.0.0.1:4200’). It’s the remote web I am loading, not in current Electron app.


#4

If I understood correctly, you are looking for node integration attribute in the webview tag.