From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/permissions_api/index.html | 94 ++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 files/zh-cn/web/api/permissions_api/index.html (limited to 'files/zh-cn/web/api/permissions_api/index.html') diff --git a/files/zh-cn/web/api/permissions_api/index.html b/files/zh-cn/web/api/permissions_api/index.html new file mode 100644 index 0000000000..5c14434f15 --- /dev/null +++ b/files/zh-cn/web/api/permissions_api/index.html @@ -0,0 +1,94 @@ +--- +title: Permissions API +slug: Web/API/Permissions_API +tags: + - API + - Introduction + - NeedsTranslation + - Overview + - Permissions + - Permissions API + - TopicStub + - Web + - access +translation_of: Web/API/Permissions_API +--- +

{{DefaultAPISidebar("Permissions API")}}

+ +
+

The Permissions API provides a consistent programmatic way to query the status of API permissions attributed to the current context. For example, the Permissions API can be used to determine if permission to access a particular API has been granted or denied.

+
+ +

Concepts and usage

+ +

Historically different APIs handle their own permissions inconsistently — for example the Notifications API allows for explicit checking of permission status and requesting permission, whereas the Geolocation API doesn't (which causes problems if the user denied the initial permission request). The Permissions API provides the tools to allow developers to implement a better user experience as far as permissions are concerned.

+ +

The permissions property has been made available on the {{domxref("Navigator")}} object, both in the standard browsing context and the worker context ({{domxref("WorkerNavigator")}} — so permission checks are available inside workers), and returns a {{domxref("Permissions")}} object that provides access to the Permissions API functionality.

+ +

Once you have this object you can then perform permission-related tasks, for example querying a permission using the {{domxref("Permissions.query()")}} method to return a promise that resolves with the {{domxref("PermissionStatus")}} for a specific API.

+ +

Not all APIs' permission statuses can be queried using the Permissions API. Notable APIs that are Permissions-aware include:

+ + + +

More APIs will gain Permissions API support over time.

+ +

Examples

+ +

We have made a simple example available called Location Finder. You can run the example live, or view the source code on Github.

+ +

Read more about how it works in our article Using the Permissions API.

+ +

Interfaces

+ +
+
{{domxref("Navigator.permissions")}} and {{domxref("WorkerNavigator.permissions")}} {{readonlyinline}}
+
Provides access to the {{domxref("Permissions")}} object from the main context and worker context respectively.
+
{{domxref("Permissions")}}
+
Provides the core Permission API functionality, such as methods for querying and revoking permissions.
+
{{domxref("PermissionStatus")}}
+
Provides access to the current status of a permission, and an event handler to respond to changes in permission status.
+
+ +

Specification

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Permissions API')}}{{Spec2('Permissions API')}}Initial definition.
+ +

Browser compatibility

+ +
+

Permissions interface

+ +
+ + +

{{Compat("api.Permissions")}}

+
+
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf