Skip to content

Inspect and intercept full HTTP requests sent from Android WebViews

License

Notifications You must be signed in to change notification settings

acsbendi/Android-Request-Inspector-WebView

Repository files navigation

Android Request Inspector WebView Release

Inspect and intercept full HTTP requests (including all headers, cookies and body) sent from Android WebViews.

This project is inspired by android-post-webview and request_data_webviewclient and some code was taken from both projects.

Installation

Step 1. Add the JitPack repository to your build file:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.acsbendi:Android-Request-Inspector-WebView:1.0.8'
}

Get the latest version on JitPack

Usage

To log the requests (default functionality):

    val webView = WebView(this)
    webView.webViewClient = RequestInspectorWebViewClient(webView)

To manually process requests:

    val webView = WebView(this)
    webView.webViewClient = object : RequestInspectorWebViewClient(webView) {
        override fun shouldInterceptRequest(
            view: WebView,
            webViewRequest: WebViewRequest
        ): WebResourceResponse? {
            TODO("handle request manually based on data from webViewRequest and return custom response")
            return super.shouldInterceptRequest(view, webViewRequest)
        }
    }

Known limitations

Detailed data (e.g. request body) is not available for requests sent from iframes as it's not possible to execute JavaScript code in iframes in Android WebViews. One possible workaround to still inspect the requests sent from a specific iframe is to load its URL into a different WebView and attach RequestInspectorWebViewClient to that.

Contributions

All feedback, PRs, and issues are welcome!

License

The MIT License

See LICENSE