Skip to content

Instantly share code, notes, and snippets.

@theArina
Last active March 22, 2021 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theArina/3956d7ef31119559d4219ade2bc4cd74 to your computer and use it in GitHub Desktop.
Save theArina/3956d7ef31119559d4219ade2bc4cd74 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<webview
src="about:blank"
preload="preload.js"
nodeintegrationinsubframes="true"
/>
</body>
<script>
const webview = document.querySelector('webview');
const onDomReady = () => {
webview.openDevTools();
webview.src = `${__dirname}/page.html`;
webview.removeEventListener('dom-ready', onDomReady);
}
webview.addEventListener('dom-ready', onDomReady);
</script>
</html>
const { app, BrowserWindow } = require('electron');
app.on('ready', () => {
let mainWindow = new BrowserWindow({
show: false,
webPreferences: {
contextIsolation: false,
webviewTag: true,
nodeIntegration: true,
nodeIntegrationInSubFrames: true,
worldSafeExecuteJavaScript: false
}
});
mainWindow.loadFile(`${__dirname}/index.html`);
mainWindow.on('closed', () => mainWindow = null);
});
{
"name": "webivew-preload-example",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"keywords": [],
"dependencies": {
"electron": "12.0.0"
}
}
<!DOCTYPE html>
<html>
<script>
console.log('test from the page: ', window.preloadTest);
</script>
</html>
window.preloadTest = 'hello !';
console.log('test from preload: ', window.preloadTest);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment