My goal is remove user cookies when browser tab closed.
Is it possible? Can I handle browser tab close event without refresh case?
If I use beforeunlo
If your goal is to remove cookies when the browser is closed, don't set expiration. Cookies without expiration are removed when the browser closes.
You really should never need to know if a user closes their browser or not. I'm confident there are alternative ways to accomplish whatever it is you're wanting to do.
The Bottom Line:
If a visitor is not on your page anymore, it really is none of your business what the user is doing with their browser or their computer. So detecting browser close will likely never be implemented without some kind of opting-in from the user, e.g., browser extensions/plugins.