svarog
svarog

Reputation: 696

Is it possible to allow mixed content in Flutter WebView

I have a problem where web page is secured with SSL, but video and audio content inside the page are not, the source urls are HTTP, and this prevents users to play these type of content inside WebView. The message that is the following:

"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)

Is it possible to somehow allow or force WebView to load mixed content and allow user to play content that is not secured with SSL?

Thanks

Upvotes: 3

Views: 5435

Answers (1)

Lorenzo Pichilli
Lorenzo Pichilli

Reputation: 3429

The webview_flutter plugin doesn't have an option to change the Android WebView mixed content mode.

Instead, you can use my flutter_inappwebview plugin which support that specific Android webview option.

In your case, you can set the Android webview option mixedContentMode with value AndroidMixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW

In this mode, the WebView will allow a secure origin to load content from any other origin, even if that origin is insecure.

Code example:

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

Upvotes: 6

Related Questions