HIJACKING localStorage<p>in chrome you can hijack basic functions in localStorage and then when they are called later, they call the replaced function.<p><pre><code> localStorage.getItem = function(val){ console.log( val ); }
//function (val){ console.log( val ); }
localStorage.getItem( "truck" );
//truck
//undefined
localStorage.getItem2 = function(val){ console.log( val ); }
//function (val){ console.log( val ); }
localStorage.getItem2( "truck" );
//TypeError: Property 'getItem2' of object #<a Storage> is not a function
</code></pre>
localStorage keys can be any unicode character.<p><pre><code> for( var i = 0; i < 32000; i ++ ){
localStorage[ String.fromCharCode(i) + "_test" ] =
String.fromCharCode(i) + "_test";
}
</code></pre>
localStorage does not have a prototype<p>but, Storage.prototype is the prototype for localStorage, so you can add methods there.<p>localStorage NAMESPACING<p>i am wondering how one should namespace content on the same page large data sets seem dangerous.<p>localStorage private keys
if a key starts with a character that is not property safe, it must be accessed via the array notation localStorage[key] rather than dot notation. using one of these chars in front of all of your keys could prevent you from overwriting key functions.<p>what are other localStorage hacks that you guys have found?