0

I have a Kiosk App that will be used to collect public signups and the signup page is a public website that is displayed in a controlled WebView. I need to clear all of the user's personal data from the WebView cache but can't seem to do that using the Documented procedures.

Here is my WebView markup:

<div><webview id="wv" style="width:100%; height:95%;position:absolute;margin:0px;padding:0px;" partition="extraContent"></webview></div>

Here is the code I use to clear the cache and storage:

 var webview = document.getElementById("wv");
 var options = {
  'since':1000000000
};
var caches = {
  "appcache": true,
    "cache": true,
    "cookies": true,
    "fileSystems": true,
    "indexedDB": true,
    "localStorage": true,
    "webSQL": true
};
webview.clearData(options, caches, function() {
  webview.terminate();
  $("webview").remove();
  appendWebview();
});

When clearData didn't do the job, I started terminating the view entirely and adding a new one with the same markup. Yet still I can see personal details when the new WebView loads. Why is this happening and how can I remove the data?

Xan
  • 74,770
  • 16
  • 179
  • 206
  • When you create the new webview, are you using the same partition id as before? – Sarah Elan Oct 08 '15 at 18:21
  • Yes, exact same markup –  Oct 08 '15 at 18:22
  • You could try using a different partition id each time you create a new webview, so you can be sure that you aren't still using the same storage partition. – Sarah Elan Oct 08 '15 at 18:27
  • 1
    I specifically use that partition because I need access to some local html pages to blend offline content with the signup and other web pages –  Oct 08 '15 at 18:30
  • I even just tried making multiple partitions, all copies of the first one, and switching between them when ending the session. Data still persists once you get back to a partition that the web view used as storage. –  Oct 08 '15 at 18:38
  • 1
    Why, arbitrarily, `'since': 1000000000`? Also, have you tried logging `chrome.runtime.lastError` inside the callback? – Xan Oct 09 '15 at 10:59
  • I tried the large number, in case the default 0 value wasn't actually clearing all data. –  Oct 11 '15 at 04:57
  • It can be problem with client javascript code. I want to demonstrate example of code I stumbled with: ``deferredArray = []; $('webview').each(function(i, webview){ var deferred = new $.Deferred(); webview.clearData({since: 0}, clearDataType, function(){ deferred.resolve(); // <--- resource hog }); deferredArray.push(deferred); }); $.when.apply($, deferredArray).then(function() { if(cb) cb(); });`` Here cb() gets called at deferred.resolve() and recreates webview. Try to move your code outside of the callback. – Vlad Jun 21 '18 at 16:33

1 Answers1

0

It seems that currently it isn't possible to do what I want (seriously?): Similar SO Question

There is however a workaround for my particular use case. I can display the local content in a normal view, or even it's own webview, and then use a unique, dummy partition ID for webviews showing web content. When the session should be ended I can generate a new unique partition ID and use that to start a new webview that will not have access to the cache of the previous one.

For anyone else having similar issues, this is not the only unacceptable and buggy behavior I've found on this platform and it should be avoided for serious projects until the Chromium team can produce a more stable product.

Community
  • 1
  • 1
  • You'll notice that the bug that your link mentions has been already fixed. It specifically referred to clearing web cache, not the other types of things you want to clear. – Xan Oct 09 '15 at 10:56
  • 1
    If you see the behavior described though, it looks like a bug; boil your app down to a minimal example and do _every Chrome app developer_ a favor by [submitting it as a bug](http://crbug.com/). – Xan Oct 09 '15 at 10:59
  • I will try your suggestion of running chrome.runetime.lastError in the clearData callback and report back! –  Oct 11 '15 at 04:57
  • The runtime.lastError is undefined, so it is a bug. I have noticed that some information is deleted after calling clearData, but not all, thus my issue remains. –  Oct 11 '15 at 23:21