Is local storage for a Phonegap app on an Android device separate from the built in browser? Is local storage for a Phonegap app on an Android device separate from the built in browser? android android

Is local storage for a Phonegap app on an Android device separate from the built in browser?


Since Phonegap uses Webiview to render your app : WebView and Phonegap.

And For security reason each app that uses WebView has its own cache and history."No User or OS wants such data to be accessed by 3rd party applications".So in a nutshell, your app will keep its own history and data in its cache folder and will be deleted in one of the following cases:

  • User manually deleted them.
  • User used app setting screen and deleted them.
  • App uninstalled.

To read more about this. take look at WebView cache : Cookie and window management


Nope, the cache created within the in-app browser can only be deleted with the methods:

window.localStorage.removeItem("key");

or

window.localStorage.clear();

or app uninstall

or manual action (delete data/cache) in the application manager.

But the best answer is to make an experiment yourself and see what happens.


Yes it is separate but there are time where you need to pass a variable of some kind to the In App Browser. It makes coding so much more easier to pass a ls item from a current webview to another one like in iOS.

Here is what I did in PhoneGap

I use the InAppBrowser executeScript() to pass a copy of the current webviews localStorage to another.

//add the listener to detect when the page loads after inappbrowser is called into viewref.addEventListener('loadstop', function(){     ref.executeScript({code: 'SetInAppBrowserLocalStorage(\''+localStorage+'\');'});});

//In your inAppBrowser page you create a function that  will get called on loadStop//This will pass "all" the contents of the main webviws localStorage to the webview //created by InAppBrowserfunction SetInAppBrowserLocalStorage(localStorageThatWasPassed){    localStorage = localStorageThatWasPassed;};

You could also clear the localStorage created by SetInAppBrowserLocalStorage() before the use leaves that view as well.

Tested and working 100% :)...let me know if you need more help

***UPDATE*****

This still works ...but not consistently anymore. After much testing I realize this is simply not the way to go. Sometimes the data simply is not passed fast enough when the inappbrowser instance is created. I talked to the cordova guys via there issue tracker and they told me it wasn't a secure way of doing things...I get that...but my response to them was what if I just want to pass ls variables between pages in my app..those are not even accessible from the internet... I honestly don't understand why the ls items can't be accessible globally in the app like it is in iOS and the rest of the web. If anyone has a better solution I would love to hear about it.