Using React Native Webview in iOS App is crashing intermittently

Viewed 1038

I have a react native iOS application (version 0.62.2) using react-native-webview plugin latest version 11.x to render few webview screens in the App. Recently noticed in the crash logs that sometimes the webview screens crash intermittently on launch. Got below exception from the error logs of the sessions.

Error

NSInvalidArgumentException *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]

Need inputs on the below point:

  1. How to decode this error? If I try to replicate the same behavior on xcode I get the error 1 out of 5 times and it points to the webview plugin. enter image description here

  2. Is there a way to try/catch this error so that the App at least does not crash? I tried error boundary but that will not catch this exception.

Update: adding code as requested

<View height={getScreenHeight() - 150}>
    <KeyboardAvoidingView {...keyboardBehavior}>
      <WebView
        style={isApplyDeviceHeight ? styleWithHeight : style}
        originWhitelist={['*']}
        javaScriptEnabled
        injectedJavaScript={this.captureAnchors()}
        startInLoadingState
        thirdPartyCookiesEnabled={thirdPartyCookiesEnabled}
        source={{
          uri: this.updateUrl(pageUrl),
          headers: {'channel': WebViewHeaderChannel},
        }}
        onMessage={this.handleWebViewEvents}
        useWebKit={isIOSDevice}
        allowsInlineMediaPlayback
      />
    </KeyboardAvoidingView>
  </View>


updateUrl = webURL => {
const {webAppDomain, siteId} = getAPIConfig();
const url = this.updateToken(webURL);
let URL = url;
// url path transformation in case of absolute image URL
if (/^http/.test(url)) {
  URL = url ? url.replace(/^\//, '') : '';
} else if (webURL.includes(`/${siteId}/`)) {
  // url path transformation in case of relative image URL
  URL = `${webAppDomain}${url}`;
} else {
  URL = `${webAppDomain}/${siteId}${url}`;
}
return URL;

};

Any help is greatly appreciated.

0 Answers
Related