Electron: WebView.getWebContents is undefined

Created on 21 Aug 2016  路  1Comment  路  Source: electron/electron

  • Electron version: 1.3.3
  • Operating system: Ubuntu Linux 16.04

When embedding a WebView, getWebContents returns undefined when being called on window load. I'm not sure if this is an actual bug or just a lack of documentation.

The documentation does not mention anything related as far as I can tell.

To verify this issue, I used this index.html in electron-quick-start

<!--[...]-->
  <script>
    window.addEventListener('load', () => {
      var webview = document.getElementById('testview');
      console.log('window load: ', webview.getWebContents()); //undefined

      webview.addEventListener('dom-ready', () => {
        console.log('webview dom-ready: ', webview.getWebContents()); //Object
      });
    });
  </script>
<!--[...]-->

Most helpful comment

The methods have to be used after the webview is loaded as documented:

Note: The webview element must be loaded before using the methods.

>All comments

The methods have to be used after the webview is loaded as documented:

Note: The webview element must be loaded before using the methods.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lealife picture lealife  路  3Comments

tenry92 picture tenry92  路  3Comments

EladBezalel picture EladBezalel  路  3Comments

etiktin picture etiktin  路  3Comments

dangan-ronpa picture dangan-ronpa  路  3Comments