Screenfull is a lightweight JavaScript utility that wraps the browser's Fullscreen API into a single, consistent interface. It normalizes the vendor-prefixed fullscreen methods across different browsers, providing a unified way to request, exit, and toggle fullscreen mode on any DOM element or the entire page.
The library handles cross-browser differences automatically, abstracting away the webkit, moz, and ms prefixes behind a clean API. It includes runtime feature detection to check browser support before exposing fullscreen methods, and uses promises for asynchronous fullscreen requests and exits, enabling straightforward error handling and chaining. Screenfull also provides event-driven state tracking, listening to native fullscreenchange and fullscreenerror events to maintain accurate internal state and fire callbacks when fullscreen mode is entered, exited, or fails.
Beyond the core request and exit functions, Screenfull offers a toggle method that automatically determines whether to enter or exit fullscreen based on the current state. It includes utilities for querying the current fullscreen element, checking whether fullscreen is active, and attaching or removing event listeners for change and error events. The library also provides a fullscreen availability check that considers iframe permissions, helping developers avoid runtime errors when fullscreen is not permitted.