Skip to content

WebView Data Monitoring

This document describes data collection methods for HarmonyOS WebView scenarios.

How to Enable

After enabling setEnableTraceWebView(true) in RUM Configuration, the SDK automatically collects RUM data from WebViews.

Configure Host Allowlist

You can use setAllowWebViewHost(...) to restrict the Hosts allowed to use the WebView JavaScript Bridge. The allowlist is provided to the Browser SDK in the WebView; passing null or an empty array means no Host restrictions.

import { FTSDK, FTRUMConfig } from '@guancecloud/ft_sdk/Index';

const rumConfig = new FTRUMConfig()
  .setRumAppId('your-rum-app-id')
  .setEnableTraceWebView(true)
  .setAllowWebViewHost(['example.com', 'm.example.com']);

FTSDK.installRUMConfig(rumConfig);

Example

import { FTWebViewHandler } from '@guancecloud/ft_sdk/Index';
import { webview } from '@kit.ArkWeb';

@Component
export struct MyWebViewPage {
  @State webController: webview.WebviewController = new webview.WebviewController();
  private webViewHandler: FTWebViewHandler = new FTWebViewHandler();

  aboutToAppear() {
    this.webViewHandler.setWebView(this.webController);
  }

  aboutToDisappear() {
    this.webViewHandler.clearWebController();
  }

  build() {
    Web({
      src: 'https://example.com',
      controller: this.webController
    })
    .javaScriptAccess(true)
    .javaScriptProxy(this.webViewHandler.getJavaScriptProxy(this.webController))
  }
}

Notes

  • FTWebViewHandler reads the RUM configuration from the application entry point.
  • Bind the webController when the page enters and clean it up promptly when the page leaves.
  • If setEnableTraceWebView(true) is not enabled, WebView data is not automatically collected.
  • When a Host allowlist is configured, only pages in the allowlist can use the JavaScript Bridge.
  • If view_path_name is not provided, the SDK does not populate this field; if it is provided, its value is preserved. If view_referrer is not provided, it falls back to the current native View.
  • For WebView data, sdk_version is determined by the native SDK; the Browser SDK version information is retained in sdk_pkg_info.

Feedback

Is this page helpful?