blob: 5c14434f1508d9e8dc2ae821732b12ed2b97a0fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
---
<p>{{DefaultAPISidebar("Permissions API")}}</p>
<div class="summary">
<p><span class="seoSummary">The <strong>Permissions API</strong> 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.</span></p>
</div>
<h2 id="Concepts_and_usage">Concepts and usage</h2>
<p>Historically different APIs handle their own permissions inconsistently — for example the <a href="/en-US/docs/Web/API/Notifications_API">Notifications API</a> allows for explicit checking of permission status and requesting permission, whereas the <a href="/en-US/docs/Web/API/Geolocation">Geolocation API</a> 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.</p>
<p>The <code>permissions</code> 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.</p>
<p>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.</p>
<p>Not all APIs' permission statuses can be queried using the Permissions API. Notable APIs that are Permissions-aware include:</p>
<ul>
<li><a href="/en-US/docs/Web/API/Clipboard_API">Clipboard API</a></li>
<li><a href="/en-US/docs/Web/API/Notifications_API">Notifications API</a></li>
<li><a href="/en-US/docs/Web/API/Push_API">Push API</a></li>
<li>Web MIDI API</li>
</ul>
<p>More APIs will gain Permissions API support over time.</p>
<h2 id="Examples">Examples</h2>
<p>We have made a simple example available called Location Finder. You can <a href="https://chrisdavidmills.github.io/location-finder-permissions-api/">run the example live</a>, or <a href="https://github.com/chrisdavidmills/location-finder-permissions-api/tree/gh-pages">view the source code on Github</a>.</p>
<p>Read more about how it works in our article <a href="/en-US/docs/Web/API/Permissions_API/Using_the_Permissions_API">Using the Permissions API</a>.</p>
<h2 id="Interfaces">Interfaces</h2>
<dl>
<dt>{{domxref("Navigator.permissions")}} and {{domxref("WorkerNavigator.permissions")}} {{readonlyinline}}</dt>
<dd>Provides access to the {{domxref("Permissions")}} object from the main context and worker context respectively.</dd>
<dt>{{domxref("Permissions")}}</dt>
<dd>Provides the core Permission API functionality, such as methods for querying and revoking permissions.</dd>
<dt>{{domxref("PermissionStatus")}}</dt>
<dd>Provides access to the current status of a permission, and an event handler to respond to changes in permission status.</dd>
</dl>
<h2 id="Specification">Specification</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Permissions API')}}</td>
<td>{{Spec2('Permissions API')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
<h3 id="Permissions_interface">Permissions interface</h3>
<div>
<p>{{Compat("api.Permissions")}}</p>
</div>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li><a href="/en-US/docs/Web/API/Permissions_API/Using_the_Permissions_API">Using the Permissions API</a></li>
<li><a href="https://blog.addpipe.com/using-permissions-api-to-detect-getusermedia-responses/">Using the Permissions API to Detect How Often Users Allow or Deny Camera Access</a></li>
<li>{{DOMxRef("Notification.permission")}}</li>
<li><a href="/en-US/docs/Web/Privacy">Privacy, permissions, and information security</a></li>
</ul>
|