WebView Data Monitoring¶
This document describes the data collection methods for WebView scenarios in HarmonyOS.
Enabling¶
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/src/main/ets/components/web/FTWebViewHandler';
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¶
FTWebViewHandlerreads the RUM configuration from the application entry point.- Bind the
webControllerwhen the page enters, and clean it up promptly when the page leaves. - If
setEnableTraceWebView(true)is not enabled, WebView data will not be collected automatically.