Modern web applications can access native device capabilities—including GPS coordinates, the system clipboard, hardware vibration motors, and battery status. These Device APIs enable web apps to provide native-app-like user experiences while respecting user privacy and security sandboxes.
The navigator.geolocation interface provides access to the device's physical geographic location (GPS, Wi-Fi tri-angulation, cell towers):
navigator.clipboard)Replacing the legacy, insecure document.execCommand('copy'), the modern Async Clipboard API enables safe reading and writing to the system clipboard with Promise-based asynchronous calls:
navigator.vibrate)Provides physical haptic feedback on supported mobile devices:
Before invoking intrusive device features, use the Permissions API to inspect whether permission has already been granted, denied, or needs a prompt:
All modern Device APIs require a Secure Context (HTTPS or localhost) and explicit User Gesture Activation (e.g., must be triggered inside a click event listener). Invoking navigator.clipboard.writeText() automatically on page load without user interaction throws a NotAllowedError.
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| History API & Client-Side Routing | Fullscreen & Screen Orientation APIs |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.