In the previous recipe, we took a look at how to use the Local Storage functionality in your website. There will be instances where you might want to examine the raw information being stored in your browser—we'll take a look at how to do this within this task.
For this task, you will need at least one modern browser—this can be IE, Chrome, Safari, or Firefox. The version must be a recent one, from within the last two years. For IE users, you will also need access to a working local web server, such as WAMP Server (for PC) or MAMP for Macs. Linux users will likely have one installed, or available to install within the distribution.
Also, if you are using Firefox, you will need to avail yourself of a copy of Firebug, which you can get from https://addons.mozilla.org/en-US/firefox/addon/firebug/.
In this recipe, it is assumed that you have all four browsers installed (including a local web server for IE). You'll see how to view the raw data within each browser.
To view the content of Local Storage in a browser, perform the following steps:
webappsstore.sqlite
file within the profile
folder. You can't edit it manually there, but can do so by pressing F12 in Firefox to bring up Firebug. Click on DOM and then Show DOM Properties to show the values being stored in the Local Storage database:Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
www
folder on your PC. Ensure your web server is started. Then, open up Internet Explorer and browse to that file from within your web server.localStorage
, and press Enter. Note that this is case sensitive! You will see the contents of localStorage
:You may prefer to use one of the tools available to view the localStorage
contents in IE. Have a look at Foundstone HTML5 Local Storage Explorer 1.1, which is available as an add-in from https://addons.mozilla.org/en-US/firefox/addon/foundstone-html5-local-storage/.
In this recipe, we looked at the raw information that the browser holds, when asked to store content within its localStorage
area. While the means to view it might differ from browser to browser, the principles are still the same. Each browser will reference the contents of the localStorage
area on your client PC in similar ways. This content is stored at various locations:
%userprofiles%/Local Settings/Application Data/Microsoft/Internet Explorer/DOMStore
.webappsstore.sqlite
file in the profile
folder and you can also get hold of some add-ons to view the contents.C:Documents and Settings\%username%Local Settings\%Application Data%GoogleChromeUser DataDefault
.If you are using Vista or Windows 7, it's in C:Users\%username%\%AppData%LocalGoogleChromeUser DataDefault
.
sqllite
file in C:Users\%username%AppDataLocalApple ComputerSafariLocalStorage
. There's a Local Storage file named the same as the website storing it.If you want to get really down and dirty in your browser, you can use the console application that comes as part of each browser. It is possible to get and set values into Local or Session Storage, using the command line, in much the same way that you would do using something like JavaScript. The beauty of this is that it doesn't need any additional plugins—the exception being IE, which needs its Developer toolbar, but this is included by default anyway!
As an example, here's how you would do this if you were using Firefox. Navigate to the domain in question and open Firefox's console (Ctrl + Shift + K in Windows). You can then enter any of the following actions as shown in the examples:
localStorage.foo = "bar"
or use localStorage.setItem ("foo", "bar")
localStorage.setItem ("foo", "all day")
or use localStorage.foo = "all day"
localStorage.removeItem ("foo")
This is not the easiest way to do it, but it still works, just in case you need it.
We're going to move on and look at the second type of storage available, which is Session Storage. Although it is similar to Local Storage, there are some noticeable differences, as you will see in the next recipe.