pageVisibleSignal
G
Reports whether the page is visible as a readonly signal. The initial value comes from document.visibilityState, and the signal updates when the document receives a visibilitychange event.
true: the document's visibility state is visible.false: the document's visibility state is hidden.undefined: the status is unknown, such as during server rendering when document is unavailable, or when document.visibilityState is not supported.
Pausing audio when the page is hidden
Play the melody, then switch tabs. Music pauses while hidden and resumes when you return.