Request Data
WebView Configuration for Collection
To collect WebView data, you need to set setDomStorageEnabled(true) and call the setWebViewClient() method. If the instrumented app doesn't call this method, please add the following content
WebSettings webSettings = webview.getSettings();
webSettings.setDomStorageEnabled(true);
webview.setWebViewClient(new WebViewClient(){});
-
Automatic JS Probe Injection
To enable automatic JS probe injection, call isHookWebChromeClient(true) during SDK initialization.
With automatic JS probe injection, the SDK will replace WebChromeClient with Tingyun SDK's implementation class. If compatibility issues arise, contact technical support or switch to manual JS probe injection.
-
Related interface
/**
* @param isHookWebChromeClient Whether to automatically inject JS probe, defaults to false
*/
NBSAppAgent.isHookWebChromeClient(boolean isHookWebChromeClient) -
Code example
NBSAppAgent.setLicenseKey("AppKey")
.setRedirectHost("Host")
.isHookWebChromeClient(true) // Enable automatic JS probe injection
.start(this.getApplicationContext());
-
-
Manual JS Probe Injection
-
Related interface
/**
* To collect WebView data, this interface must be called in the onProgressChanged() method of WebChromeClient
* @param view WebView object
* @param newProgreess Loading progress
*/
NBSWebChromeClient.initJSMonitor(view, newProgress); -
Code example
webview.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
NBSWebChromeClient.initJSMonitor(view, newProgress);
super.onProgressChanged(view, newProgress);
}
});
-
X5 WebView Configuration for Collection
To collect WebView data, you need to call setDomStorageEnabled() and setWebViewClient() methods. If the instrumented app doesn't call these methods, please add the following content
WebSettings webSettings = webview.getSettings();
webSettings.setDomStorageEnabled(true);
webview.setWebViewClient(new WebViewClient(){})
-
Automatic JS Probe Injection
To enable automatic JS probe injection, call isHookWebChromeClient(true) during SDK initialization.
Note: With automatic JS probe injection, the SDK will replace WebChromeClient with Tingyun SDK's implementation class. If compatibility issues arise, contact technical support or switch to manual JS probe injection.
-
Related interface
/**
* @param isHookWebChromeClient Whether to automatically inject JS probe, defaults to false
*/
NBSAppAgent.isHookWebChromeClient(boolean isHookWebChromeClient) -
Code example
NBSAppAgent.setLicenseKey("AppKey").setRedirectHost("Host")
.isHookWebChromeClient(true) // Enable automatic JS probe injection
.start(this.getApplicationContext());
-
-
Manual JS Probe Injection
-
Related interface
/**
* @param view X5 WebView instance
* @param newProgress Loading progress
*/
NBSWebChromeX5Client.initJSMonitorX5(view, newProgress); -
Code example
webview.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
NBSWebChromeX5Client.initJSMonitorX5(view, newProgress); // Need to set WebChromeClient and call initJSMonitorX5 method in onProgressChanged method
}
});
-
-
Adding JsBridge
Note: For manual JS probe injection, you also need to add JsBridge. Automatic JS probe injection ignores this configuration.
-
Related interface
/**
* @param x5WebView X5 WebView instance
*/
NBSWebChromeX5Client.addWebViewBridge(WebView x5WebView); -
Code example
NBSWebChromeX5Client.addWebViewBridge(x5WebView); // Call after creating X5WebView instance
-
mPaaS Embedded WebView Data Collection
You can collect mPaaS embedded WebView data through this interface.
- Related interface
/**
* @param h5Page H5Page object
* @param apWebViewClient If there is a custom APWebViewClient implementation class, pass this object; otherwise pass null
* @param apWebChromeClient If there is a custom APWebChromeClient implementation class, pass this object; otherwise pass null
*/
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);
// When there is no custom APWebViewClient or APWebChromeClient, only pass the h5Page object
NBSNebulaWebViewConfig.configWebView(h5Page, null, null);
mLayout.addView(h5Page.getContentView(), lp);
}
});
Request Content Collection
After calling this interface, the SDK will collect request headers, response headers, request body, and response body of Http/Https requests.
When the Content-Type value in the request header is application/json, application/x-www-form-urlencoded, or text/plain, the request body will be collected. When the Content-Type value in the response header is application/json or text/plain, the response body will be collected.
Note: The request content collection feature is only enabled when the platform's "Collect Network Request Content" is enabled and this interface is called.
- Related interface
/**
* @param enabled Defaults to false. Set to true, and the SDK will collect request content
*/
enableNetworkContentRecord(boolean enabled)
- Code example
NBSAppAgent.setLicenseKey("AppKey").setRedirectHost("Host")
.enableNetworkContentRecord(true) // Collect request content
.start(this.getApplicationContext());
Custom Request Header/Request Body Collection
After calling this interface, you can customize the collected request header/request body information. Multiple calls will override previous settings.
Note: If both platform and interface configure request header collection, interface configuration takes priority. Body collection only supports okhttp3.
- Related interface
/**
* @param headerCallBack Can intercept network header data collected by the SDK
* @param bodyCallBack Can intercept network body data collected by the SDK
*/
setRequestHeaderCallback(INBSNetworkHeader headerCallBack)
setRequestBodyCallback(INBSNetworkBody bodyCallBack)
- Code example
NBSAppAgent.setRequestHeaderCallback(new INBSNetworkHeader() {
@Override
public Map<String, String> processHeaderMap(String url, Map<String, String> headers) {
// When the request URL contains www.tingyun.com, do not collect x-tingyun request header
if(url.contains("www.tingyun.com")){
headers.remove("x-tingyun");
return headers;
}else{
return headers;
}
}
});
NBSAppAgent.setRequestBodyCallback(new INBSNetworkBody() {
@Override
public String processBody(String url, String body) {
// When the request URL contains www.tingyun.com, return custom request body information
if(url.contains("www.tingyun.com")){
// Return custom request body information
return "";
}else{
return body;
}
}
});
Custom Response Header/Response Body Collection
After calling this interface, you can customize the collected response header/response body information. Multiple calls will override previous settings.
Note: If both platform and interface configure response header collection, interface configuration takes priority. Body collection only supports okhttp3.
- Related interface
/**
* @param headerCallBack Can intercept network header data collected by the SDK
* @param bodyCallBack Can intercept network body data collected by the SDK
*/
setResponseHeaderCallback(INBSNetworkHeader headerCallBack)
setResponseBodyCallback(INBSNetworkBody bodyCallBack)
- Code example
NBSAppAgent.setResponseHeaderCallback(new INBSNetworkHeader() {
@Override
public Map<String, String> processHeaderMap(String url, Map<String, String> headers) {
// When the request URL contains www.tingyun.com, do not collect x-tingyun-data response header
if(url.contains("www.tingyun.com")){
headers.remove("x-tingyun-data");
return headers;
}else{
return headers;
}
}
});
NBSAppAgent.setResponseBodyCallback(new INBSNetworkBody() {
@Override
public String processBody(String url, String body) {
// When the request URL contains www.tingyun.com, return custom response body information
if(url.contains("www.tingyun.com")){
// Return custom response body information
}else{
return body;
}
}
});