Skip to main content

WebView

WebView Collection Configuration

If the currently used SDK version is greater than or equal to 2.18.0, please continue adding the following configurations.

To collect WebView data, you must set setDomStorageEnabled(true), and also configure WebViewClient and WebChromeClient. If these methods are not called in your project, please add the following content.

WebSettings webSettings = webview.getSettings();
webSettings.setDomStorageEnabled(true);
webview.setWebViewClient(new WebViewClient(){});
webview.setWebChromeClient(new WebChromeClient(){});

If the currently used SDK version is lower than 2.18.0, please continue adding the following configurations.

To collect WebView data, you must set setDomStorageEnabled(true), and also configure WebViewClient and WebChromeClient. If these methods are not called in your project, please add the following content.

WebSettings webSettings = webview.getSettings();
webSettings.setDomStorageEnabled(true);
webview.setWebViewClient(new WebViewClient(){});
webview.setWebChromeClient(new WebChromeClient(){});
  • Manually inject the JS probe.

    • Related Interface

      /**
      * To collect WebView data, this API must be called in the onProgressChanged() method of WebChromeClient
      * @param view WebView object
      * @param newProgress Loading progress
      */
      NBSWebChromeClient.initJSMonitor(view, newProgress);
    • Code Example

      webview.setWebChromeClient(new WebChromeClient(){
      @Override
      public void onProgressChanged(WebView view, int newProgress) {
      NBSWebChromeClient.initJSMonitor(view, newProgress);// Manually inject the JS probe
      super.onProgressChanged(view, newProgress);
      }
      });

X5WebView Collection Configuration

If the currently used SDK version is greater than or equal to 2.18.0, please continue adding the following configurations.

To collect X5WebView data, you must set setDomStorageEnabled(true), and also configure WebViewClient and WebChromeClient. If these methods are not called in your project, please add the following content.

WebSettings webSettings = webview.getSettings();
webSettings.setDomStorageEnabled(true);
webview.setWebViewClient(new WebViewClient(){});
webview.setWebChromeClient(new WebChromeClient(){});

If the currently used SDK version is lower than 2.18.0, please continue adding the following configurations.

To collect X5WebView data, you must set setDomStorageEnabled(true), and also configure WebViewClient and WebChromeClient. If these methods are not called in your project, please add the following content.

WebSettings webSettings = webview.getSettings();
webSettings.setDomStorageEnabled(true);
webview.setWebViewClient(new WebViewClient(){});
webview.setWebChromeClient(new WebChromeClient(){});
  • Manually inject the JS probe.

    • Related Interface

      /**
      * To collect X5WebView data, this API must be called in the onProgressChanged() method of WebChromeClient
      * @param view WebView object
      * @param newProgress Loading progress
      */
      NBSWebChromeX5Client.initJSMonitorX5(view, newProgress);
    • Code Example

      webview.setWebChromeClient(new WebChromeClient(){
      @Override
      public void onProgressChanged(WebView view, int newProgress) {
      NBSWebChromeX5Client.initJSMonitorX5(view, newProgress);// Manually inject the JS probe
      super.onProgressChanged(view, newProgress);
      }
      });
  • Add JsBridge

    Note: For manual JS probe injection in X5WebView, JsBridge must also be added.

    • Related Interface

      /**
      * @param Instance of the X5WebView.
      */
      NBSWebChromeX5Client.addWebViewBridge(WebView x5WebView);
    • Code Example

      NBSWebChromeX5Client.addWebViewBridge(x5WebView);//Call after creating the X5WebView instance.

Collecting mpaas Embedded WebView Data

This interface can be used to collect mpaas embedded WebView data.

  • Related Interface
java/** 
* @param h5Page H5Page object
* @param apWebViewClient Custom APWebViewClient implementation class, pass null if not exists
* @param apWebChromeClient Custom APWebChromeClient implementation class, pass null if not exists
*/
NBSNebulaWebViewConfig.configWebView(H5Page h5Page, APWebViewClient apWebViewClient, APWebChromeClient apWebChromeClient);
  • Code Example
MPNebula.getH5ViewAsync(this, param, new H5PageReadyListener() {
@Override
public void getH5Page(H5Page h5Page) {
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
// If there is no custom APWebViewClient or APWebChromeClient, only pass the h5Page object
NBSNebulaWebViewConfig.configWebView(h5Page, null, null);

mLayout.addView(h5Page.getContentView(), lp);
}
});