gpt4 book ai didi

javascript - 如何在 JS 中设置功能策略 header

转载 作者:行者123 更新时间:2023-12-04 11:50:29 30 4
gpt4 key购买 nike

我在我的站点上的控制台中收到以下错误:

Error with Feature-Policy header: Unrecognized feature: 'unsized-media'.
Error with Feature-Policy header: Unrecognized feature: 'ambient-light-sensor'.
Error with Feature-Policy header: Unrecognized feature: 'speaker'.
Error with Feature-Policy header: Unrecognized feature: 'vr'.
我是前端 Web 开发人员,所以我尝试在 JS 中设置它,如此处所述 https://developers.google.com/web/updates/2018/06/feature-policy#js不会弄乱我的服务器配置。
console.log(document.featurePolicy.allowedFeatures());
结果是:
["geolocation", "midi", "ch-ect", "usb", "magnetometer", "picture-in-picture", "publickey-credentials-get", "accelerometer", "ch-lang", "document-domain", "encrypted-media", "ch-downlink", "ch-ua-arch", "xr-spatial-tracking", "ch-ua-platform-version", "ch-width", "ch-ua-model", "sync-xhr", "camera", "ch-viewport-width", "payment", "ch-rtt", "ch-ua-full-version", "fullscreen", "autoplay", "ch-dpr", "ch-ua-platform", "screen-wake-lock", "gyroscope", "ch-ua-mobile", "ch-device-memory", "ch-ua", "microphone"]
document.featurePolicy.allowsFeature('unsized-media', 'self');
结果是:
Invalid origin url for feature 'unsized-media': self.

最佳答案

你不能。
功能策略由服务器设置(通过 Feature-PolicyPermissions-Policy header )并控制 JavaScript 允许执行的操作。
如果 JavaScript 可以授予自己做任何它喜欢的事情的权限,那将毫无意义。

关于javascript - 如何在 JS 中设置功能策略 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63050916/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com