Skip to content

Commit

Permalink
feat(injectedJavaScript): Error replaced by warnings, and callback runs
Browse files Browse the repository at this point in the history
* Changes error/redbox into warning/yellowbox. So wouldn't crash production releases
* Warning added actual error, useful for debugging bad JS injected into webview
* callback runs, whether there's error or not. As used in my app (https://medium.com/wonderswipe/rethink-mobile-search-10-100x-faster-introducing-wonderswipe-6f2ff0d0e667) which injects JS into sanitized html from the wild, small error in injected JS doesn't warrant the whole JS payload from being injected/run
  • Loading branch information
fungilation authored and Titozzz committed Aug 4, 2019
1 parent 9e41a2b commit 3baebf8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions ios/RNCWKWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,11 @@ - (void)evaluateJS:(NSString *)js
thenCall: (void (^)(NSString*)) callback
{
[self.webView evaluateJavaScript: js completionHandler: ^(id result, NSError *error) {
if (error == nil) {
if (callback != nil) {
callback([NSString stringWithFormat:@"%@", result]);
}
} else {
RCTLogError(@"Error evaluating injectedJavaScript: This is possibly due to an unsupported return type. Try adding true to the end of your injectedJavaScript string.");
if (callback != nil) {
callback([NSString stringWithFormat:@"%@", result]);
}
if (error != nil) {
RCTLogWarn([NSString stringWithFormat:@"Error evaluating injectedJavaScript: This is possibly due to an unsupported return type. Try adding true to the end of your injectedJavaScript string. %@", error]);
}
}];
}
Expand Down

0 comments on commit 3baebf8

Please sign in to comment.