Can you close the PWA programmatically?

By specification, only windows that are opened via scripts can be closed via w.close() call.
In my application, I have a “logout” button that cleans up certain things and executes the JS “window.close();”. It works when the application is installed as a PWA app.