When embedding a WebView, getWebContents returns undefined when being called on window load. I'm not sure if this is an actual bug or just a lack of documentation.
The documentation does not mention anything related as far as I can tell.
To verify this issue, I used this index.html in electron-quick-start
<!--[...]-->
<script>
window.addEventListener('load', () => {
var webview = document.getElementById('testview');
console.log('window load: ', webview.getWebContents()); //undefined
webview.addEventListener('dom-ready', () => {
console.log('webview dom-ready: ', webview.getWebContents()); //Object
});
});
</script>
<!--[...]-->
The methods have to be used after the webview is loaded as documented:
Note: The webview element must be loaded before using the methods.
Most helpful comment
The methods have to be used after the webview is loaded as documented: