@@ -15,6 +15,7 @@ import androidx.webkit.WebViewAssetLoader
1515class RustWebViewClient (webView : RustWebView , context : Context ): WebViewClient() {
1616 private val interceptedState = mutableMapOf<String , Boolean >()
1717 var currentUrl: String = " about:blank"
18+ private var lastInterceptedUrl: Uri ? = null
1819 private var pendingUrlRedirect: String? = null
1920
2021 private val assetLoader = WebViewAssetLoader .Builder ()
@@ -34,10 +35,18 @@ class RustWebViewClient(webView: RustWebView, context: Context): WebViewClient()
3435 return null
3536 }
3637
38+ lastInterceptedUrl = request.url
3739 return if (Rust .withAssetLoader((view as RustWebView ).id)) {
3840 assetLoader.shouldInterceptRequest(request.url)
3941 } else {
4042 val response = Rust .handleRequest(view.id, request, view.isDocumentStartScriptEnabled)
43+ if (response != null ) {
44+ if (response.responseHeaders != null ) {
45+ response.responseHeaders[" Cache-Control" ] = " no-store"
46+ } else {
47+ response.responseHeaders = mapOf (" Cache-Control" to " no-store" )
48+ }
49+ }
4150 interceptedState[request.url.toString()] = response != null
4251 return response
4352 }
@@ -73,17 +82,13 @@ class RustWebViewClient(webView: RustWebView, context: Context): WebViewClient()
7382 // we get a net::ERR_CONNECTION_REFUSED when an external URL redirects to a custom protocol
7483 // e.g. oauth flow, because shouldInterceptRequest is not called on redirects
7584 // so we must force retry here with loadUrl() to get a chance of the custom protocol to kick in
76- //
77- // we also get a net::ERR_CONNECTION_REFUSED when a second webview tries to load http://tauri.localhost
78- // so we retry the currentUrl regardless. We do not have a timeout yet due to the amount of retries needed to make it work
79- // but we might add a timeout in the future
80- if (error.errorCode == ERROR_CONNECT ) {
85+ if (error.errorCode == ERROR_CONNECT && request.isForMainFrame && request.url != lastInterceptedUrl) {
8186 // prevent the default error page from showing
8287 view.stopLoading()
8388 // without this initial loadUrl the app is stuck
84- view.loadUrl(currentUrl )
89+ view.loadUrl(request.url.toString() )
8590 // ensure the URL is actually loaded - for some reason there's a race condition and we need to call loadUrl() again later
86- pendingUrlRedirect = currentUrl
91+ pendingUrlRedirect = request.url.toString()
8792 } else {
8893 super .onReceivedError(view, request, error)
8994 }
0 commit comments