我在我的站点上的控制台中收到以下错误:
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.发布于 2020-07-23 17:29:33
你不能这么做。
功能策略由服务器设置(通过Feature-Policy或Permissions-Policy标头),并控制允许JavaScript执行的操作。
如果JavaScript可以允许自己做任何它喜欢做的事情,那将是毫无意义的。
https://stackoverflow.com/questions/63050916
复制相似问题