Sfoglia il codice sorgente

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 anni fa
parent
commit
3baebf84db
1 ha cambiato i file con 5 aggiunte e 6 eliminazioni
  1. 5
    6
      ios/RNCWKWebView.m

+ 5
- 6
ios/RNCWKWebView.m Vedi File

@@ -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
 }