Created
January 5, 2017 13:36
-
-
Save deepak/57bbcc6f5a272bad10e99f47808d9201 to your computer and use it in GitHub Desktop.
override content in Electron webview
This file contains hidden or 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 { ipcRenderer } = require('electron'); | |
ipcRenderer.on('ping', () => { | |
console.log(document); | |
console.log(document.querySelector('input')); | |
// the document references to the document of the <webview> | |
document.querySelector('input').addEventListener('change', function(event) { | |
event.preventDefault(); | |
console.log("====> test"); | |
}); | |
ipcRenderer.sendToHost('pong'); | |
}); |
This file contains hidden or 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
<webview | |
id="app" | |
preload="./hack.js" | |
src="http://example.com"> | |
</webview> | |
<script> | |
require('./index.js'); | |
</script> |
This file contains hidden or 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
'use strict'; | |
console.log("===> starting index.js"); | |
const fs = require('fs'); | |
const webview = document.getElementById('app'); | |
webview.addEventListener('ipc-message', (event) => { | |
console.log(event.channel); | |
// Prints "pong" | |
}); | |
webview.addEventListener("dom-ready", function() { | |
webview.send('ping'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment