├── .eslintrc.js
├── .gcloudignore
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── app.yaml
├── package.json
├── permissions-policy-header.mjs
├── public
├── demos
│ ├── animations.html
│ ├── autoplay.html
│ ├── geolocation.html
│ ├── oversized-images.html
│ ├── picture-in-picture.html
│ ├── sync-script.html
│ ├── sync-xhr.html
│ ├── unoptimized-lossy-images.html
│ ├── unsized-media.css
│ ├── unsized-media.html
│ └── vertical-scroll.html
├── img
│ ├── emilio-large.jpg
│ ├── emilio.bmp
│ ├── emilio.jpg
│ ├── flag-24px.svg
│ ├── github.svg
│ ├── lossless-emilio.webp
│ ├── lossy-emilio.webp
│ ├── menu24px.svg
│ └── sink.svg
├── index.html
├── js
│ ├── app.js
│ ├── policies.json
│ ├── resources
│ │ ├── async-script.js
│ │ ├── defer-script.js
│ │ ├── module.mjs
│ │ └── parser-blocking-script.js
│ └── shared.js
├── styles
│ ├── header.css
│ └── main.css
├── test.json
├── testpage.html
└── video
│ └── mixkit-rain-falling-from-the-roof-on-a-rainy-day-2716.mp4
├── server.mjs
└── yarn.lock
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | // start with google standard style
3 | // https://github.com/google/eslint-config-google/blob/master/index.js
4 | "extends": ["eslint:recommended", "google"],
5 | "env": {
6 | "node": true,
7 | "es6": true,
8 | "browser": true
9 | },
10 | "parserOptions": {
11 | "ecmaVersion": 8,
12 | "ecmaFeatures": {
13 | "jsx": false,
14 | },
15 | "sourceType": "module"
16 | },
17 | "rules": {
18 | // 2 == error, 1 == warning, 0 == off
19 | "indent": [2, 2, {
20 | "SwitchCase": 1,
21 | "VariableDeclarator": 2,
22 | "MemberExpression": 2,
23 | "outerIIFEBody": 0
24 | }],
25 | "max-len": [2, 100, {
26 | "ignoreComments": true,
27 | "ignoreUrls": true,
28 | "tabWidth": 2
29 | }],
30 | "no-var": 2,
31 | "no-console": 1,
32 | "prefer-const": 2,
33 |
34 | // Disable rules
35 | "arrow-parens": 0,
36 | // "require-jsdoc": 0
37 | }
38 | }
--------------------------------------------------------------------------------
/.gcloudignore:
--------------------------------------------------------------------------------
1 | # This file specifies files that are *not* uploaded to Google Cloud Platform
2 | # using gcloud. It follows the same syntax as .gitignore, with the addition of
3 | # "#!include" directives (which insert the entries of the given .gitignore-style
4 | # file at that point).
5 | #
6 | # For more information, run:
7 | # $ gcloud topic gcloudignore
8 | #
9 | .gcloudignore
10 | # If you would like to upload your .git directory, .gitignore file or files
11 | # from your .gitignore file, remove the corresponding line
12 | # below:
13 | .git
14 | .gitignore
15 |
16 | # Node.js dependencies:
17 | node_modules/
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community
28 | Guidelines](https://opensource.google.com/conduct/).
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Permissions Policy and Document Policy Demos
2 |
3 | Kitchen sink of [Permissions Policy](https://www.chromestatus.com/feature/5745992911552512) and [Document Policy](https://www.chromestatus.com/feature/5756689661820928) demos.
4 |
5 | ### Development
6 |
7 | First install the dependencies:
8 |
9 | `npm i`
10 |
11 | Then run the web server:
12 |
13 | `npm run start`
14 |
15 | ### Deployment
16 |
17 | `npm run deploy`
18 |
--------------------------------------------------------------------------------
/app.yaml:
--------------------------------------------------------------------------------
1 | runtime: nodejs10
2 | #instance_class: F4
3 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "feature-policy-demos",
3 | "version": "1.0.0",
4 | "author": "Eric Bidelman ",
5 | "main": "server.mjs",
6 | "license": "Apache-2.0",
7 | "engines": {
8 | "node": ">=8"
9 | },
10 | "dependencies": {
11 | "express": "^4.16.4",
12 | "lit-html": "^0.14.0"
13 | },
14 | "scripts": {
15 | "start": "node --experimental-modules server.mjs",
16 | "deploy": "gcloud app deploy app.yaml --project feature-policy-demos",
17 | "lint": "./node_modules/eslint/bin/eslint.js --ext .js,.mjs ."
18 | },
19 | "devDependencies": {
20 | "eslint": "^5.10.0",
21 | "eslint-config-google": "^0.11.0"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/permissions-policy-header.mjs:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /**
3 | * Copyright 2020 Google Inc. All rights reserved.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | export class FeaturePolicyHeader {
19 | /**
20 | * @param {Map} policies
21 | */
22 | constructor(policies) {
23 | this.policies = policies;
24 | }
25 |
26 | /**
27 | * Parse Feature-Policy header string
28 | *
29 | * @param {string} header_string e.g. unsized-images 'none'; geolocation *; usb foo.com bar.com
30 | * @returns {FeaturePolicyHeader}
31 | */
32 | static parse(header_string) {
33 | if (!header_string)
34 | return new FeaturePolicyHeader(new Map());
35 |
36 | return new FeaturePolicyHeader(header_string.split(';')
37 | .reduce((acc, item) => {
38 | const [policyName, ...allowlist] = item.trim().split(' ').filter(s => s !== '');
39 | acc.set(policyName, allowlist);
40 | return acc;
41 | }, new Map()));
42 | }
43 |
44 | serialize() {
45 | return [...this.policies.entries()]
46 | .map(([policyName, allowlist]) => `${policyName} ${allowlist.join(' ')}`)
47 | .join('; ');
48 | }
49 | };
50 |
51 | export class PermissionsPolicyHeader {
52 | /**
53 | * @param {Map} policies
54 | */
55 | constructor(policies) {
56 | this.policies = policies;
57 | }
58 | /**
59 | * Parse Permissions-Policy header string.
60 | *
61 | * Note: Permissions-Policy header uses Dictionary in [structured header syntax]
62 | *(https://httpwg.org/http-extensions/draft-ietf-httpbis-header-structure.html).
63 | *
64 | * Note: This function does not provide full structured header syntax parsing.
65 | * When incomplete syntax is received, it can lead to unexpected behaviour.
66 | *
67 | * @param {string} header_string e.g. p1=(), p2=("foo.com" "bar.com"), p3=self
68 | * @returns {PermissionsPolicyHeader}
69 | */
70 | static parse(header_string) {
71 | if (!header_string)
72 | return new PermissionsPolicyHeader(new Map());
73 |
74 | return new PermissionsPolicyHeader(header_string.split(',')
75 | .reduce((acc, item) => {
76 | const [policyName, allowlist_string] = item.split('=').map(s => s.trim());
77 |
78 | const match_result = allowlist_string.match(/\((.*)\)/);
79 | // Bracket is optional when there is only single item in SH's dictionary
80 | // value.
81 | const allowlist = match_result ? (
82 | match_result.length > 1 ? match_result[1].split(' ') : ['']
83 | ) : [allowlist_string];
84 | acc.set(policyName, allowlist);
85 | return acc;
86 | }, new Map()));
87 | }
88 |
89 | serialize() {
90 | return [...this.policies.entries()]
91 | .map(([policyName, allowlist]) => `${policyName}=(${allowlist.join(' ')})`)
92 | .join(', ');
93 | }
94 |
95 | /**
96 | * @returns {FeaturePolicyHeader}
97 | */
98 | toFeaturePolicy() {
99 | /**
100 | * Convert permissions policy allowlist item to feature policy allowlist
101 | * item.
102 | * @param {string} item
103 | * @returns {string}
104 | */
105 | function mapAllowlistItem(item) {
106 | switch (item) {
107 | case '*':
108 | return '*';
109 | case "self":
110 | return "'self'";
111 | case "":
112 | return "'none'";
113 | default:
114 | // Remove leading and trailing '"' in permissions header syntax.
115 | return item.slice(1, -1);
116 | }
117 | }
118 | return new FeaturePolicyHeader(
119 | new Map(
120 | [...this.policies.entries()]
121 | .map(([feature, allowlist]) => [feature, allowlist.map(mapAllowlistItem)])
122 | ));
123 | }
124 | };
125 |
--------------------------------------------------------------------------------
/public/demos/animations.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Document Policy: animations example
8 |
9 |
10 |
11 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | ...
85 |
86 |
87 |
This page shows how animations are affected by this policy.
88 |
89 |
90 |
CSS keyframe animation on transform property
91 |
This first animation continues when the policy is active because it is GPU accelerated. It's
92 | animating one of the three properties (opacity, transform, filter) that can be
93 | reliably hardware accelerated.
94 |
95 |
96 |
97 |
CSS keyframe animation on left property
98 |
This second animation jumps when the policy is
99 | active because it's animating the left property. Don't do that.
100 |
101 |
102 |
103 |
CSS keyframe animation on left and transform properties
104 |
This one shows what happens if you animate more than one property and
105 | one of the properties is non accelerated. Some of the animation still continues.
106 |
107 |
108 |
109 |
requestionAnimationFrame-based animation on left property
110 |
JS-based animations using requestionAnimationFrame are not affected
111 | by the policy, even if they do terrible things like animate CSS left.
112 |
113 |
114 |
115 |
CSS Transition on height property
116 |
Hover over this box. The CSS transition on the height/width won't animate when the policy is active.
Click the buttons above to see how the page loads with different policy values.
19 | Images where the ratio of intrinsic dimensions to container size exceeds the given
20 | threshold should render as placeholder images.
21 |
22 |
31 |
32 |
33 |
34 | When the downscaling ratio does not exceed the limit (2.0) in either direction, the image renders normally.
35 |
36 |
37 |
38 |
39 | Intrinsic size: 800px x 500px
40 | Container size: 800px x 500px
41 |
42 |
43 |
44 |
45 |
46 | When the downscaling ratio exceeds the limit (2.0) for width, the image renders as a placeholder image.
47 |
48 |
49 | For devices with device pixel ratio of 1 (e.g. tablets, monitors, etc), the downscaling ratio (800/380) > 2, the image renders as a placeholder image.
50 |
51 |
52 | Intrinsic size: 800px x 500px
53 | Container size: 380px x 500px
54 |
55 |
56 |
57 |
58 | For devices with device pixel ratio of 2 (e.g. iPad, MacBook, smartphones, etc), the downscaling ratio (800/(180 * 2)) > 2, the image renders as a placeholder image.
59 |
60 |
61 | Intrinsic size: 800px x 500px
62 | Container size: 180px x 500px
63 |
64 |
65 |
66 |
67 | For devices with device pixel ratio between 3 to 5 (e.g. iPhoneX, LG G3+, Samsung Galaxy S4, etc),
68 | the downscaling ratio (800 / (60 * 5)) > 2, the image renders as a placeholder image.
69 |
70 |
71 | Intrinsic size: 800px x 500px
72 | Container size: 60px x 500px
73 |
74 |
75 |
76 |
77 |
78 | When the downscaling ratio exceeds the limit (2.0) for height, the image as a placeholder image.
79 |
80 |
81 | For devices with device pixel ratio of 1 (e.g. tablets, monitors, etc), the downscaling ratio (500/200) > 2, the image renders as a placeholder image.
82 |
83 |
84 | Intrinsic size: 800px x 500px
85 | Container size: 800px x 200px
86 |
87 |
88 |
89 |
90 | For devices with device pixel ratio of 2 (e.g. iPad, MacBook, smartphones, etc), the downscaling ratio (800/(200 * 2)) > 2, the image renders as a placeholder image.
91 |
92 |
93 | Intrinsic size: 800px x 500px
94 | Container size: 800px x 100px
95 |
96 |
97 |
98 |
99 | For devices with device pixel ratio between 3 to 5 (e.g. iPhoneX, LG G3+, Samsung Galaxy S4, etc),
100 | the downscaling ratio (500 / (40 * 5)) > 2, the image renders as a placeholder image.
101 |
102 |
103 | Intrinsic size: 800px x 500px
104 | Container size: 800px x 40px
105 |
106 |
107 |
108 |
109 |
110 | When the downscaling ratio exceeds the limit (2.0) in both direction, the image renders as a placeholder image.
111 |
112 |
113 | For devices with device pixel ratio of 1 (e.g. tablets, monitors, etc), the downscaling ratio > 2, the image renders as a placeholder image.
114 |
115 |
116 | Intrinsic size: 800px x 500px
117 | Container size: 380px x 200px
118 |
119 |
120 |
121 |
122 | For devices with device pixel ratio of 2 (e.g. iPad, MacBook, smartphones, etc), the downscaling ratio > 2, the image renders as a placeholder image.
123 |
124 |
125 | Intrinsic size: 800px x 500px
126 | Container size: 180px x 100px
127 |
128 |
129 |
130 |
131 | For devices with device pixel ratio between 3 to 5 (e.g. iPhoneX, LG G3+, Samsung Galaxy S4, etc),
132 | the downscaling ratio > 2, image renders as a placeholder image.
133 |
134 |
135 | Intrinsic size: 800px x 500px
136 | Container size: 60px x 40px
137 |
The video below uses native controls. Reload the page with the permissions policy
23 | on/off to see the effect on its controls.
24 |
25 |
Note: At the moment, you may need to enable the
26 | --enable-picture-in-picture, --enable-surfaces-for-videos,
27 | and --enable-experimental-web-platform-features flags in Chrome 69+
28 | chrome://flags for this demo to work.
Reload the page. When the page allows synchronous XHRs, you will eventually see a list of web
35 | features supported in Chrome. Note that the banner doesn't render until the JSON request has
36 | finished. This is because the main thread is blocked by the request + parsing of JSON data. When the
37 | page turns on this policy, the browser simply blocks the sync XHR request.
Click the buttons above to see how the page loads with different policy values.
19 | Images where the compression ratio (bytes per pixel) exceeds the threshold should render as placeholder images.
20 |
21 |
22 |
31 |
32 |
For lossy images, (image size - 1KB) / image resolution should be under 0.5
Click the disallow/allow buttons above to see how the page loads with the policy on and off.
21 | When the policy is on, you won't see layout thrashing as large images load. Media without
22 | explicit sizes (either as HTML attributes ore defined in CSS) causes layout and text reflows
23 | as the page loads.
24 |
25 |
39 |
40 |
41 |
Lorem ipsum dolor sit amet, pretium urna faucibus etiam enim sollicitudin,
42 | sagittis phasellus nec suspendisse aenean. Orci nec nam ipsum lobortis ipsum,
43 | at nunc, semper in suscipit sem et, mauris amet amet accumsan risus quis, urna
44 | quam. Lacus mi elit lectus tortor nec enim, sed ornare est praesent est id ut,
45 | mi at. Vestibulum varius, diam posuere tristique est adipiscing, proin quam orci,
46 | nunc tincidunt purus accumsan erat, nec amet magna donec. Consectetuer vivamus
47 | pharetra nulla vivamus, quam sit conubia ligula turpis, condimentum purus mauris
48 | felis scelerisque id. Tincidunt nullam tristique mattis sit vivamus viverra,
49 | velit orci convallis, suspendisse urna sed.
50 |
51 |
52 |
53 |
54 |
55 |
Lorem ipsum dolor sit amet, pretium urna faucibus etiam enim sollicitudin,
56 | sagittis phasellus nec suspendisse aenean. Orci nec nam ipsum lobortis ipsum,
57 | at nunc, semper in suscipit sem et, mauris amet amet accumsan risus quis, urna
58 | quam. Lacus mi elit lectus tortor nec enim, sed ornare est praesent est id ut,
59 | mi at. Vestibulum varius, diam posuere tristique est adipiscing, proin quam orci,
60 | nunc tincidunt purus accumsan erat, nec amet magna donec. Consectetuer vivamus
61 | pharetra nulla vivamus, quam sit conubia ligula turpis, condimentum purus mauris
62 | felis scelerisque id. Tincidunt nullam tristique mattis sit vivamus viverra,
63 | velit orci convallis, suspendisse urna sed.
64 |
65 |
Lorem ipsum dolor sit amet, pretium urna faucibus etiam enim sollicitudin,
66 | sagittis phasellus nec suspendisse aenean. Orci nec nam ipsum lobortis ipsum,
67 | at nunc, semper in suscipit sem et, mauris amet amet accumsan risus quis, urna
68 | quam. Lacus mi elit lectus tortor nec enim, sed ornare est praesent est id ut,
69 | mi at. Vestibulum varius, diam posuere tristique est adipiscing, proin quam orci,
70 | nunc tincidunt purus accumsan erat, nec amet magna donec. Consectetuer vivamus
71 | pharetra nulla vivamus, quam sit conubia ligula turpis, condimentum purus mauris
72 | felis scelerisque id. Tincidunt nullam tristique mattis sit vivamus viverra,
73 | velit orci convallis, suspendisse urna sed.
74 |
75 |
76 |
77 |
78 |
79 |
80 |
Lorem ipsum dolor sit amet, pretium urna faucibus etiam enim sollicitudin,
81 | sagittis phasellus nec suspendisse aenean. Orci nec nam ipsum lobortis ipsum,
82 | at nunc, semper in suscipit sem et, mauris amet amet accumsan risus quis, urna
83 | quam. Lacus mi elit lectus tortor nec enim, sed ornare est praesent est id ut,
84 | mi at. Vestibulum varius, diam posuere tristique est adipiscing, proin quam orci,
85 | nunc tincidunt purus accumsan erat, nec amet magna donec. Consectetuer vivamus
86 | pharetra nulla vivamus, quam sit conubia ligula turpis, condimentum purus mauris
87 | felis scelerisque id. Tincidunt nullam tristique mattis sit vivamus viverra,
88 | velit orci convallis, suspendisse urna sed.
89 |
90 |
94 |
95 |
96 |
Lorem ipsum dolor sit amet, pretium urna faucibus etiam enim sollicitudin,
97 | sagittis phasellus nec suspendisse aenean. Orci nec nam ipsum lobortis ipsum,
98 | at nunc, semper in suscipit sem et, mauris amet amet accumsan risus quis, urna
99 | quam. Lacus mi elit lectus tortor nec enim, sed ornare est praesent est id ut,
100 | mi at. Vestibulum varius, diam posuere tristique est adipiscing, proin quam orci,
101 | nunc tincidunt purus accumsan erat, nec amet magna donec. Consectetuer vivamus
102 | pharetra nulla vivamus, quam sit conubia ligula turpis, condimentum purus mauris
103 | felis scelerisque id. Tincidunt nullam tristique mattis sit vivamus viverra,
104 | velit orci convallis, suspendisse urna sed.
When this policy is active, a frame or main page content will not
34 | be able prevent its content from scrolling vertically. This is done by:
35 |
36 |
37 |
Ensuring all scroll related input events (e.g. touchstart) are non-cancelable.
38 |
Treat touch-action: none as if it were touch-action: pan-y). Meaning the page still blocks pan-x and zoom.
39 |
Ensuring programmatic scrolling using the DOM scroll APIs is handled within the scope of the frame, i.e., calls to el.scrollIntoView() do not propagate outside of the frame.
40 |
Ensuring that no scrollable layer is targeted for scroll gestures (to avoid a frame from consuming
41 | all the scroll gestures).
42 |
43 |
44 |
The frame below uses body{ touch-action: none; } to
45 | prevent its content from scrolling. However, when the policy is "on", it
46 | will be scrollable!. In other words, the policy prevents
47 | the page from blocking vertical scroll by treating the touch-action: none
48 | as touch-action: pan-y.
49 |
50 |
Try scrolling the iframe below on mobile (e.g. using touch events).
Permissions Policy
64 | allows web developers to selectively enable, disable, and modify the behavior
65 | of various features and APIs in the browser. This can provide a well-lit path towards good performance
66 | and prevent common footguns when building and maintaining web apps.
67 |
Permissions policy is not supported in your browser. Try Chrome Canary and enable the --enable-experimental-web-platform-features flag.
68 |
You control permissions policies through an HTTP header: