2525import com .facebook .react .bridge .WritableMap ;
2626import com .facebook .react .uimanager .ThemedReactContext ;
2727import com .facebook .react .uimanager .UIManagerHelper ;
28+ import com .reactnativecommunity .webview .events .SubResourceErrorEvent ;
2829import com .reactnativecommunity .webview .events .TopHttpErrorEvent ;
2930import com .reactnativecommunity .webview .events .TopLoadingErrorEvent ;
3031import com .reactnativecommunity .webview .events .TopLoadingFinishEvent ;
@@ -42,13 +43,8 @@ public class RNCWebViewClient extends WebViewClient {
4243
4344 protected boolean mLastLoadFailed = false ;
4445 protected RNCWebView .ProgressChangedFilter progressChangedFilter = null ;
45- protected @ Nullable String ignoreErrFailedForThisURL = null ;
4646 protected @ Nullable RNCBasicAuthCredential basicAuthCredential = null ;
4747
48- public void setIgnoreErrFailedForThisURL (@ Nullable String url ) {
49- ignoreErrFailedForThisURL = url ;
50- }
51-
5248 public void setBasicAuthCredential (@ Nullable RNCBasicAuthCredential credential ) {
5349 basicAuthCredential = credential ;
5450 }
@@ -173,12 +169,6 @@ public void onReceivedSslError(final WebView webView, final SslErrorHandler hand
173169 // Undesired behavior: Return value of WebView.getUrl() may be the current URL instead of the failing URL.
174170 handler .cancel ();
175171
176- if (!topWindowUrl .equalsIgnoreCase (failingUrl )) {
177- // If error is not due to top-level navigation, then do not call onReceivedError()
178- Log .w (TAG , "Resource blocked from loading due to SSL error. Blocked URL: " +failingUrl );
179- return ;
180- }
181-
182172 int code = error .getPrimaryError ();
183173 String description = "" ;
184174 String descriptionPrefix = "SSL error: " ;
@@ -210,6 +200,18 @@ public void onReceivedSslError(final WebView webView, final SslErrorHandler hand
210200
211201 description = descriptionPrefix + description ;
212202
203+ if (!topWindowUrl .equalsIgnoreCase (failingUrl )) {
204+ // If error is not due to top-level navigation, then do not call onReceivedError()
205+ Log .w (TAG , "Resource blocked from loading due to SSL error. Blocked URL: " +failingUrl );
206+ this .onReceivedSubResourceSslError (
207+ webView ,
208+ code ,
209+ description ,
210+ failingUrl
211+ );
212+ return ;
213+ }
214+
213215 this .onReceivedError (
214216 webView ,
215217 code ,
@@ -218,27 +220,27 @@ public void onReceivedSslError(final WebView webView, final SslErrorHandler hand
218220 );
219221 }
220222
223+ public void onReceivedSubResourceSslError (
224+ WebView webView ,
225+ int errorCode ,
226+ String description ,
227+ String failingUrl ) {
228+
229+ WritableMap eventData = createWebViewEvent (webView , failingUrl );
230+ eventData .putDouble ("code" , errorCode );
231+ eventData .putString ("description" , description );
232+
233+ int reactTag = RNCWebViewWrapper .getReactTagFromWebView (webView );
234+ UIManagerHelper .getEventDispatcherForReactTag ((ReactContext ) webView .getContext (), reactTag ).dispatchEvent (new SubResourceErrorEvent (reactTag , eventData ));
235+ }
236+
221237 @ Override
222238 public void onReceivedError (
223239 WebView webView ,
224240 int errorCode ,
225241 String description ,
226242 String failingUrl ) {
227243
228- if (ignoreErrFailedForThisURL != null
229- && failingUrl .equals (ignoreErrFailedForThisURL )
230- && errorCode == -1
231- && description .equals ("net::ERR_FAILED" )) {
232-
233- // This is a workaround for a bug in the WebView.
234- // See these chromium issues for more context:
235- // https://bugs.chromium.org/p/chromium/issues/detail?id=1023678
236- // https://bugs.chromium.org/p/chromium/issues/detail?id=1050635
237- // This entire commit should be reverted once this bug is resolved in chromium.
238- setIgnoreErrFailedForThisURL (null );
239- return ;
240- }
241-
242244 super .onReceivedError (webView , errorCode , description , failingUrl );
243245 mLastLoadFailed = true ;
244246
0 commit comments