Kaynağa Gözat

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-6f2ff0d0e6) 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
Gary Fung 5 yıl önce
ebeveyn
işleme
3baebf84db
1 değiştirilmiş dosya ile 5 ekleme ve 6 silme
  1. 5
    6
      ios/RNCWKWebView.m

+ 5
- 6
ios/RNCWKWebView.m Dosyayı Görüntüle

@@ -795,12 +795,11 @@ static NSURLCredential* clientAuthenticationCredential;
795 795
           thenCall: (void (^)(NSString*)) callback
796 796
 {
797 797
   [self.webView evaluateJavaScript: js completionHandler: ^(id result, NSError *error) {
798
-    if (error == nil) {
799
-      if (callback != nil) {
800
-        callback([NSString stringWithFormat:@"%@", result]);
801
-      }
802
-    } else {
803
-      RCTLogError(@"Error evaluating injectedJavaScript: This is possibly due to an unsupported return type. Try adding true to the end of your injectedJavaScript string.");
798
+    if (callback != nil) {
799
+      callback([NSString stringWithFormat:@"%@", result]);
800
+    }
801
+    if (error != nil) {
802
+      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]);
804 803
     }
805 804
   }];
806 805
 }