Bridges the Web Permissions API to one check / request /
subscribe interface, with fallbacks for legacy getUserMedia, iOS Safari
sensor permissions, and browsers that never fire permission change events. Nothing
here throws — failure is a state.
supported reports whether the Query API (navigator.permissions) exists.
Where it does not, the kit still answers through per-API fallbacks.
readonly version: string;
get supported(): boolean;
Never prompts, and asks the browser for the current state every time it is called — use it to decide what UI to show on load. Sensors have no read-only query on iOS, so a sensor check listens for events briefly before falling back.
check(type: PermissionType): Promise<PermissionState>;
May prompt. Device sensors only prompt from inside a user gesture, which the button below is
— called anywhere else they resolve "prompt" without asking.
request(type: PermissionType): Promise<PermissionState>;
Fires once with the current state, then on every change. Where the native
change event is unreliable the kit re-checks when the page regains focus, so
flipping the permission in browser settings and coming back shows up in the log.
subscribe(type: PermissionType, callback: PermissionSubscriber): PermissionUnsubscribe;
type PermissionSubscriber = (state: PermissionState) => void;
type PermissionUnsubscribe = () => void;
Both enums are reachable from the singleton, so the named imports are optional. The rows are built by walking the live objects.
readonly Type: typeof PermissionType;
readonly State: typeof PermissionState;
enum PermissionType {
Notification = 'notifications',
Geolocation = 'geolocation',
Camera = 'camera',
ClipboardRead = 'clipboard-read',
ClipboardWrite = 'clipboard-write',
Microphone = 'microphone',
MIDI = 'midi',
DeviceOrientation = 'device-orientation',
DeviceMotion = 'device-motion',
PersistentStorage = 'persistent-storage'
}
enum PermissionState {
Grant = 'grant',
Denied = 'denied',
Prompt = 'prompt',
Unsupported = 'unsupported'
}