Check for existence of localStorage object before trying to index it.