Algolia: restore scroll position

I open algolia search results page(or category), then scroll down and click on some product. After I click Back button on browser and we must go to the same scroll position. But I at the Top.

What we need to do for save scroll down position?

I saw similar themes here, but there no solution for VanillaJs specially. I use it on Magento 2.

Hello, currently, your best option is to save the scroll position:

$(window).scroll(function () {
//set scroll position in session storage
sessionStorage.scrollPos = $(window).scrollTop();
});
var init = function () {
//return scroll position in session storage
$(window).scrollTop(sessionStorage.scrollPos || 0);
$(’.ap-dropdown-menu’).remove();

};
window.onload = init;

As described by other users: