react-use icon indicating copy to clipboard operation
react-use copied to clipboard

usePermission throws exception in iOS Safari

Open kamranayub opened this issue 5 years ago • 4 comments

What is the current behavior?

When testing on BrowserStack with a physical iPhone 11 in Safari, navigator.permissions.query is throwing an exception within usePermission.

image

Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:

Run the code in Safari on desktop. Or, sign up for BrowserStack (free) and open an app that uses usePermission in Safari.

What is the expected behavior?

usePermission should probably no-op if the Permissions API is not supported. Alternatively, for each kind of permission, it could try and support what Safari is able to support (notifications, mostly).

See Google polyfill for an example: https://github.com/chromium/permissions.request

Workaround

I haven't found one yet since Rule of Hooks states you can't conditionally execute a hook. Polyfilling the APIs that I need (notifications) may be the only alternative that is compatible.

A little about versions:

  • OS: iOS
  • Browser (vendor and version): Safari v13
  • React: 16.13
  • react-use: 15.1.1
  • Did this worked in the previous package version? No

kamranayub avatar Aug 01 '20 19:08 kamranayub

Contrary to what the linked PR says, I don't think this is fixed on master. Still seeing this error on iOS Safari, as well as on MacOS Safari, when using the latest version of react-use.

will-ks avatar Oct 25 '21 09:10 will-ks

Hmm interesting, I assumed it was, maybe the PR needs to be re opened and updated.

kamranayub avatar Oct 25 '21 11:10 kamranayub

I'm seeing this on safari on mobile and desktop

DustinDSchultz avatar Nov 15 '21 14:11 DustinDSchultz

This is still throwing an exception in 17.4.0 on safari on all plaftorms...

dorsharonfuse avatar Jul 23 '22 11:07 dorsharonfuse