Requesting Permissions

Requesting Permissions

Draft Community Group Report,

This version:
https://jyasskin.github.io/permissions-request
Issue Tracking:
GitHub
Inline In Spec
Editor:
(Google Inc.)
Former Editor:
(Google Inc.)
Tests:
web-platform-tests permissions-request/ (ongoing work)
Polyfills:
chromium/permissions.request

Abstract

This specification extends the Permissions API to provide a uniform function for requesting permission to use powerful features.

Status of this document

This specification was published by the Web Platform Incubator Community Group. It is not a W3C Standard nor is it on the W3C Standards Track. Please note that under the W3C Community Contributor License Agreement (CLA) there is a limited opt-out and other conditions apply. Learn more about W3C Community and Business Groups.

1. Introduction

This document specifies a function to request permission to use powerful features on the Web platform.

Different Web APIs have disparate ways to signal a developer’s intent to use them:

It’s easier for developers to design their permission-related code if they have a single pattern to follow for all powerful features.

2. Request API

partial interface Permissions {
  Promise<PermissionStatus> request(object permissionDesc);
};

When the request(permissionDesc) method is invoked, the user agent MUST run the following algorithm, passing the parameter permissionDesc:

  1. Let rootDesc be the object permissionDesc refers to, converted to an IDL value of type PermissionDescriptor. If this throws an exception, return a promise rejected with that exception and abort these steps.

  2. Let typedDescriptor be the object permissionDesc refers to, converted to an IDL value of rootDesc.name’s permission descriptor type. If this throws an exception, return a promise rejected with that exception and abort these steps.

  3. Let promise be a newly-created Promise.

  4. Return promise and continue the following steps asynchronously.

  5. Run the steps to create a PermissionStatus for typedDescriptor, and let status be the result.

  6. Run the permission request algorithm of the feature named typedDescriptor.name with typedDescriptor and status as arguments.

  7. If the previous step threw an exception, reject promise with that exception.

  8. Otherwise resolve promise with status.

3. Additional fields in the Permission Registry

Powerful features in the Permission Registry additionally define a permission request algorithm:

Input
Behavior

Uses the algorithms in Requesting more permission to show the user any necessary prompt to try to increase permissions, and updates the instance of the permission result type to match.

Returns

Nothing, but may throw an exception if the request can fail exceptionally. (Merely being denied permission is not exceptional.)

Example callers
Default

If unspecified, this defaults to the default permission request algorithm.

3.1. Default request algorithm

The default permission request algorithm, given a PermissionDescriptor permissionDesc and a PermissionStatus status, runs the following steps:

  1. Run the default permission query algorithm on permissionDesc and status.

  2. If status.state is not "prompt", abort these steps.

  3. Request permission to use permissionDesc.

  4. Run the default permission query algorithm again on permissionDesc and status.

    On browsers that don’t store permissions persistently within an environment settings object, this will always return "prompt", but still show the user an unnecessary prompt. That may mean that no permissions should use the default permission request algorithm, since it can never return an appropriate object-capability.

4. Security Considerations

No security considerations have been identified.

5. Privacy Considerations

No privacy considerations have been identified.

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Conformant Algorithms

Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should", "may", etc) used in introducing the algorithm.

Conformance requirements phrased as algorithms or specific steps can be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not intended to be performant. Implementers are encouraged to optimize.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[HTML]
Anne van Kesteren; et al. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[PERMISSIONS]
Marcos Caceres; Mike Taylor. Permissions. 11 March 2022. WD. URL: https://www.w3.org/TR/permissions/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119
[WEBIDL]
Edgar Chen; Timothy Gu. Web IDL Standard. Living Standard. URL: https://webidl.spec.whatwg.org/

Informative References

[geolocation-API]
Andrei Popescu. Geolocation API Specification 2nd Edition. 8 November 2016. REC. URL: https://www.w3.org/TR/geolocation-API/
[NOTIFICATIONS]
Anne van Kesteren. Notifications API Standard. Living Standard. URL: https://notifications.spec.whatwg.org/

IDL Index

partial interface Permissions {
  Promise<PermissionStatus> request(object permissionDesc);
};

Issues Index

On browsers that don’t store permissions persistently within an environment settings object, this will always return "prompt", but still show the user an unnecessary prompt. That may mean that no permissions should use the default permission request algorithm, since it can never return an appropriate object-capability.