Android-Request-Inspector-WebView icon indicating copy to clipboard operation
Android-Request-Inspector-WebView copied to clipboard

Is possible to change body content?

Open momadvisor opened this issue 3 years ago • 5 comments

First of all, I deeply appreciate this very good project. I wonder If a changed request does not make any problem when I change some body content.

ex. override fun shouldInterceptRequest( view: WebView, webViewRequest: WebViewRequest ): WebResourceResponse? { webViewRequest.body = changedBodyString return super.shouldInterceptRequest(view, webViewRequest) }

momadvisor avatar Jun 09 '22 07:06 momadvisor

I'm glad to hear!

This library does not actually send the request, it just inspects it. So changing the body has no effect. However, it wouldn't be difficult to implement that functionality: you have to copy the data from WebViewRequest to e.g. okhttp's Request, then send it, then return the response in a WebResourceResponse. Do you think it would be a good idea to include such a feature in this library itself?

acsbendi avatar Jun 09 '22 14:06 acsbendi

Thanks for your good suggestions. And In my opinion about your ask... Yea. I think many people want such features. I could find many questions on google about how to change body content of WebView Request.

momadvisor avatar Jun 29 '22 05:06 momadvisor

I agree, it seems like a useful feature. Would you like to make that contribution? I can help and review it:)

acsbendi avatar Jul 24 '22 21:07 acsbendi

Hi, is it possible to achieve the "changing response content/receiving the response" feature by adding some JS listeners to JAVASCRIPT_INTERCEPTION_CODE?

MostafaAryan avatar Jan 18 '24 21:01 MostafaAryan

@MostafaAryan It's probably possible, but that doesn't seem like an easy/optimal way. Since, if everything works as expected, we have all the data in Kotlin, it's much simpler to execute the request in Kotlin, and then return the result to the Android framework, than modify the data in Javascript after passing it back from Kotlin.

acsbendi avatar Jan 24 '24 19:01 acsbendi