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.
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 usingshouldInterceptRequest
, 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 ofshouldInterceptRequest
method.