Advanced
WebView Interception#
WebView interception is a fallback, not the default. Prefer regular OkHttp + HTML parsing unless the upstream site requires browser execution or JS-based challenge handling.
Overview#
Core Stubs now exposes WebView integration through WebViewInterceptor, which extends WebViewDriver and can be added to an OkHttpClient when a request needs browser-based interception.
This is the recommended path now that the legacy provider WebView flow is deprecated.
WebViewInterceptor#
WebViewInterceptor lives in the Core Stubs OkHttp helpers and can be attached to a client with:
val clientWithWebView = client.addWebViewInterceptor(myWebViewInterceptor)API reference:
Example skeleton#
class CaptchaInterceptor(context: Context) : WebViewInterceptor(context) {
override val name: String = "CAPTCHA Interceptor"
override val isHeadless: Boolean = false
override val shouldClearCache: Boolean = true
override val shouldClearCookies: Boolean = true
override fun intercept(chain: Interceptor.Chain): Response {
// Run your browser challenge flow here, then return the final response.
return chain.proceed(chain.request())
}
}Use WebView interception only for the specific requests that need it.
Keep the interceptor logic small and deterministic, and always call destroy() when the flow is finished.
Common use cases#
- CAPTCHA or anti-bot challenge resolution
- JS-rendered request handoff
- Cookie/bootstrap flows that require a browser context
Common issues#
- Memory leaks from long-lived WebView instances
- Threading mistakes around main-thread WebView APIs
- Excessive resource usage from repeated interception
