UNPKG

webdev-power-kit

Version:

A powerful toolkit that simplifies access to browser features like clipboard, notifications, battery, vibration, and more — perfect for modern web developers.

28 lines (27 loc) 827 B
/** * @fileoverview Get browser network connection details using the Network Information API. * Provides type, speed estimate, save-data preference, etc. */ /** * Returns current network connection information. * Falls back gracefully if API is not supported. * * @returns An object with network type, speed, and flags. */ export function getConnectionInfo() { const nav = navigator; if (!nav.connection) { return { isSupported: false }; } const connection = nav.connection; return { type: connection.type ?? undefined, effectiveType: connection.effectiveType ?? undefined, downlink: connection.downlink ?? undefined, rtt: connection.rtt ?? undefined, saveData: connection.saveData ?? undefined, isSupported: true }; }