PROVISIO DevBlog

How to Delete HTML5 Web Storage Content

HTML5 Web Storage is intended to store content locally on a PC for longer periods, e.g. for working offline. The web page/web app that stores the content is responsible for deleting it as well, therefore SiteKiosk does not delete Web Storage content by design.

In case you come across a project, where you can't influence the behaviour of a web page that uses Web Storage but need to delete the content nonetheless, you may use the scripting options of SiteKiosk to handle that situation.

The following script makes use of the OnReset and OnScreenSaverBegin events of the SiteKiosk Object Model to trigger deleting the Web Storage content. OnReset fires when a person hits the logout button of SiteKiosk or when a Pay session runs out. OnScreenSaverBegin fires once the screensaver starts. Note that deleting the Web Storage requires a restart of SiteKiosk to also clear the Web Storage content from the currently running instance of the browser. This means that the screensaver will only run for the time we define as the wait time for the content deletion to happen, if we use the OnScreenSaverBegin event. Please consider this fact for your project.

Next we need to wait a few seconds to let SiteKiosk run through the default processes that happen if any of the above events occur. To make SiteKiosk wait, we use the AddDelayedEvent method.

The next step is to actually delete the Web Storage content. For that we use the FileSystemObject of Windows Scripting. Be aware that the location of the folder (C:\Users\[User Name]\AppData\Local\Microsoft\Internet Explorer\DOMStore) that needs to be deleted is user sensitive. Make sure to use the path that is appropriate for the user you run SiteKiosk under. In most cases SiteKiosk will run under the restricted SiteKiosk Windows user, therefore the script we are building uses the path suitable for this environment: C:\Users\SiteKiosk\AppData\Local\Microsoft\Internet Explorer\DOMStore.

The final step is to make a restart of SiteKiosk. Without the restart the current browser instance will still use a cached version of the Web Storage content.

The script looks like this:

//Initializing the events we want to use to delete Web Storage
SiteKiosk.OnReset = WaitBeforeDelete;
SiteKiosk.ScreenSaver.OnScreenSaverBegin = WaitBeforeDelete; //Note that using the screensaver event will basically stop the screensaver from running longer than the wait time defined below, because of the required SiteKiosk restart.

function WaitBeforeDelete()
{
	//Give SiteKiosk some time to run through its default session end/screensaver activation methods
	evtid = SiteKiosk.Scheduler.AddDelayedEvent(5000, DeleteWebStorage);
}

function DeleteWebStorage(eventID)
{  
	try
	{	 
		//Deleting the folder with the help of the FileSystemObject
		var fso = new ActiveXObject("Scripting.FileSystemObject");
 		fso.DeleteFolder("C:\\Users\\SiteKiosk\\AppData\\Local\\Microsoft\\Internet Explorer\\DOMStore", true);
 		SiteKiosk.Logfile.Notification("Deleting the Web Storage content was successful");

		//Required restart to clear the Web Storage from the temporary cache of the current browser instance
		SiteKiosk.Restart();
 	}
	catch (e)
	{
		//Create a SiteKiosk logfile entry in case something goes wrong
		SiteKiosk.Logfile.Notification("There was an error deleting the Web Storage content: " + e.description);
	}
}

Save the script under any name as a javascript file, e.g. DeleteWebStorage.js. Put the file in the ..\SiteKiosk\html folder and then open the SiteKiosk configuration and go to Start Page & Browser, click on Advanced and add the script file as an external script under Execute Script.

If you run the script and monitor the logfiles, a successful deletion of the Web Storage will look like this in the moment of the necessary restart of SiteKiosk: