The CloseWatcher API landed in Firefox 149, making it easy to listen for platform-specific 'dismiss' signals. Here's how it works:
And, of course, the full documentation on MDN https://developer.mozilla.org/en-US/docs/Web/API/CloseWatcher
CloseWatcher - Web APIs | MDN

The CloseWatcher interface allows a custom UI component with open and close semantics to respond to device-specific close actions in the same way as a built-in component.

MDN Web Docs
@firefoxwebdevs Something I noticed in the example is that if the browser does not support CloseWatcher, the "Close" button does not work.
I get that the button's event listener calls watcher.close() for demonstration purposes, but I feel that in production it would be more appropriate to call closeSidebar() instead, maybe the accompanying text should reflect that?

@axeleroy in cases where you use close watcher, you still need to destroy the close watcher.

I guess closeWatcher?.destroy(); closeSidebar(); would do it.