diff --git a/packages/app-mobile/components/ExtendedWebView/index.tsx b/packages/app-mobile/components/ExtendedWebView/index.tsx index 68279c5f0d5..e5ff0e2709c 100644 --- a/packages/app-mobile/components/ExtendedWebView/index.tsx +++ b/packages/app-mobile/components/ExtendedWebView/index.tsx @@ -87,6 +87,17 @@ const ExtendedWebView = (props: Props, ref: Ref) => { return Setting.value('env') === 'dev' || (!!props.hasPluginScripts && Setting.value('plugins.enableWebviewDebugging')); }, [props.hasPluginScripts]); + const [reloadCounter, setReloadCounter] = useState(0); + const refreshWebViewAfterCrash = useCallback(() => { + // Reload the WebView on crash. See https://github.com/react-native-webview/react-native-webview/issues/3524 + logger.warn('Content process lost. Reloading the webview...'); + shim.setTimeout(() => { + setReloadCounter(counter => counter + 1); + // Restart after a brief delay to mitigate the case where the crash is due to + // an out-of-memory or content script bug. + }, 250); + }, []); + // - `setSupportMultipleWindows` must be `true` for security reasons: // https://github.com/react-native-webview/react-native-webview/releases/tag/v11.0.0 @@ -99,6 +110,7 @@ const ExtendedWebView = (props: Props, ref: Ref) => { // (the default deaccelerates too quickly). return ( ) => { onMessage={props.onMessage} onError={props.onError ?? onError} onLoadEnd={props.onLoadEnd} + onContentProcessDidTerminate={refreshWebViewAfterCrash} + onRenderProcessGone={refreshWebViewAfterCrash} decelerationRate='normal' /> );