-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removed navigator.canShare. #8
Conversation
I'm not super convinced we don't want this (since there may be situations in which the UA sometimes has targets, sometimes does not). But best to start small and add later if necessary. |
Seems good to me, but I can't merge it :( |
|
||
**TODO(mgiuca)**: This may have to be asynchronous, so that the implementation | ||
can query the file system without blocking. | ||
The `navigator.share` method should be `undefined` if the user agent does not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposal here is not very idiomatic and would cause it to behave unlike any other DOM API. Share targets can be added asynchronously at any point in time (via the OS or via a share target being registered). As such, this should probably not appear and disappear from one turn of the event loop to another (or change from a function to undefined. The problem is that navigator.hasOwnProperty("share")
would return true
even if set to undefined
... which would be confusing).
We could work on the assumption that there is always at least 1 share target: the UA share box itself... For instance, Safari has "Add to Reading List" and "Add To Bookmarks" as persistent share targets. Other UAs might inform the user about adding share targets or might simply allow the user to cancel.
@benfredwells, I've added you to the list of collaborators and made @mgiuca repo admin. Matt, please feel free to add additional collaborators. |
Yes, we did decide on that assumption on Tuesday. (The rationale for removing I did not mean to imply that I don't mind either way. I just thought we could remove |
Ah, ok. But the current phrasing is confusing then, as it makes it sounds like the browser might take the API away at arbitrary moments. |
Fair enough. Reworded. |
**TODO(mgiuca)**: This may have to be asynchronous, so that the implementation | ||
can query the file system without blocking. | ||
In a user agent that will never provide any share targets (e.g., on a platform | ||
that does not support sharing) `navigator.share` SHOULD be `undefined`, so that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, but the problem here remains. The current reading is that the user agent would implement ".share", but it would return "undefined". This would mean that the following would return true:
var x = "share" in navigator; // true, even though it's "undefined"
Worst case, .share should be nullable - but if there is no share target at all in the platform, the user agent would not implement the API at all.
There are examples of this in the platform: for instance, Android's marketplace APK size restrictions prevent Firefox from shipping ES's Intl
on Android (because it would add like 30+ megabytes to Firefox) - hence, Firefox does not ship that API on Android - and thus Intl
is not implemented at all, even though it's shipped on Desktop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, didn't realise that there's a difference between being undefined
and not being defined. (bleh) Is it sufficient to say "navigator.share
SHOULD NOT be present"? I'm not sure what you mean by "Worst case, .share should be nullable".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
Update: We've had some discussion on the Chrome side and it looks like it isn't great to have I think there's a case to be made that, in dglazkov's words: "the API surface does not change from OS to OS, but the way it responds does." This means we probably do want |
This similar thing is being discussed on the notifications spec as well whatwg/notifications#81 and whatwg/notifications#80 - for things that are not available on the platform should the notification object expose it and how should we do it. |
I think the if (navigator.canShare !== undefined && navigator.canShare()) {
navigator.share(...);
} or even, for the paranoid: if (navigator.canShare !== undefined && navigator.canShare()) {
if (navigator.share !== undefined) {
navigator.share(...);
}
} instead of if (navigator.share !== undefined) {
navigator.share(...);
} |
The key issue, I think, is that you end up having different varieties of a Web platform across implementations, and that seems bad for predictability. I sympathize with @benfredwells syntactic elegance argument. If there was a way to specify that |
@RByers, to put this on Predictability folks' radar. |
The way I see it, if you consider a method being undefined or not as a "variety", then you're always going to have two different varieties of every API until all browsers implement on all platforms, and all users update to the newer versions of those browsers: And developers always have to deal with those two "varieties". If we add a In effect, forcing developers to deal with more possibilities. (I believe this is @benfredwells point.)
Do you mean a call to |
Thanks for explaining. I see that |
d5dcf3f
to
50e6231
Compare
Sorry for the delay (still getting caught up after TPAC).
Yes, in cases like this I agree it's better for developers if they have to reason only about "does this API exist or not". Just to make sure I understand, we're talking only about variations between platforms (Android vs. Windows) here, right? Not something more dynamic? The challenge we've had in other contexts (eg. TouchEvents API, origin trials) is that it's difficult for us to make expressions like If there's no such need for dynamism here, then I agree we should definitely just leverage normal feature detection patterns around the existence of properties. |
@RByers Yes, this is (at the moment) just a static "is this supported on my platform". We would reconsider adding canShare if we needed anything dynamic (such as "are there any apps installed that handle this request"). |
So we are launching this on the origin trial without |
sounds good. |
Resolves #5.