useScreenDetailsApi
About
Hook for multi-screen information and management using the Screen Details API. This hook provides access to information about all screens connected to the user's device and allows for reactive updates when screens are added, removed, or changed.
Note: This hook requires the Screen Details API which is experimental and only available in Chromium-based browsers with appropriate permissions.
Examples
Basic Usage
Multi-Screen Window Management
Screen Layout Visualization
Options
Option | Type | Default | Description |
---|---|---|---|
requestOnMount | boolean | false | Whether to automatically request permission on mount |
autoRefresh | boolean | true | Whether to automatically refresh screen details on events |
Return Value
Property | Type | Description |
---|---|---|
screens | ScreenDetailed[] | Array of all available screens |
currentScreen | ScreenDetailed|null | Current screen where the browser window is displayed |
primaryScreen | ScreenDetailed|null | Primary screen (the main display) |
externalScreens | ScreenDetailed[] | External screens (non-primary screens) |
isSupported | boolean | Whether the Screen Details API is supported |
isLoading | boolean | Whether the hook is currently loading screen details |
hasPermission | boolean | Whether permission has been granted |
error | string|null | Error message if any operation failed |
requestPermission | () => Promise<void> | Request permission to access screen details |
refresh | () => Promise<void> | Manually refresh screen details |
ScreenDetailed Object
Property | Type | Description |
---|---|---|
availLeft | number | X-coordinate of available screen area |
availTop | number | Y-coordinate of available screen area |
availWidth | number | Width of available screen area |
availHeight | number | Height of available screen area |
left | number | X-coordinate of total screen area |
top | number | Y-coordinate of total screen area |
width | number | Width of total screen area |
height | number | Height of total screen area |
colorDepth | number | Color depth of the screen |
pixelDepth | number | Pixel depth of the screen |
devicePixelRatio | number | Device pixel ratio |
isPrimary | boolean | Whether this is the primary screen |
isInternal | boolean | Whether this is an internal screen |
label | string | Human-readable label for the screen |
Browser Support
The Screen Details API is experimental and currently only supported in:
- Chrome/Chromium-based browsers (version 100+)
- Requires HTTPS context
- Requires user permission (window-management permission)
Notes
- The hook will automatically detect if the API is supported and provide appropriate fallbacks
- Permission must be requested and granted before accessing screen details
- The hook automatically sets up event listeners for screen changes when permission is granted
- Screen details are automatically refreshed when screens are added, removed, or changed (unless
autoRefresh
is disabled) - All screen coordinates are in CSS pixels relative to the multi-screen coordinate system