Permissions API - Web APIs 编辑

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.

Note: This feature is available in Web Workers (although not current versions of Firefox, as WorkerNavigator.permissions is not implemented).

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 Navigator object, both in the standard browsing context and the worker context (WorkerNavigator — so permission checks are available inside workers), and returns a 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 Permissions.query() method to return a promise that resolves with the 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

Navigator.permissions and WorkerNavigator.permissions Read only
Provides access to the Permissions object from the main context and worker context respectively.
Permissions
Provides the core Permission API functionality, such as methods for querying and revoking permissions.
PermissionStatus
Provides access to the current status of a permission, and an event handler to respond to changes in permission status.

Specifications

SpecificationStatusComment
PermissionsWorking DraftInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:118 次

字数:5403

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文