Abort error when share is cancelled
sgtpenguin opened this issue · 2 comments
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.
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
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?
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.