How to use <webview> methods in Electron

The online documentation <webview> provides a list of methods that you can use with the object. When I try to run any of these methods, none of them work. When I looked at the properties of the element <webview>in the inspector, it says its prototype webview. ( __proto__ : webview)

It is in this prototype that all methods are stored. Therefore, my element should basically just inherit these methods from its prototype when I use these methods (e.g. myWebview.openDevTools()).

However! when i use Object.getProptotypeOf(myWebview)i get HTMLElementNOT webviewas shown in the inspector.

Here is an example of my code:

<webview id="myWebview" src="path/to.file"></webview>

<script> 
  var myWebview = document.getElementById('myWebview');
  console.log("myWebview: ",myWebview);
  console.log("prototype: ",Object.getPrototypeOf(myWebview)); //=> HTMLElement
  myWebview.openDevTools();
</script>
+4
source share
2 answers

, -, , - :

webview.addEventListener("dom-ready", function(){
  webview.openDevTools();
});

@Shwany, - , did-start-loading , , webview , dom-ready


:

DOM, - . <webview> - HTMLElement.

, , , <webview> , webview ( , ). webview, webview.

+6

webview :

- , JavaScript, - , webview.

openDevTools -, :

  <script> 
  var myWebview = document.getElementById('myWebview');
  myWebview.addEventListener("did-start-loading", function (e) {
    myWebview.openDevTools();      
  });
  </script>  

, -. document.readystate == "complete", . , .

+2

All Articles