Skip to content

usePermission throws when the Permissions API is unavailable (navigator.permissions is undefined) #1711

Description

@vitalyq

Prior Issues

None found. #1563 is about Safari not firing the change event, which is a different problem.

What is the current behavior?

usePermission calls navigator.permissions.query() inside its effect without checking that the Permissions API exists:
https://github.com/react-hookz/web/blob/master/src/usePermission/index.ts

navigator.permissions
	.query(descriptor)
	.then((status): void => { ... });

In environments where navigator.permissions is undefined, the effect throws:

TypeError: Cannot read properties of undefined (reading 'query')

We see this in production logs from Android WebView.

Steps to Reproduce

Render a component using the hook in any environment without the Permissions API.

What is the expected behavior?

The hook should never throw. When the API is missing it should report that instead (for example a dedicated 'unsupported' state), so apps can degrade gracefully.

Environment Details

  • @react-hookz/web version: 26.1.0
  • react version: 19.2.5
  • react-dom version: 19.2.5
  • typescript version: 5.x
  • OS: Android (also reproducible on iOS < 16)
  • Browser: Android WebView, iOS Safari 15
  • Did this work in previous versions? No, the call has been unguarded since the hook was added

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions