Feature Police如何让iframe页面粘贴功能失效?

摘要:说明 在Chrome 81版本之上时,通过iframe引入的页面无法正常使用粘贴板。此时,控制台会输出 DOMException: The Clipboard API has been blocked because of a permis
说明 在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属性即可。