Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inspect HTTP requests made by WebViews

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.

like image 552
Francisco Corrales Morales Avatar asked Jun 02 '14 18:06

Francisco Corrales Morales


People also ask

How do I inspect in WebView app?

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.

How can I view Android WebView in Chrome?

# 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.

What is WebView DevTools?

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.


2 Answers

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.

like image 132
marcin.kosiba Avatar answered Oct 16 '22 12:10

marcin.kosiba


Look here: https://gist.github.com/kibotu/32313b957cd01258cf67 where you get the http headers at android >=21

like image 29
Jan Rabe Avatar answered Oct 16 '22 12:10

Jan Rabe