you could use befoeRender event from Code pack, $items are available there as a variable, you would jsut need to loop trough them to get ids and store them in session storage.
I really couldn´t find $items variable on beforeform field. Only solution I found was make a copy of list template, and in this new template alterate index.php file to access $items variable using a loop as suggested.