Skip to content

Commit f0d274c

Browse files
authored
The app is crashed, if any low memory issue occured
If any crash occurred due toa low memory issue, we just prevent the app from crashing and reload the webview. To test this issue please execute the following code ``` <script> function crashWebView() { try { let a = []; while (true) { a.push(new Array(1000000).fill('*')); } } catch (e) { console.log('Crashed!', e); } } crashWebView(); </script> ```
1 parent a054aa5 commit f0d274c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public void onReceivedHttpError(WebView view, WebResourceRequest request, WebRes
9797
@Override
9898
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
9999
super.onRenderProcessGone(view, detail);
100+
100101
boolean result = false;
101102

102103
List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
@@ -106,6 +107,18 @@ public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail)
106107
}
107108
}
108109

110+
if (!result) {
111+
// If no one handled it, handle it ourselves!
112+
113+
view.post(() -> {
114+
Toast.makeText(view.getContext(), "Reloading due to low memory issue", Toast.LENGTH_SHORT).show();
115+
});
116+
117+
view.reload(); // Safely reload WebView
118+
119+
return true;
120+
}
121+
109122
return result;
110123
}
111124
}

0 commit comments

Comments
 (0)