react-nativewebview

react native Webview Process Terminated


Im using react native to show a local HTML on a web view, I have noticed that some times randomly, the webView crashes, and I get the message on console:

Webview Process Terminated

I have searched about it, but cannot find any answers? what is that? why is happening? how to avoid it or reload web view after that error?

 <WebView
      style={styles.webContainer}
      originWhitelist={['*']}
      source={isAndroid ? {uri:'file:///android_asset/binaura.html'} : HTML_FILE}

      javaScriptEnabled={true}
          domStorageEnabled={true}

    />

Solution

  • If by "WebView" you mean react-native-webview:

    This happens on iOS if the WebView is using too many resources, and results in either the WebView crashing (showing a blank white page) or the app freezing.

    There is a callback property, onContentProcessDidTerminate (introduced in this PR), that you can use to listen for termination and force a reload of the WebView by updating its key. It's a bit of a hack, but it works.

    Usage example:

    class MyComponent extends Component {
      state = {
        webviewKey: 0,
      }
    
      reload() {
        this.setState({
          webviewKey: this.state.webviewKey + 1,
        })
      }
    
      render() {
        return (
          <WebView
            key={this.state.webviewKey}
            onContentProcessDidTerminate={this.reload}
          />
        )
      }
    }