This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Feature Policy allows web developers to selectively enable, disable, and modify the behavior of certain features and APIs in the browser. It is similar to Content Security Policy but controls features instead of security behavior.
Feature Policy provides a mechanism to explicitly declare what functionality is used (or not used), throughout your website. This allows you to lock in best practices, even as the codebase evolves over time — as well as to more safely compose third-party content — by limiting which features are available.
With Feature Policy, you opt-in to a set of "policies" for the browser to enforce on specific features used throughout a website. These policies restrict what APIs the site can access or modify the browser's default behavior for certain features.
Examples of what you can do with Feature Policy:
document.write()
.Feature Policy allows you to control which origins can use which features, both in the top-level page and in embedded frames. Essentially, you write a policy, which is an allowed list of origins for each feature. For every feature controlled by Feature Policy, the feature is only enabled in the current document or frame if its origin matches the allowed list of origins.
For each policy-controlled feature, the browser maintains a list of origins for which the feature is enabled, known as an allowlist. If you do not specify a policy for a feature, then a default allowlist will be used. The default allowlist is specific to each feature.
A policy is described using a set of individual policy directives. A policy directive is a combination of a defined feature name, and an allowlist of origins that can use the feature.
Feature Policy provides two ways to specify policies to control features:
Feature-Policy
HTTP header.allow
attribute on iframes.The primary difference between the HTTP header and the allow
attribute is that the allow attribute only controls features within an iframe. The header controls features in the response and any embedded content within the page.
For more details see Using Feature Policy.
Though Feature Policy provides control of multiple features using a consistent syntax, the behavior of policy controlled features varies and depends on several factors.
The general principle is that there should be an intuitive or non-breaking way for web developers to detect or handle the case when the feature is disabled. Newly introduced features may have an explicit API to signal the state. Existing features that later integrate with Feature Policy will typically use existing mechanisms. Some approaches include:
false
or error from an existing JavaScript API that provides access to feature.The current set of policy-controlled features fall into two broad categories:
There are several policy-controlled features to help enforce best practices for providing good performance and user experiences.
In most cases, the policy-controlled features represent functionality that when used will negatively impact the user experience. To avoid breaking existing web content, the default for such policy-controlled features is to allow the functionality to be used by all origins. Best practices are then enforced by using policies that disable the policy-controlled features. For more details see "Enforcing best practices for good user experiences".
The features include:
The web provides functionality and APIs that may have privacy or security risks if abused. In some cases, you may wish to strictly limit how such functionality is used on a website. There are policy-controlled features to allow functionality to be enabled/disabled for specific origins or frames within a website. Where available, the feature integrates with the Permissions API, or feature-specific mechanisms to check if the feature is available.
The features include:
Specification | Status | Comment |
---|---|---|
Feature Policy The definition of 'Feature-Policy' in that specification. | Draft | Initial definition. Defines the Feature-Policy header. Directives are defined in the specs for the features they control. See individual directive pages for details. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 60 | No | No | No | 47 | No |
accelerometer
|
69
|
No | No | No | 56
|
No |
ambient-light-sensor
|
69
|
No | No | No | 56
|
No |
autoplay
|
64 | No | No | No | 51 | No |
camera
|
59 | No | No | No | 48 | No |
encrypted-media
|
59 | No | No | No | 48 | No |
fullscreen
|
57 | No | No | No | 46 | No |
geolocation
|
56 | No | No | No | 45 | No |
gyroscope
|
69
|
No | No | No | 56
|
No |
layout-animations
|
No | No | No | No | No | No |
legacy-image-formats
|
68
|
No | No | No | 55
|
No |
magnetometer
|
69
|
No | No | No | 56
|
No |
maximum-downscaling-image
|
68
|
No | No | No | 55
|
No |
microphone
|
59 | No | No | No | 48 | No |
midi
|
56 | No | No | No | 45 | No |
payment
|
56 | No | No | No | 45 | No |
picture-in-picture
|
No | No | No | No | No | No |
speaker
|
59 | No | No | No | 48 | No |
sync-xhr
|
65
|
No | No | No | 52
|
No |
unsized-media
|
66
|
No | No | No | 53
|
No |
usb
|
60 | No | No | No | 47 | No |
vibrate
|
56 | No | No | No | 43 | No |
vr
|
62 | No | No | No | 49 | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 60 | 60 | No | No | 47 | No | No |
accelerometer
|
69
|
69
|
No | No | 56
|
No | No |
ambient-light-sensor
|
69
|
69
|
No | No | 56
|
No | No |
autoplay
|
64 | 64 | No | No | 51 | No | No |
camera
|
59 | 59 | No | No | 48 | No | No |
encrypted-media
|
59 | 59 | No | No | 48 | No | No |
fullscreen
|
57 | 57 | No | No | 46 | No | No |
geolocation
|
56 | 56 | No | No | 45 | No | No |
gyroscope
|
69
|
69
|
No | No | 56
|
No | No |
layout-animations
|
No | No | No | No | No | No | No |
legacy-image-formats
|
68
|
68
|
No | No | 55
|
No | No |
magnetometer
|
69
|
69
|
No | No | 56
|
No | No |
maximum-downscaling-image
|
68
|
68
|
No | No | 55
|
No | No |
microphone
|
59 | 59 | No | No | 48 | No | No |
midi
|
56 | 56 | No | No | 45 | No | No |
payment
|
56 | 56 | No | No | 45 | No | No |
picture-in-picture
|
No | No | No | No | No | No | No |
speaker
|
59 | 59 | No | No | 48 | No | No |
sync-xhr
|
65
|
65
|
No | No | 52
|
No | No |
unsized-media
|
66
|
66
|
No | No | 53
|
No | No |
usb
|
60 | 60 | No | No | 47 | No | No |
vibrate
|
56 | 56 | No | No | 43 | No | No |
vr
|
62 | 62 | No | No | 49 | No | No |
Feature-Policy
HTTP headerallow
attribute on iframes
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Feature_Policy