The Browser Storage Commands module provides AJAX commands to add and delete data from browser storage (either local or session).

To use it, attach the library to a page or form where you want to use it

$build['#attached']['library'][] = 'browser_storage_commands/ajax';

Then there are two AJAX commands that can be used by adding them to an AjaxResponse: