As you know, a lot of request (images, scripts, AJAX, etc.) are send when loading a single page. So I need to get all those request and inspect them.
So the question would be: How can I inspect the HTTP requests that are made when a WebView loads a page ?
I want: headers, method, status code, response, cookies.
Right now, I have:
public void onLoadResource(WebView view, String url){
Log.d("my-tag", "onLoadResource = " + url );
}
But that only shows me the URL.
Launch Chrome on your dev computer and navigate to the url chrome://inspect . This page shows you a list of webview instances running on your connected Android device. Click the inspect link next to the webview that you wish to debug. This will open a new Chrome DevTools window for inspecting the webview.
# Open a WebView in DevToolsThe chrome://inspect page displays a list of debug-enabled WebViews on your device. To start debugging, click inspect below the WebView you want to debug. Use DevTools as you would for a remote browser tab.
WebView DevTools are a set of on-device tools to help debug your WebView apps. The best way to launch WebView DevTools is to download WebView Beta, Dev, or Canary. These channels contain a launcher icon which launches WebView DevTools.
The best you can get in your app is the WebViewClient.shouldInterceptRequest
method, but that only has the URL. You currently can't get any of the things you've listed.
For debugging you can use Chrome DevTools if you're using Android 4.4.
Look here: https://gist.github.com/kibotu/32313b957cd01258cf67 where you get the http headers at android >=21
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With