React js ‘beforeunload’ event does not work when closing tab or browser

In React.js when I close the form page either by selecting on nav menu(redirect using hyperlink) or back arrow or others, I need send a request to server that current login user is not working on this page
hence I use this code

window.addEventListener('beforeunload', async function (e) {
                //e.preventDefault();

                await fetch('/connetion',{
                    headers : { 
                      'Content-Type': 'application/json',         
                     }
                  }) 
                   .then(res => res.json())
                   .then((data) => {
                        console.log('You left this page');
                   })
                  
            }); 

/connection is one of the server function which shows(on console/Terminal) when the request received.
like below

Listening on port 3500
[ { message: 'database connected on08-12 07:20:47' } ]
[ { message: 'database connected on08-12 07:20:57' } ]
[ { message: 'database connected on08-12 07:20:57' } ]
[ { message: 'database connected on08-12 07:25:55' } ]
[ { message: 'database connected on08-12 07:26:56' } ]

this event sends request when we refresh or back arrow ‘previous URL’ or redirect using hyperlink except when the tab or browser is closed.

I tried ‘e.preventDefault();’ statement but it stopped sending request when we refresh or back arrow ‘previous URL’ on this page.
is there any solution?

How can this event send request while the tab or browser is closed?