KevinnZou / compose-webview-multiplatform

WebView for JetBrains Compose Multiplatform
https://kevinnzou.github.io/compose-webview-multiplatform/
Apache License 2.0
351 stars 44 forks source link

Add shouldInterceptRequest method #180

Open TelephoneTan opened 2 weeks ago

TelephoneTan commented 2 weeks ago

Android WebView has a method called shouldInterceptRequest, it is used to support fully control over every request. We can use whatever we want as the response of the request by using this method.

It's good to have such method or any similar feature.

Here is my use case with Android WebView's shouldInterceptRequest:

I need to send some large messages(big image in base64 encoding, eg.) to js code, but the Android WebView has a maximum limit on the size of the data exchanged between js code and java code through the @JavascriptInterface(aka the js-bridge), so the ONLY way to achieve this is to make a "fake" HTTP request with a special url from js side, and "catch" this request in java side using shouldInterceptRequest, construct a HTTP response using the large message as the response body, and extract the large message from the HTTP response in js side later.

By the way, according to SO, it seems that we can use WKURLSchemeHandler to implement an iOS version of shouldInterceptRequest method.

KevinnZou commented 2 weeks ago

@TelephoneTan Thanks for your suggestion! I will add it to our feature plan. Feel free to submit a PR for it as well!