【问题标题】:Electron webview is blocking http imagesElectron webview 阻止了 http 图像
【发布时间】:2016-03-09 01:35:12
【问题描述】:

我正在尝试加载要在 webview 上显示的 URL (http://twitch.tv/directory/following)。它曾经完美地反映了我在 Google Chrome 中看到的内容。一路走来,它开始阻止页面中的图像,我一直收到错误

Mixed Content: The page at 'https://www.twitch.tv/directory/following' was loaded over HTTPS, but requested an insecure image 'http://static-cdn.jtvnw.net/ttv-boxart/Music-138x190.jpg'. This request has been blocked; the content must be served over HTTPS.

对于每个尝试加载的图像。我在 Chrome 中对此进行了检查,我收到了相同的消息,但将其列为警告,因为图像仍在通过。我尝试禁用 BrowserWindow 中的安全设置:

function createWindow () {
  // Create the browser window.
  mainWindow = new BrowserWindow({
    width: 1200,
    height: 800,
    'title-bar-style': 'hidden',
    frame : false,
    webPreferences : {
      webSecurity: false,
      allowDisplayingInsecureContent: true
    }
  });

但无济于事,因为它仍然会阻止图像。有任何想法吗?谢谢。

【问题讨论】:

    标签: javascript google-chrome electron mixed-content


    【解决方案1】:

    因为 webview 在 BrowserWindow 之外的另一个进程中运行,所以它有自己的安全性,因为它不从 BrowserWindow 继承。如果你想禁用它,你需要将 disablewebsecurity 添加到你的 webview 标签。它在此处的文档中被引用:http://electron.atom.io/docs/v0.36.8/api/web-view-tag/#disablewebsecurity

    它应该是这样的:

    <webview src="http://twitch.tv/directory/following" disablewebsecurity></webview>
    

    我能够复制该问题。当我添加 disablewebsecurity 时,错误变成了您在使用 Chrome 时遇到的警告。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 2018-12-02
      • 1970-01-01
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      • 2010-12-12
      相关资源
      最近更新 更多