WebView Monitoring¶
WebView Data Monitoring¶
For WebView data monitoring, integrate the Web Monitoring SDK into the pages accessed by the WebView.
If you also need to support collection for web applications in desktop browsers, it is recommended to integrate according to the recommended configuration for desktop applications.
When the collection scenario is limited to WebView in the app and does not need to support web applications in desktop browsers, after completing the basic Web SDK integration configuration, you can initialize with any applicationId.
After the native side completes RUM initialization and establishes the JavaScript Bridge through FTWebViewHandler, the collection data from WebView in the app is handled centrally by the app side.
To disable WebView collection or filter the collection scope by Host, refer to the following configuration descriptions:
FTRUMConfig.setAllowWebViewHostis deprecated. After upgrading, useFTSDKConfig.setAllowWebViewHostto centrally control the Host scope for WebView RUM and Replay.
Code Invocation¶
Initialize the SDK and RUM at the application entry point and enable WebView data collection:
import { FTSDK, FTSDKConfig, FTRUMConfig } from '@guancecloud/ft_sdk/Index';
const sdkConfig = FTSDKConfig.builder('YOUR_DATAKIT_URL')
.setAllowWebViewHost(['example.com']);
FTSDK.install(sdkConfig, this.context);
FTSDK.installRUMConfig(new FTRUMConfig()
.setRumAppId('your-rum-app-id')
.setEnableTraceWebView(true));
Bind in the Page Lifecycle¶
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))
}
}
Bind After the Web Controller Is Ready¶
You can also call setWebView(...) after the Web component is bound to the controller via onControllerAttached(...):
Web({
src: 'https://example.com',
controller: this.webController
})
.javaScriptAccess(true)
.javaScriptProxy(this.webViewHandler.getJavaScriptProxy(this.webController))
.onControllerAttached(() => {
this.webViewHandler.setWebView(this.webController);
})
Use either approach. When using onControllerAttached(...), remove the binding call in aboutToAppear() from the previous example and retain the clearWebController() cleanup logic in aboutToDisappear().
Notes:
- When
view_path_nameis not provided, the SDK does not add this field; when it is provided, its value is retained. Whenview_referreris not provided, it falls back to the current native View. - The
sdk_versionof WebView data is based on the native SDK; Browser SDK version information is retained insdk_pkg_info.
Common Troubleshooting Entry Points¶
- When WebView data is not reported, check the corresponding collection switch, Host allowlist, and
FTWebViewHandlerbinding. For how to enable diagnostic logs, see Troubleshooting. - To collect WebView Session Replay, it is recommended to first start native Replay and complete
FTWebViewHandlerbinding, and then load the web page Browser SDK. For details, see HarmonyOS Session Replay (Experimental).