Skip to content

Commit

Permalink
Ignore "Frame load interrupted" errors in UIWebView
Browse files Browse the repository at this point in the history
Summary:
Am writing an OAuth flow using `WebView`, when the OAuth provider redirects back to the [redirect_uri](https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#logindialog) I intercept the request using `onShouldStartLoadWithRequest`, get the access token from the url and close the `WebView`.

The problem I see is that when the OAuth provider redirects to the `redirect_uri` and I intercept it by returning false from `onShouldStartLoadWithRequest`, I get a WebKitErrorDomain error code 102 ("Frame load interrupted").

Looking at some other iOS libraries that implement OAuth with a WebView - it seems that the error can be ignored. eg.

https://github.com/facebook/facebook-ios-sdk/blob/master/FBSDKCoreKit/FBSDKCoreKit/Internal/WebDialog/FBSDKWebDialogView.m#L146

https://github.com/evernote/evernote-sdk-ios/blob/master/evernote-sdk-ios/internal/ENOAuthViewController.m#L147

You can recreate the error using a url that automatically redirects, eg http://www.facebook.com -> https://www.facebook.com

```js
<WebView
  source={{ uri: 'http://www.facebook.com' }}
  onShouldStartLoadWithRequest={(event) => {
    if (event.url.startsWith('https://www.facebook.com')) {
      return false;
    }
    return true;
  }}
/>
```
Closes facebook#12482

Differential Revision: D5154115

Pulled By: shergin

fbshipit-source-id: 25151d00a1f97e17760617ee5aac6a0140c733c8
  • Loading branch information
adamjmcgrath authored and facebook-github-bot committed May 31, 2017
1 parent f1284b8 commit 23a34d4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions React/Views/RCTWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ - (void)webView:(__unused UIWebView *)webView didFailLoadWithError:(NSError *)er
return;
}

if ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102) {
// Error code 102 "Frame load interrupted" is raised by the UIWebView if
// its delegate returns FALSE from webView:shouldStartLoadWithRequest:navigationType
// when the URL is from an http redirect. This is a common pattern when
// implementing OAuth with a WebView.
return;
}

NSMutableDictionary<NSString *, id> *event = [self baseEvent];
[event addEntriesFromDictionary:@{
@"domain": error.domain,
Expand Down

0 comments on commit 23a34d4

Please sign in to comment.