Interface for Request Data
Collecting WebView Configuration
To collect WebView data, set setDomStorageEnabled(true) and call setWebViewClient() method. If these methods are not called in the embedding App, please add the following content:
WebSettings webSettings = webview.getSettings();
webSettings.setDomStorageEnabled(true);
webview.setWebViewClient(new WebViewClient(){});
-
Automatically Injecting JS Probe
To enable automatic injection of JS probe, call isHookWebChromeClient(true) during SDK initialization.
Automatic injection of JS probe will replace WebChromeClient with the implementation class of the NBS SDK. If compatibility issues arise, please contact technical support or switch to manual injection of JS probe.
-
Related Interface
/**
* @param isHookWebChromeClient Whether to automatically inject JS probe, default is false
*/
NBSAppAgent.isHookWebChromeClient(boolean isHookWebChromeClient) -
Code Example
NBSAppAgent.setLicenseKey("AppKey")
.setRedirectHost("Host")
.isHookWebChromeClient(true)// Enable automatic injection of JS probe
.start(this.getApplicationContext());
-
-
Manually Injecting JS Probe
-
Related Interface
/**
* This method should be called in the onProgressChanged() method of WebChromeClient to collect WebView data
* @param view The WebView object
* @param newProgreess The 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);
}
});
-
Collecting X5 WebView Configuration
To collect WebView data, call setDomStorageEnabled() and setWebViewClient() methods. If these methods are not called in the embedding App, please add the following content:
WebSettings webSettings = webview.getSettings();
webSettings.setDomStorageEnabled(true);
webview.setWebViewClient(new WebViewClient(){})
-
Automatically Injecting JS Probe
To enable automatic injection of JS probe, call isHookWebChromeClient(true) during SDK initialization.
Note: Automatic injection of JS probe will replace WebChromeClient with the implementation class of the NBS SDK. If compatibility issues arise, please contact technical support or switch to manual injection of JS probe.
-
Related Interface
/**
* @param isHookWebChromeClient Whether to automatically inject JS probe, default is false
*/
NBSAppAgent.isHookWebChromeClient(boolean isHookWebChromeClient) -
Code Example
NBSAppAgent.setLicenseKey("AppKey").setRedirectHost("Host")
.isHookWebChromeClient(true)// Enable automatic injection of JS probe
.start(this.getApplicationContext());
-
-
Manually Injecting JS Probe
-
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);// Needs to set WebChromeClient and call initJSMonitorX5 method in onProgressChanged method
}
});
-
-
Add JsBridge
Note: When manually injecting JS probe, JsBridge needs to be added as well. This configuration is ignored if automatic injection of JS probe is enabled.
-
Related Interface
/**
* @param x5WebView X5 WebView instance
*/
NBSWebChromeX5Client.addWebViewBridge(WebView x5WebView); -
Code Example
NBSWebChromeX5Client.addWebViewBridge(x5WebView);//Call after generating 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);
}
});
Request Content Collection
After calling this interface, the SDK will collect the request headers, response headers, request bodies, and response bodies of Http/Https requests.
Request bodies will be collected when the Content-Type value in the request header is application/json, application/x-www-form-urlencoded, or text/plain. Response bodies will be collected when the Content-Type value in the response header is application/json or text/plain.
Note: The request content collection feature is enabled only when the platform's "Collect Network Request Content" is enabled and this interface is called.
- Related Interface
/**
* @param enabled Default is false. Set to true to enable the SDK to collect request content
*/
*/
enableNetworkContentRecord(boolean enabled)
- Code Example
NBSAppAgent.setLicenseKey("AppKey").setRedirectHost("Host")
.enableNetworkContentRecord(true)// Collect request content
.start(this.getApplicationContext());
Custom Request Header/Body Collection
After calling this interface, you can customize the request header/body information to be collected. Multiple calls will override previous configurations.
Note: If both the platform and the interface are configured with request header collection, the interface configuration takes precedence. Body collection only supports okhttp3.
- Related Interface
/**
* @param headerCallBack Intercept the network header data collected by the SDK
* @param bodyCallBack Intercept the 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) {
//Do not collect x-tingyun request header when the requested URL contains www.tingyun.com
if(url.contains("www.tingyun.com")){
headers.remove("x-tingyun");
return haaders;
}else{
return headers;
}
}
});
NBSAppAgent.setRequestBodyCallback(new INBSNetworkBody() {
@Override
public String processBody(String url, String body) {
//Return custom request body information when the requested URL contains www.tingyun.com
if(url.contains("www.tingyun.com")){
//Return custom request body information
return "";
return "";
}else{
return body;
}
}
});
Custom Response Header/Body Collection
After calling this interface, you can customize the response header/body information to be collected. Multiple calls will override previous configurations.
Note: If both the platform and the interface are configured with response header collection, the interface configuration takes precedence. Body collection only supports okhttp3.
- Related Interface
/**
* @param headerCallBack Intercept the network header data collected by the SDK
* @param bodyCallBack Intercept the 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) {
//Do not collect x-tingyun-data response header when the requested URL contains www.tingyun.com
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) {
//Return custom response body information when the requested URL contains www.tingyun.com
if(url.contains("www.tingyun.com")){
//Return custom response body information
}else{
return body;
}
}
});