Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usePermission on Safari fails to update #1563

Open
johnpaulett opened this issue Nov 13, 2024 · 0 comments
Open

usePermission on Safari fails to update #1563

johnpaulett opened this issue Nov 13, 2024 · 0 comments
Assignees
Labels
🪲 bug Something isn't working

Comments

@johnpaulett
Copy link

What is the current behavior?

usePermission works on Chrome, but not Safari. Seems like root issue is in Safari not firing change event: https://forums.developer.apple.com/forums/thread/757353

I'm documenting this here in case someone else runs into it and partly to see if anyone has an idea for a workaround.

Steps to Reproduce

  const permission = usePermission({ name: "microphone" });

  const prompt = useCallback(async () => {
    try {
      await navigator.mediaDevices.getUserMedia({ audio: true });
    } catch (promptError) {
      console.warn("Microphone prompt error", promptError);

      if (promptError instanceof DOMException) {
        setError(promptError);
      }
    }
  }, []);

  // Prompt on first mount if permissions have not yet been granted or denied.
  useEffect(() => {
    if (permission === "prompt") {
      prompt();
    }
  }, [permission]);

permission is prompt and never updated on Safari, even though re-querying shows it was granted

navigator.permissions
    .query({ name: "microphone" })
    .then((result) => console.log(result.status));
// logs "granted"

Have tried to adjust the on call to use onchange = handleChange, but that did nothing.

What is the expected behavior?

Seems like it is Safari not firing onchange, ideally Safari would fix. But is there a workaround for react-hookz? Perhaps if Safari, provide a setInterval check?

Environment Details

  • @react-hookz/web version: 23.1.0
  • react version: 18.2.0
  • react-dom version: 18.2.0
  • typescript version: 5.4.5
  • OS: MacOS
  • Browser: Safari Version 17.4.1 (19618.1.15.11.14)
  • Did this work in previous versions? unknown. It works currently in Chrome
@xobotyi xobotyi self-assigned this Dec 23, 2024
@xobotyi xobotyi added the 🪲 bug Something isn't working label Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working
Development

No branches or pull requests

2 participants