如何在离子中实现Cordova白名单插件?

时间:2016-02-01 07:07:26

标签: cordova ionic-framework cordova-plugins

我一直在关注如何实现这一目标的大量博客和教程,但没有运气。我有一种感觉,我在这个过程中缺少一步(很可能是一些非常明显的东西,教程的作者认为没有必要提及)。我正在使用ionic framework作为我的应用,并关注this tutorial

首先我从cli运行它:

ionic plugin add https://github.com/apache/cordova-plugin-whitelist.git

然后我在config.xml中添加它:

<allow-navigation href="*" />

但我仍然认为这不起作用。我的index.html中有什么需要做的吗?我的app.js也许吧?我在这里有点失落。

PS - 我可以看到'cordova-plugin-whitelist'文件夹位于我的[app root]/plugins/目录中。但同样,我有一种感觉,我应该在某处引用它。

更新

我将以下内容添加到我的index.html文件中:

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

但是,当我这样做时,我的应用程序中出现以下错误:

Refused to load the script 'http://maps.googleapis.com/maps/api/js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval'".

(index):99 Refused to load the script 'http://localhost:35729/livereload.js?snipver=1' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval'".
(anonymous function) @ (index):99
angular-google-maps.min.js:5 Refused to load the script 'https://maps.googleapis.com/maps/api/js?v=3&libraries=&language=en&sensor=false&callback=onGoogleMapsReady773' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval'".

1 个答案:

答案 0 :(得分:1)

您必须在content-security-policy元标记中启用来自HTTPS网址的脚本加载:

PRAGMA restrict_references (Check_View, WNDS, TRUST);

您可以限制使用特定的Google域名:

script-src 'self' 'unsafe-eval' https:;