WebAPI/Navigator.hasFeature: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1: Line 1:
= Navigator.hasFeature API =
= Navigator.getFeature API =


== Use Cases ==
== Use Cases ==
Line 12: Line 12:
   [NoInterfaceObject]
   [NoInterfaceObject]
   interface NavigatorFeatures {
   interface NavigatorFeatures {
    Promise hasFeature(DOMString name);
     Promise getFeature(DOMString name);
     Promise getFeature(DOMString name);
   };
   };
Line 19: Line 18:


== Semantics ==
== Semantics ==
Both hasFeature and getFeature accept string arguments to denote the feature names.  getFeature resolves the promise with an undefined value if the feature name passed to them is unknown.  hasFeature will fullfill the promise with a true value if the feature exists on the "platform" (which means the current state and version of the hardware and the UA software) albeit hidden behind some runtime permissions, and it will fulfill the promise with a false value if the feature doesn't exist on the "platform" or if the feature name passed to it is unknown.  getFeature will resolve the promise with a value describing the feature name passed to the API.  The type of that value depends on the feature being queried.  The idea is that hasFeature should be used for mere existence tests, and getFeature should be used for queries involving asking more information about a feature, such as the size of something.
getFeature accepts a string argument to denote the feature name.  getFeature resolves the promise with an undefined value if the feature name passed to them is unknown.  For the "api" namespace as described below, getFeature will fullfill the promise with a true value if the feature exists on the "platform" (which means the current state and version of the hardware and the UA software) albeit hidden behind some runtime permissions, and it will fulfill the promise with a false value if the feature doesn't exist on the "platform".  The type of that value depends on the feature being queried.


The feature name specifies a namespaced value in the following form:
The feature name specifies a namespaced value in the following form:
Line 64: Line 63:
The second example checks to see if the privileged FM Radio API is available.
The second example checks to see if the privileged FM Radio API is available.


   navigator.hasFeature("api.window.Navigator.mozFMRadio").then(function(enabled) {
   navigator.getFeature("api.window.Navigator.mozFMRadio").then(function(enabled) {
     if (enabled) {
     if (enabled) {
       alert("FM Radio support detected, my privileged app will work!");
       alert("FM Radio support detected, my privileged app will work!");
     }
     }
   });
   });
Confirmed users
657

edits

Navigation menu