compose-webview-multiplatform
compose-webview-multiplatform copied to clipboard
onInterceptUrlRequest not working
I was trying to block some urls using onInterceptUrlRequest but when the webview loads the urls it does not activate. I am using the same example from the documentation.
val navigator =
rememberWebViewNavigator(
requestInterceptor =
object : RequestInterceptor {
override fun onInterceptUrlRequest(
request: WebRequest,
navigator: WebViewNavigator,
): WebRequestInterceptResult {
return if (request.url.contains("kotlin")) {
WebRequestInterceptResult.Reject
} else {
WebRequestInterceptResult.Allow
}
}
},
)
@orelvis15 Could you provide more code?
same here, using 1.9.20, here are the code snippets:
class MyRequestInterceptor : RequestInterceptor {
val lastRequest = mutableStateOf<WebRequest?>(null)
override fun onInterceptUrlRequest(request: WebRequest, navigator: WebViewNavigator): WebRequestInterceptResult {
println("intercepting url: ${request.url}")
lastRequest.value = request
return WebRequestInterceptResult.Allow
}
}
...
val interceptor by remember { mutableStateOf(MyRequestInterceptor()) }
...
val navigator = rememberWebViewNavigator(requestInterceptor = interceptor)
...
Text("Last Request: ${interceptor.lastRequest.value?.url}", Modifier.matchParentSize())
...
There is nothing printed and also lastRequest never gets updated. Looks like the intercepter is never injected.
jftr: it looks like the first initial request is not intercepted. and also only requests for loading the whole view are intercepted. this made it look like the interceptor is not working at all.
jftr: it looks like the first initial request is not intercepted. and also only requests for loading the whole view are intercepted. this made it look like the interceptor is not working at all.
Yes, it is designed to have the same behavior as Android WebView's onInterceptRequest.
Same problem here. Request headers is always empty
val navigator = rememberWebViewNavigator(
requestInterceptor =
object : RequestInterceptor {
override fun onInterceptUrlRequest(
request: WebRequest,
navigator: WebViewNavigator,
): WebRequestInterceptResult {
Logger.d("URL ${request.url}")
Logger.d("HEADERS ${request.headers}")
return WebRequestInterceptResult.Allow
}
},
)
Hello, good afternoon, any updates?
I find that iOS intercepts the first request, Android does not intercept the first request, and there are some differences