forked from electron/minimal-repro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
executable file
·25 lines (22 loc) · 833 Bytes
/
preload.js
File metadata and controls
executable file
·25 lines (22 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* The preload script runs before `index.html` is loaded
* in the renderer. It has access to web APIs as well as
* Electron's renderer process modules and some polyfilled
* Node.js functions.
*
* https://www.electronjs.org/docs/latest/tutorial/sandbox
*/
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})
const { contextBridge, ipcRenderer } = require('electron');
// Expose a safe API to the renderer process
contextBridge.exposeInMainWorld('electron', {
openNewWindow: (url, features) => ipcRenderer.send('create-new-window', { url, features })
});