在电子中附加Webview的事件处理程序

我在电子webview中加载外部url。

我需要附加一个事件处理程序来点击由某个类标记的元素。 处理程序应该在与示例中的eventhandler loadstart类似的托pipe页面的上下文中执行。 这可能吗?

<!DOCTYPE html> <html> <head> <title>Hello World!</title> </head> <body> <h1>Some eventhandler test</h1> <div class="indicator" > </div> <div id="content" ></div> <webview id="cmsWebview" src="http:///www.stackoverflow.com" style="height:100vh;display: flex;"></webview> <script> onload = function() { var webview = document.getElementById("cmsWebview"); var indicator = document.querySelector(".indicator"); var loadstart = function() { indicator.innerText = "loading..."; } var loadstop = function() { indicator.innerText = "...finished loading"; } webview.addEventListener("did-start-loading", loadstart); webview.addEventListener("did-stop-loading", loadstop); } </script> </body> </html>