How to remember variable after tab is closed

I want to make the game remember a variable after the tab is closed. I tried using localstorage.setItem, but it didnt work for some reason. the variable is a variable in my open world game that is used for checkpoints. when you die you will respawn in the last checkpoint you touched.

whenever I use localStorage.setItem, I just see the background of my game and nothing else.

Perhaps you will find it useful for yourself.
https://github.com/lcavadas/browser-storage-js
https://agnostic.github.io/LocalDB.js/

the second link looks amazing! thanks a lot!