Skip to content

Instantly share code, notes, and snippets.

@deepak
Created January 5, 2017 13:36
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 deepak/57bbcc6f5a272bad10e99f47808d9201 to your computer and use it in GitHub Desktop.
Save deepak/57bbcc6f5a272bad10e99f47808d9201 to your computer and use it in GitHub Desktop.
override content in Electron webview
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');
});
<webview
id="app"
preload="./hack.js"
src="http://example.com">
</webview>
<script>
require('./index.js');
</script>
'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