目录

How do I set the mixed content policy in WebView to load HTTP and HTTPS mixed content?

ArkWeb provides the mixedMode(mixedMode: MixedMode) API for specifying whether to enable loading of HTTP and HTTPS mixed content. By default, loading of mixed content is disabled.

Add the network access permission ohos.permission.INTERNET to the module.json5 configuration file in the project.

The code snippet is as follows:

// xxx.ets
import { webview } from '@kit.ArkWeb';

@Entry
@Component
struct WebComponent {
  controller: webview.WebviewController = new webview.WebviewController();
  // MixedMode.All indicates that all mixed content is allowed to be loaded (HTTP/HTTPS)
  @State mixedMode: MixedMode = MixedMode.All;
  build() {
    Column() {
      Web({ src: 'www.example.com', controller: this.controller })
        .mixedMode(this.mixedMode)
    }
  }
}

Reference

mixedMode