javascript - How to use the <webview> methods in Electron -
on electron <webview>
documentation there list of methods can use object. when try run of methods, none of them work. when looked in inpect properties of <webview>
element in inspector, says prototype webview
. (__proto__ : webview
)
it in prototype of methods stored. element should inherit methods prototype when use methods (e.g. mywebview.opendevtools()
).
however! when use object.getproptotypeof(mywebview)
htmlelement
, not webview
shows in inspector.
here example of 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>
i discovered issue , added example electron documentation
the bottom line need add listener webview listens when webview element ready:
webview.addeventlistener("dom-ready", function(){ webview.opendevtools(); });
according @shwany, webview's methods available when did-start-loading
event fired, may better practice wait until webview element ready using dom-ready
for more detailed explanation:
when window rendering dom, webview methods not available. initially, prototype <webview>
element still generic htmlelement
.
it after page renders <webview>
element begins loading , prototype changed webview prototype (same name element). , when gains access webview prototype, gains access of webview prototype methods.
Comments
Post a Comment