I want to get the webContents from an iframe, that is located inside my index.html. Unfortunately my following approach doesn't work. What am I doing wrong?
I created an index.js containing:
const ipcRenderer = require('electron');
const iframe = document.getElementById('iframe'); // get iframe by id
let contents = iframe.webContents
contents.addEventListener('did-navigate-in-page', (event, input) => { // If navigation in frame occurs
ipcRenderer.send('did-navigate-in-iframe', input); // Send event and navigation input
})
which I required inside the index.html close to the iframe:
<main class="main_window">
<script>
require('./index.js');
</script>
<iframe id="iframe" src="top.html" ></iframe>
</main>
In my main.js I am trying to
const ipcMain = require('electron')
ipcMain.on('did-navigate-in-iframe', (event, input) => {
console.log(input) // Trying to log input here, which should be the location of the HTML file or link
});