Electron webview为什么没法使用?

发布于 1周前 作者 phonegap100 来自 分享

Electron webview警告

electronic的webview标签基于Chromium的webview,后者正在经历巨大的架构变化。这将影响webview的稳定性,包括呈现、导航和事件路由。我们目前建议不使用webview标签,并考虑其他替代方案,如iframe、electronic的BrowserView或完全避免嵌入内容的体系结构。

来源: https://electronjs.org/docs/api/webview-tag

Electron webview源码

<webview id="foo" src="https://www.github.com/" style="display:inline-flex; width:640px; height:480px"></webview>
<script>
  onload = () => {
    const webview = document.querySelector('webview')
    const indicator = document.querySelector('.indicator')

    const loadstart = () => {
      indicator.innerText = 'loading...'
    }

    const loadstop = () => {
      indicator.innerText = ''
    }

    webview.addEventListener('did-start-loading', loadstart)
    webview.addEventListener('did-stop-loading', loadstop)
  }
</script>

Electron webview替代方案

<iframe id="foo" src="https://www.github.com/" style="display:inline-flex; width:640px; height:480px"></iframe>
<script>
  onload = () => {
    const webview = document.querySelector('webview')
    const indicator = document.querySelector('.indicator')

    const loadstart = () => {
      indicator.innerText = 'loading...'
    }

    const loadstop = () => {
      indicator.innerText = ''
    }

    webview.addEventListener('did-start-loading', loadstart)
    webview.addEventListener('did-stop-loading', loadstop)
  }
</script>
回到顶部