Skip to content

Commit 8b60dca

Browse files
dpoguegwynjudd
andauthored
fix: Avoid showing error page on cancelled navigation (#1483)
This was previously implemented back in the UIWebView days as CB-13222 in #334 and was then proposed in apache/cordova-plugin-wkwebview-engine#84 for the WKWebView plugin, but that didn't get reviewed/merged before the repo was archived. The fix is still valid, so we'll port it to the current version of the WKWebView plugin. Closes GH-959. Co-authored-by: Gwyn Judd <gjudd@stayinfront.com>
1 parent b6ae567 commit 8b60dca

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,17 +509,17 @@ - (void)webView:(WKWebView*)theWebView didFailProvisionalNavigation:(WKNavigatio
509509

510510
- (void)webView:(WKWebView*)theWebView didFailNavigation:(WKNavigation*)navigation withError:(NSError*)error
511511
{
512-
CDVViewController* vc = (CDVViewController*)self.viewController;
513-
514512
NSString* message = [NSString stringWithFormat:@"Failed to load webpage with error: %@", [error localizedDescription]];
515513
NSLog(@"%@", message);
516514

517-
NSURL* errorUrl = vc.errorURL;
518-
if (errorUrl) {
519-
NSCharacterSet *charSet = [NSCharacterSet URLFragmentAllowedCharacterSet];
520-
errorUrl = [NSURL URLWithString:[NSString stringWithFormat:@"?error=%@", [message stringByAddingPercentEncodingWithAllowedCharacters:charSet]] relativeToURL:errorUrl];
521-
NSLog(@"%@", [errorUrl absoluteString]);
522-
[theWebView loadRequest:[NSURLRequest requestWithURL:errorUrl]];
515+
if (error.code != NSURLErrorCancelled) {
516+
NSURL* errorUrl = self.viewController.errorURL;
517+
if (errorUrl) {
518+
NSCharacterSet *charSet = [NSCharacterSet URLFragmentAllowedCharacterSet];
519+
errorUrl = [NSURL URLWithString:[NSString stringWithFormat:@"?error=%@", [message stringByAddingPercentEncodingWithAllowedCharacters:charSet]] relativeToURL:errorUrl];
520+
NSLog(@"%@", [errorUrl absoluteString]);
521+
[theWebView loadRequest:[NSURLRequest requestWithURL:errorUrl]];
522+
}
523523
}
524524
}
525525

0 commit comments

Comments
 (0)