“未找到内容安全策略元标记."我的 phonegap 应用程序中的错误 [英] "No Content-Security-Policy meta tag found." error in my phonegap application

查看:33
本文介绍了“未找到内容安全策略元标记."我的 phonegap 应用程序中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的系统中更新 Cordova 5.0 后,我创建了新的应用程序.当我在设备上测试我的应用程序时,我在控制台日志中收到一个错误:

After update Cordova 5.0 in my system, I create new applications. When I tested my application on a device that time I get an error in the console log:

No Content-Security-Policy meta tag found.
Please add one when using the Cordova-plugin-whitelist plugin.: 23.

我在头部部分添加元数据

I add meta in the head section

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src: 'self' 'unsafe-inline' 'unsafe-eval'>

但是,我又遇到了同样的错误,在应用程序中我使用了应用内浏览器插件和 7 个其他网站链接.

But again, I got the same error, in the application I use in-app browser plugin and 7 of other website links.

推荐答案

添加cordova-plugin-whitelist,如果您想保持特定,您必须告诉您的应用程序允许访问所有网页链接或特定链接.

After adding the cordova-plugin-whitelist, you must tell your application to allow access all the web-page links or specific links, if you want to keep it specific.

您可以简单地将它添加到您的 config.xml,它可以在您的应用程序的根目录中找到:

You can simply add this to your config.xml, which can be found in your application's root directory:

推荐:

<allow-navigation href="http://example.com/*" />

或:

<allow-navigation href="http://*/*" />

来自插件的文档:

导航白名单

控制 WebView 本身可以导航到哪些 URL.适用于仅限顶级导航.

Controls which URLs the WebView itself can be navigated to. Applies to top-level navigations only.

怪癖:在 Android 上,它也适用于非 http(s) 方案的 iframe.

Quirks: on Android it also applies to iframes for non-http(s) schemes.

默认情况下,只允许导航到 file://URL.允许其他网址,您必须在您的网址中添加标签配置文件:

By default, navigations only to file:// URLs, are allowed. To allow other other URLs, you must add tags to your config.xml:

<!-- Allow links to example.com -->
<allow-navigation href="http://example.com/*" />

<!-- Wildcards are allowed for the protocol, as a prefix
     to the host, or as a suffix to the path -->
<allow-navigation href="*://*.example.com/*" />

<!-- A wildcard can be used to whitelist the entire network,
     over HTTP and HTTPS.
     *NOT RECOMMENDED* -->
<allow-navigation href="*" />

<!-- The above is equivalent to these three declarations -->
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="data:*" />

这篇关于“未找到内容安全策略元标记."我的 phonegap 应用程序中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆