Logging the start and end of an HTTP request from the embedded Android WebView

I am looking for a way to log requests and start / end times made by the built-in webview. I cannot find a way to do this so far, except rooting the phone and running tcpdump. This works for me, but I need to run this in a field, so this is not real. There are many ways to register the URL and start time, but I do not see the end (or, bonus, metadata of the full response).

shouldLoadResource could work if I could wrap the current request, but I would have to get it directly with HTTP support in order to return it in bulk, because the API is not enough to go completely to the internal request. (I don’t want to do this for a number of reasons, including the fact that web browsing on devices does not use the same network stack as the HTTP classes, and because it will change the subresource time.)

I am trying to find ways to enable the chromium_net debug flags for this, but I cannot figure out how to do this in the context of WebView or system properties.

I really would not post my own website to do this, but if needs should ...

+6
source share
2 answers

override method shouldInterceptRequest()

 @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { Log.d(LOG_TAG, "shouldInterceptRequest: " + url); return super.shouldInterceptRequest(view, url); } 
+2
source

In this case, you can also add WebViewClient (see http://developer.android.com/reference/android/webkit/WebViewClient.html ). What will look like

 WebView webView.setWebViewClient(new MyWebViewClient()); . . . public class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // Note time // Return false to say we want the WebView to handle the url. return false; } @Override public void onPageFinished (WebView view, String url) { super.onPageFinished(view, url); // Note time } } 

Note that both shouldOverrideUrlLoading and onPageFinished are called only for the main frame - they will not be called for iframes or framesets. But that should give you what you need.

0
source

Source: https://habr.com/ru/post/908374/


All Articles