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

Abort error when share is cancelled #2

Closed
sgtpenguin opened this issue Dec 19, 2023 · 2 comments
Closed

Abort error when share is cancelled #2

sgtpenguin opened this issue Dec 19, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@sgtpenguin
Copy link

Describe the bug
When closing a share dialog without selecting an option an exception is thrown in Safari.

Uncaught runtime errors:
×
ERROR
Abort due to cancellation of share.

Screenshots
Screen Shot 2023-12-19 at 11 08 24 AM

Desktop (please complete the following information):

  • OS: Mac
  • Browser: Safari
  • Version: recent/latest

Additional context
Possibly wrapping navigator.share in a try/catch could avoid the issue. Untested.

See this SO thread:
https://stackoverflow.com/questions/60510383/web-share-api-navigator-share-problem-when-canceling-share-dialog-ios-and-androi

@sgtpenguin sgtpenguin added the bug Something isn't working label Dec 19, 2023
@daviddarnes
Copy link
Owner

daviddarnes commented Dec 19, 2023

Thanks for reporting! I am aware of this issue, but not sure how to handle it. Could wrap it in a try/catch but since I think it's a promise in of itself we could use a .then() and a .catch() to catch the error and surface console information for debugging:

 window.navigator.share({
      title: root.title,
      text: root.title + "\n" + window.location.href
    })
    .then(() => alert('The page was shared'))
    .catch((e) => console.log(e))

What do you think?

@sgtpenguin
Copy link
Author

This looks good to me. I just tested on my end and it works as expected in Safari, logs the error, but still working and toggling properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants