Has anyone else ran into this issue? I'm implementing the Web Share API to add a share button to a number of listings on a page. The code seems to be working fine initially, as I can click any of the "Share" buttons and the dialog will appear correctly.
However, if I close the dialog and try to click it again, I get an error saying "The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission."
Stranger still, I'm experiencing this same behavior on all these tutorial sites on how to implement the Web Share API (example: https://alligator.io/js/web-share-api/ - Try clicking the "Share Me!" button halfway down the page more than once on iOS Safari.)
Here's my code for reference:
const shareButtons = document.querySelectorAll('.share');
for (const button of shareButtons) {
button.addEventListener("click", async () => {
if (navigator.share) {
try {
await navigator.share({
url: button.getAttribute('data-url')
});
} catch (err) {
alert(err.message);
}
} else {
// fallback
}
});
}
Appreciate any insight I can get on this - Thanks much
Which version of IOS are you using?
It looks like there is a known bug in IOS 14.0.1 where the initial promise does not resolve.
https://developer.apple.com/forums/thread/662629
suggested fix from the article (which worked for me) is:
or in your case with try/catch
The downside is it actually means the user will have to click twice to trigger the second share if they are using IOS14 - but it won't happen to other users