是否可以在 Flutter WebView 中允许混合内容

Is it possible to allow mixed content in Flutter WebView

我遇到一个问题,网页使用 SSL 保护,但页面内的视频和音频内容没有,源 URL 是 HTTP,这会阻止用户在 WebView 内播放这些类型的内容。消息如下:

"Mixed Content: The page at 'https://<page url>' was loaded over HTTPS, but requested an insecure video 'http://<video url>.mp4'. This request has been blocked; the content must be served over HTTPS.", source: https://<page url> (0)

是否可以以某种方式允许或强制 WebView 加载混合内容并允许用户播放不受 SSL 保护的内容?

谢谢

webview_flutter 插件没有更改 Android WebView 混合内容模式的选项。

相反,您可以使用我的 flutter_inappwebview 插件,它支持特定的 Android webview 选项。

在您的情况下,您可以将 Android 网络视图选项 mixedContentMode 设置为值 AndroidMixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW

在此模式下,WebView 将允许安全来源从任何其他来源加载内容,即使该来源不安全。

代码示例:

child: InAppWebView(
  initialUrlRequest: URLRequest(url: Uri.parse("https://yourwebsite.com")),
  initialOptions: InAppWebViewGroupOptions(
    android: AndroidInAppWebViewOptions(
      mixedContentMode: AndroidMixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW
    )
  ),
)