w3c/web-share

Handle documents not being fully active

marcoscaceres opened this issue · 8 comments

Given a nested content (iframe), it's possible to capture a click event, have the click event remove the iframe, and then call one of the methods.

https://github.com/marcoscaceres/playground/blob/83a28912a59b6f87cec4627536450eaf1a5db8a5/share-parent.html#L6-L18

Accessible from:
https://marcoscaceres.github.io/playground/share-parent.html

In Safari, .share() rejects with a TypeError.
in Firefox, .share() rejects with a NS_ERROR_UNEXPECTED (Gecko code).
In Chrome, share() rejects with NotAllowedError: "Must be handling a user gesture to perform a share request."

Not sure why Chrome thinks that the click handler is not happening inside a user gesture (technically, not incorrect as the iframe has been removed, but still a weird).

I think we should align align with Safari here and just reject with a TypeError. @saschanaz, wdyt?

Is TypeError conventional for this kind of failure? Something like InvalidStateError makes more sense to me 🤔

When it comes to exceptions related to this, it's a bit all over the place to be honest... and having multiple exception types gets unnecessarily messy/complicated, IMO.

Safari actually does the check during share data validation, which is why it results with a TypeError. It might be a good place to do the check in the spec too. This kind of error is a super edge case.

Actually, I forgot that we already use a bunch of different exception types in this spec.

Safari actually does the check during share data validation, which is why it results with a TypeError. It might be a good place to do the check in the spec too. This kind of error is a super edge case.

That means canShare would fail on non-fully-active documents, I'm not sure it's a good idea.

Edit: What does Chrome do for canShare?

Edit: What does Chrome do for canShare?

returns true.

Screen Shot 2021-09-03 at 11 39 38 am

That means canShare would fail on non-fully-active documents, I'm not sure it's a good idea.

What use case where you thinking whereby someone would call .canShare() on a non-fully active document?

On a second thought, I agree that following WebKit and making canShare fail (return false) makes the most sense since share() will anyway fail.

Spoke to some folks over on the webkit side and they also suggested we use InvalidStateError. I've updated the PR to match.