What is the JS for closing the snipcart modal when using the back button of the browser?

I’ve been researching the history API and hash changing but I can’t figure out how to achieve the effect snipcart has done for closing the snipcart menu if its open and you’ve navigated back.

Does anyone know how this is done?

Thanks,