Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron 5.0.0 can not load webview #18145

Closed
758915145 opened this issue May 4, 2019 · 2 comments
Closed

electron 5.0.0 can not load webview #18145

758915145 opened this issue May 4, 2019 · 2 comments

Comments

@758915145
Copy link

Issue Details

相同的代码,我使用 5.0.0 版本时无法加载 webview,但是我换成 4.1.4 版本就正常了。
With the same code, I couldn't load WebView when I used version 5.0.0, but it was normal for me to switch to version 4.1.4.

My code

main.js

const { app, BrowserWindow, session } = require('electron')
function createWindow () {
  let win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })
  win.webContents.openDevTools()
  win.loadFile('index.html')
}
app.on('ready', createWindow)

index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Webview</title>
  <style>
    webview{
      display:inline-flex;
      width:300px;
      height:200px;
      background-color:#DDD;
    }
  </style>
</head>
<body>
<h1>Hello World!</h1>
We are using Node.js <script>document.write(process.versions.node)</script>,
Chromium <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
  <webview src="webview.html" id="myWebview"></webview>
</body>
</html>

webview.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Webview</title>
  </head>
<body>
  <h1>我就看看webview能不能用</h1>
</body>
</html>

Actual behavior

5.0.0

5 0 0

4.1.4

4 1 4

5.0.0 with file:// prefix

5 0 0-with

@fofohi
Copy link

fofohi commented May 4, 2019

和我遇到的一样,是 bug 吗?

@MarshallOfSound
Copy link
Member

You now need to explicitly enable webviewTag in your webPreferences object.

See https://github.com/electron/electron/blob/master/docs/api/breaking-changes.md#new-browserwindow-webpreferences-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants