Skip to content

WebView Data Monitoring

This document describes the data collection methods for HarmonyOS WebView scenarios.

Enabling Method

After enabling setEnableTraceWebView(true) in RUM Configuration, the SDK will automatically collect RUM data from within the WebView.

Usage 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 will not be automatically collected.

Feedback

Is this page helpful? ×