On Sun, Mar 4, 2012 at 3:17 PM, Timothy Chien <
timd...@gmail.com> wrote:
> Hi,
>
> I was talking with Kanru the other day on how web app authors do feature
> detection: we simply check if the existence of the interface. For example,
> if (!!window.Worker) or ('Worker' in window) evaluates to true, we assume
> the browser supports web workers and it's safe to run code with it.
>
> But then I realize the practice failed on many of our newly created
> mobility APIs.
>
> If you download Nightly/Mac today, fire up Web Console and type
> window.navigator.moz
> , you will find mozPower, mozBattery, mozSms(*1), and mozVibrate.
>
> Functions and properties reports useless or incorrect information when
> attempt to access them on a Mac.
>
> I understand many of them aren't support to work on desktops, or they are
> incomplete code that will behavior correctly once finished(*2). But for now
> I think they should be removed from DOM, or web developers will be force to
> check (navigator.userAgent.indexOf('**B2G') !== -1) to know if they are
> real APIs.
>
> *1 (mozSms === null) on Mac, but attempt to detect it with ('mozSms' in
> window.navigator) will give false positive.
>
> *2 We are certainly not going to enable website to power off my Mac. But
> will we allow websites to check your laptop battery life?
>
Somewhat OT but why shouldn't a website be able to request this capability,
and why shouldn't a user be able to grant it?
ISTM the current approach to feature-detection conflates the availability
of a capability with the ability to request a capability. These two things
are very different.
It would be nice if there were a somewhat consistent way to do either, and
in a more granular fashion than asking whether *mozPower *exists. What if
you want an app to be able to check your power level but not turn off your
device (that device potentially being your desktop or laptop even)?
As more and more sites gain more and more caps the fundamental interactions
around granting, browsing and revoking capabilities will have to be rock
solid and perfectly clear to users anyway. And WRT non-mobile devices, if
users and/or it staff don't like being able to grant certain caps to apps
they should be able to globally disable them via about:config.
Related: is there ever really a need to be able to detect whether a feature
is available but denied vs. completely unavailable on a given device? And
if so, would revealing this be considered a privacy concern? (Apologies if
this has been covered: I'm new here and just catching up -- really excited
about the prospects for b2g!)