Search code examples
androidioscordovarestart

Cordova: restart app and clear browser history


We are adding a feature to our Cordova app to catch unhandled exceptions and restart the app. We would like the browser history to be cleared in this case so the user can't hit back on an Android device to go back to the screen that crashed.

It isn't possible to clear the browser history programmatically, but I expected there to be a Cordova plugin that reinstantiates the whole app (i.e. deletes the current webview and creates a new one). I wasn't able to find anything like this though.

Is there a good way to do this that will work on both iOS and Android?


Solution

  • In Android for every WebView instance you can do:

    webView.clearCache(true);
    webView.clearHistory();
    webView.clearFormData();
    

    For IOS please read here: Clearing UIWebview cache