uni-app - Refused to display ‘xxx‘ in a frame because an ancestor violates the following Content Sec

报错原因

整体流程的话,就是将网页通过 web-view 组件内嵌到 App 中(非小程序),其中有跳转微信公众号的需求,不料却收到了以下报错。

我又不是打包小程序,就套壳个 App ,比较疑惑为什么会报错。

以下报错在 uni-app 内置浏览器中,预览 H5 端时出现:

Refused to display 'https://xxx' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'

在这里插入图片描述

归根结底是 iframe 同源策略问题。

解决方案

注意:仅适用于打包 非小程序端,如果打包小程序端则必须后台配置白名单(这是一定的)。

这是由于 uni-app 内置浏览器的原因,所以才会导致的此问题。

你正常打包成 App 后,是不会有该问题的。

所以,你直接打包就行了,完事后这个报错自己就没有了。

猜你喜欢

转载自blog.csdn.net/weixin_44198965/article/details/125866178