If you are using Livewire then you don’t need to include any external library or write a script to detect if a user is online or offline.
Livewire already provided a utility to perform offline action check. You only need to add it to the HTML element that gets affected according to the user state.
In this tutorial, I show how you can detect if the user is online or offline and display an alert using Livewire in Laravel 9.