How to get the inner html from <webview> or window.open


#1

I can not find a way to get the html from webview or window.open ,when the page loaded
could some one help me?


#2

What about injecting a preload script to the webview and using ipc to communicate with your Electron app?


#3

Have you tried using “document.getElementById(“webview_id”).innerHTML”?


#4

I visited those links and wasn’t able to get anything to work. Could you provide an example of getting the title of a webpage in a <webview>?


#5

Who ever lands on this page can follow the below code to get html from webview.
We can get content through IPC

render.js

webview.addEventListener("ipc-message", function (e) {
        if (e.channel === "html-content") {
            var html_contents = e.args[0];
            console.log(html_contents);
        }
}

preload.js

     var ipcRenderer = require('electron').ipcRenderer;
    document.addEventListener("DOMContentLoaded", function () {
        ipcRenderer.sendToHost('html-content' , document.body.innerHTML);
    });