How are you all?
Apply the following trick to detect that your friend is invisible or offline.
1.) Start a new chat with the intended user.
2.) Set the chat to off the record so that it doesn’t get logged to the gmail account.
3.) Send a message to the user. If the user is online and invisible, the message will be delivered.
4.) If the user is offline, you will get an error message indicating that the user is offline.