feat(injectedJavaScript): Error replaced by warnings, and callback runs

* 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
This commit is contained in:
Gary Fung 2019-08-04 01:43:04 -07:00 committed by Thibault Malbranche
parent 9e41a2b451
commit 3baebf84db
1 changed files with 5 additions and 6 deletions

View File

@ -795,12 +795,11 @@ static NSURLCredential* clientAuthenticationCredential;
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]);
}
}];
}