On Facebook, it is possible to log out of Messenger so that your contacts do not know that you are online.
Steps

Step 1. Go to this site
Your news feed will appear.
- If the login screen appears, enter your username and password in the boxes provided for this purpose at the top right of the screen, then click on Log in.

Step 2. Click the gear icon in the Messages tab
It is located in the lower right corner of the screen. A popup menu will appear.

Step 3. Select Disable Instant Chat

Step 4. Choose Disable instant chat for all contacts
With this option, none of your contacts will be able to know that you are online.
- To allow specific contacts to see you, choose Disable instant chat except for … and enter the names of these people.
- Select Disable instant chat for certain contacts only … if you want only certain contacts to not be able to see that you are online. With this option, you can enter specific friend names.

Step 5. Click OK
The change will be effective immediately.