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). 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. (or with a setTimeout of over 1000ms - though as seen in the example, it fails immediately if share is preceded by an AJAX/fetch call)
<rdar://problem/50708309>
This is likely the user-gesture check. Is that supposed to propagate through fetch()?
That is my assumption. Though I would hope there would be a way to propagate through the fetch (as is necessary in my situation)
There is not a way to propagate a user gesture through fetch.
Is this a V1 implementation meant to be improved on? I assume it's not against spec seeing it working in Chromium
Is it expected to remain that way?
Same problem on iOS 12.4. Need a ajax call before navigator.share. It's a disproportionate effort to query data beforehand. It's working without problems on Chrome.
Ya :( Hoping there's a way to to get Safari in line with other browsers to allow an async call before navaigator.'sharing'
Spec says that the relevant global object should have *transient* activation: [1] https://w3c.github.io/web-share/#dom-navigator-share [2] https://html.spec.whatwg.org/multipage/interaction.html#transient-activation So basically, for a certain amount of time after a user gesture, the API should work. If our implementation requires a user gesture, then it is not aligned with the spec.
(In reply to Chris Dumez from comment #9) > Spec says that the relevant global object should have *transient* activation: > [1] https://w3c.github.io/web-share/#dom-navigator-share > [2] > https://html.spec.whatwg.org/multipage/interaction.html#transient-activation > > So basically, for a certain amount of time after a user gesture, the API > should work. If our implementation requires a user gesture, then it is not > aligned with the spec. From Navigator::share(): if (!UserGestureIndicator::processingUserGesture()) { promise->reject(NotAllowedError); return; } This is not quite right indeed.
I can fix this.
(In reply to Chris Dumez from comment #11) > I can fix this. This apparently needs some internal discussion as the current behavior was intentional.
Thank you Chris!
Created attachment 386977 [details] WIP Patch
Created attachment 386983 [details] Patch
Comment on attachment 386983 [details] Patch Clearing flags on attachment: 386983 Committed r254178: <https://trac.webkit.org/changeset/254178>
All reviewed patches have been landed. Closing bug.