Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MockCordovaWebViewImpl implements CordovaWebView {
private CapacitorCordovaCookieManager cookieManager;
private WebView webView;
private boolean hasPausedEver;
private volatile boolean destroyed = false;

MockCordovaWebViewImpl(Context context) {
this.context = context;
Expand Down Expand Up @@ -172,6 +173,7 @@ public void handleStop() {

@Override
public void handleDestroy() {
destroyed = true;
if (!isInitialized()) {
return;
}
Expand All @@ -186,7 +188,11 @@ public void sendJavascript(String statememt) {

public void eval(final String js, final ValueCallback<String> callback) {
Handler mainHandler = new Handler(context.getMainLooper());
mainHandler.post(() -> webView.evaluateJavascript(js, callback));
mainHandler.post(() -> {
if (!destroyed) {
webView.evaluateJavascript(js, callback);
}
});
}

public void triggerDocumentEvent(final String eventName) {
Expand Down
8 changes: 7 additions & 1 deletion android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class Bridge {
private Boolean canInjectJS = true;
// A reference to the main WebView for the app
private final WebView webView;
private volatile boolean webViewDestroyed = false;
private BridgeWebViewClient webViewClient;
private App app;

Expand Down Expand Up @@ -786,7 +787,11 @@ public void callPluginMethod(String pluginId, final String methodName, final Plu
*/
public void eval(final String js, final ValueCallback<String> callback) {
Handler mainHandler = new Handler(context.getMainLooper());
mainHandler.post(() -> webView.evaluateJavascript(js, callback));
mainHandler.post(() -> {
if (!webViewDestroyed) {
webView.evaluateJavascript(js, callback);
}
});
}

public void logToJs(final String message, final String level) {
Expand Down Expand Up @@ -1278,6 +1283,7 @@ public void onDestroy() {
* Handle onDetachedFromWindow lifecycle event
*/
public void onDetachedFromWindow() {
webViewDestroyed = true;
webView.removeAllViews();
webView.destroy();
}
Expand Down