Feature Police导致iframe页面无法使用粘贴功能


说明

在Chrome 81版本之上时,通过iframe引入的页面无法正常使用粘贴板。此时,控制台会输出

DOMException: The Clipboard API has been blocked because of a permissions policy applied to the current document. See https://goo.gl/EuHzyv for more details.

错误,这是由于web规范之Feature Police导致的。

Feature Police有些类似于CSP,是安全策略的一种。关于FP的设置有两种,Headers设置与iframe的属性(allow)设置,目前常用的的Feature类型可参考:Features,也可以在浏览器执行

document.featurePolicy.allowedFeatures();

获取当前版本浏览器支持的类型。

解法

针对iframe无法使用粘贴板的问题,可采用

<iframe id = 'ide' allow="clipboard-read; clipboard-write " src = "xxx"></iframe>

加上allow属性即可。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM