Skip to content

Browser Permissions Helper is a lightweight library that simplifies managing browser permissions in web apps. It handles requests, user decisions, and ensures a seamless experience with minimal effort. πŸš€

License

Notifications You must be signed in to change notification settings

darshitdudhaiya/browser-permissions-helper

Repository files navigation

Browser Permissions Helper

browser-permission-helper-banner.png

A simple utility to manage and request browser permissions seamlessly. This package provides an easy-to-use API for handling permissions like notifications, geolocation, camera, microphone, and more.

πŸš€ Features

  • βœ… Check the current permission status for various browser APIs.
  • πŸ”„ Request permissions dynamically.
  • πŸ“’ Handle permission changes efficiently.
  • 🎯 Lightweight and easy to integrate.

πŸ“¦ Installation

npm install browser-permissions-helper

or

yarn add browser-permissions-helper

πŸ›  Usage

Import the Module

import {
  PermissionType,
  checkPermission,
  requestPermission,
  getPermissionSupportInfo
} from 'browser-permissions-helper';

Check Permission Status

const status = await checkPermission(PermissionType.Geolocation);
console.log(`Geolocation permission: ${status}`);

Request Permission

const result = await requestPermission(PermissionType.Notifications);
console.log(`Notification permission granted: ${result}`);

Get Browser Support Info for permission

const info = getPermissionSupportInfo(PermissionType.Bluetooth);
console.log(info.supportedBrowsers); // ['Chrome', 'Edge']
console.log(info.notes); // 'Not supported in Firefox or Safari'

πŸ“œ Supported Permissions

  • geolocation
  • clipboard-write
  • notifications
  • camera
  • microphone
  • camera-advanced
  • speaker-selection
  • bluetooth
  • midi
  • nfc
  • screen-wake-lock
  • persistent-storage
  • push
  • idle-detection
  • storage-access
  • display-capture
  • window-management

πŸ“– API Reference

checkPermission(permissionType: PermissionType) => Promise<'granted' | 'denied' | 'prompt'>

Checks the current status of a given permission.

requestPermission(permissionType: PermissionType) => Promise<boolean>

Requests the specified permission from the user and returns true if granted, otherwise false.

getPermissionSupportInfo(permissionType: PermissionType) => { supportedBrowsers: string[]; notes?: string; }

Returns a list of browsers that support the given permission, with optional notes for caveats or limited support.

πŸ›‘οΈ Browser Compatibility

This package works in modern browsers that support the Permissions API.

Browser Supported
Chrome βœ… Yes
Firefox βœ… Yes
Edge βœ… Yes
Safari βœ… Partial (Some permissions may not be available)

πŸ’‘ Use getPermissionSupportInfo() to programmatically check support for specific permission.

🀝 Contributing

Contributions are welcome! Feel free to fork the repository, create a feature branch, and submit a PR.

πŸ“œ License

This project is licensed under the MIT License.

πŸ“¬ Contact

For any queries or issues, please open an issue.


⭐ If you find this package useful, consider giving it a star on GitHub! ⭐

About

Browser Permissions Helper is a lightweight library that simplifies managing browser permissions in web apps. It handles requests, user decisions, and ensures a seamless experience with minimal effort. πŸš€

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published