Refused to frame ‘XXX‘ because an ancestor violates the following Content Security Policy directive:

问题:Chrome无痕模式下,无法访问iframe嵌套的页面,页面类似白屏

定位原因:CSP安全策略问题,但是服务端无法支持修改

解决:option中添加一句请求头

chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36")

所有option:

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36")
chrome_options.add_argument('--window-size=1920,1080')

来源:tomcat_little

物联沃分享整理
物联沃-IOTWORD物联网 » Refused to frame ‘XXX‘ because an ancestor violates the following Content Security Policy directive:

发表评论