天天看点

electron嵌入webview显示空白问题

1. 页面是这样子

<!DOCTYPE html>
<html>
  <body>
    <webview id="foo" src="https://www.baidu.com/" style="display:inline-block; width:640px; height:480px"></webview>
  </body>
</html>
           

当这个webview启动的时候却是空白。

2.解决办法

webPreferences配置下webviewTag: true

如下:

const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      webviewTag: true,
      preload: path.join(__dirname, 'preload.js')
    }
  })```

           

继续阅读