UNPKG

webapp-astro-pwa

Version:

A ready-to-use Astro component library for adding Progressive Web App (PWA) support to your Astro projects. This package provides drop-in components and utilities for manifest injection, service worker registration, install prompts, and more. Includes a w

35 lines (30 loc) 990 B
/** * Checks if the current browser is Chrome or Edge. */ function isChromeOrEdge(): boolean { const { userAgent } = navigator; return /Chrome|Edg/.test(userAgent); } /** * Checks if the beforeinstallprompt event is supported. */ function isBeforeInstallPromptSupported(): boolean { return "onbeforeinstallprompt" in window; } /** * Shows a popover by its element ID, if available. * @param id - The element ID of the popover. */ function renderPopover(id: string): void { const popover = document.getElementById(id) as HTMLElement | null; if (popover && "showPopover" in popover && typeof popover.showPopover === "function") { (popover as HTMLElement & { showPopover: () => void }).showPopover(); } } /** * Checks if the app is running in standalone (PWA) mode. */ function isPWAInstalled(): boolean { return window.matchMedia("(display-mode: standalone)").matches; } export { isBeforeInstallPromptSupported, renderPopover, isPWAInstalled, isChromeOrEdge };