Last active
March 22, 2021 11:15
-
-
Save theArina/3956d7ef31119559d4219ade2bc4cd74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "webivew-preload-example", | |
"version": "1.0.0", | |
"main": "main.js", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"keywords": [], | |
"dependencies": { | |
"electron": "12.0.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<script> | |
console.log('test from the page: ', window.preloadTest); | |
</script> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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