The Document.visibilityState read-only property returns the visibility of the document.
Document.visibilityState
MDN Reference