When users click the share button on our paywalled site, we generate a token via an async call that allows the people clicking on the share link to bypass the paywall.
I've added support for Web Share API first calling the token before triggering navigator.share
- along these lines:
fetchCallForLink()
.then((url) => {
navigator.share({
title: 'Test Title',
url,
});
This is working fine on Chrome / Android which supports Web Share.
However on Safari, I am getting a not allowed error.
The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission
(This only happens on the first share attempt as I save the response to the window and therefore on subsequent clicks it avoids the AJAX call and works just fine.)
Because of the number of readers we have and the small number that actually use the share option, it would be expensive to make the AJAX call for ever page load (vs. only when user expresses intent to share).
Being that this works fine in Chrome I am assuming nothing in the spec prohibits an AJAX call before launching Web Share.
Might this be a bug in Safari's implementation? Or the reverse and actually Chrome shouldn't be allowing?
Example: https://mkonikov.com/web-share-testing/
I've added a toggle to share with or without fetching first. This share fails only when fetch is enabled. (Also worth noting, sharing will fail with a setTimeout
of over 1000ms)
Update: I have created a bug with the web-kit team here: https://bugs.webkit.org/show_bug.cgi?id=197779.
Update 2: Here's a relevant Twitter thread with some folks from W3C https://twitter.com/marcosc/status/1167607222009884672