Most robust handling when localStorage is not available in the browser

Check for storageAvailable first so that DOM exceptions (when localStorage is unavailable) are avoided.