Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Detect idle or active browser tabs with the Page Visibility API
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Page Visibility API</title>
<video id="video" width="300" controls>
<p>Your browser doesn't support HTML video playback!</p>
const toggleVideoPlayback = () => {
const video = document.getElementById("video");
return document.hidden ? video.pause() :;
document.addEventListener("visibilitychange", toggleVideoPlayback);

This comment has been minimized.

Copy link
Owner Author

@w3collective w3collective commented Oct 19, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment