What is the correct way to set the initial zoomLevel of a webview?


#1

I create a webview and would like to set its initial zoomLevel. I tried several techniques but could not find a clean one that does not do a flickering effect.

<webview id="google" src="http://app.forestadmin.com/" style="height:100vh;width:100vw;">

<script type="text/javascript">
  var webview = document.getElementById("google");

  webview.setZoomLevel(2);
  // Uncaught TypeError: webview.setZoomLevel is not a function

  webview.getWebContents().setZoomLevel(2);
  //Uncaught TypeError: webview.getWebContents is not a function

  webview.addEventListener('did-attach', function() {
    // never fired
    console.log('did-attach');
    webview.setZoomLevel(2);
  })

  webview.addEventListener('did-finish-load', function() {
    // zoom is flickering
    console.log('did-finish-load');
    webview.setZoomLevel(3);
  })
  webview.addEventListener('did-stop-loading', function() {
    // zoom is flickering
    console.log('id-stop-loading');
    webview.setZoomLevel(3);
  })
</script>

It seems linked to this topic and this issue but not directly.