コンテンツにスキップ

WebView データ監視

本ドキュメントでは、HarmonyOS WebView シナリオにおけるデータ収集方法について説明します。

有効化方法

RUM 設定setEnableTraceWebView(true) を有効にすると、SDK が自動的に WebView 内の RUM データを収集します。

Host ホワイトリストの設定

setAllowWebViewHost(...) を使用すると、WebView の JavaScript Bridge を利用可能な Host を制限できます。ホワイトリストは WebView 内の Browser SDK に提供されます。null または空の配列を渡すと、Host は制限されません。

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

使用例

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

補足

  • FTWebViewHandler は、アプリケーションエントリで設定された RUM 設定を読み取ります
  • ページ遷移時は webController をバインドし、ページ離脱時は速やかにクリーンアップします
  • setEnableTraceWebView(true) が有効になっていない場合、WebView データは自動収集されません
  • Host ホワイトリストが設定されている場合、ホワイトリストに含まれるページのみが JavaScript Bridge を利用できます

フィードバック

このページは役に立ちましたか?