Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logging HTTP request start and finish from embedded Android WebView

I'm looking for a way to log the requests and start/end times made by an embedded webview. I'm not able to find a way to do it so far other than rooting the phone and running tcpdump. That works for me, but I need to run this in the field, so that's not really viable. There are lots of ways to log the URL and start time, but I can't see the finish (or, bonus, the full response metadata).

shouldLoadResource could work if I could wrap the current request, but I'd have to fetch it myself with HTTP support in order to return it en masse, because there isn't enough API exposed to fully forward to the inner request. (I don't want to do that for a number of reasons, including that webview on devices doesn't use the same network stack as the HTTP classes, and because it will change the timing of subresources.)

I've been trying to find ways to turn on chromium_net debug flags to do this, but I can't figure out how do do that in the context of the WebView or system properties.

I would really rather not ship my own webcore to do this, but if needs must...

like image 220
shaver Avatar asked Feb 13 '12 21:02

shaver


1 Answers

override method shouldInterceptRequest()

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

    return super.shouldInterceptRequest(view, url);
}
like image 127
bma350 Avatar answered Nov 02 '22 23:11

bma350