My goal is that whenever the user closes and comes back to the website it recognizes where he/she was and automatically goes back to the topic the user was reading.
There may be a simpler way to do this, but this is the way I found most intuitive.
document.addEventListener("DOMContentLoaded", () => {
// document has been loaded!
if (localStorage.getItem("scrollY") !== null)
window.scrollTo(0, localStorage.getItem("scrollY"));
});
document.addEventListener("scroll", () => {
// user scrolled!
localStorage.setItem("scrollY", window.scrollY);
});