带有内容安全策略的Cordova 5.0.0 Google Maps [英] Using Cordova 5.0.0 Google Maps with Content Security Policy

查看:245
本文介绍了带有内容安全策略的Cordova 5.0.0 Google Maps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Cordova 5.0.0构建Android的Cordova应用程序。我使用Google Maps without Plugin,它必须没有插件。
我包括这个脚本和meta标签,还有使用白名单插件的Cordova。



<! - Meta tag - > < meta http-equiv =Content-Security-Policycontent =default-src *; style-src'self''unsafe-inline'; script-src'self''unsafe-inline''unsafe-eval' > <! - Google地图 - > < script type =text / javascriptsrc =https://maps.googleapis.com/maps/api/js?sensor=true>< / script>

它给了我这个错误:

class =snippetdata-lang =jsdata-hide =false>

 拒绝加载脚本'https://maps.googleapis.com/maps/api/js?sensor=true',因为它违反了以下内容安全策略指令:script-src'self''unsafe- inline''unsafe-eval'。 


解决方案

尝试使用此块以避免发生错误

 < meta http-equiv =Content-Security-政策content =
default-src'self'data:gap:
*;
script-src'self''unsafe-inline''unsafe-eval'
* ;
style-src'self''unsafe-inline''unsafe-eval'
*;
media-src'self''unsaf e-inline''unsafe-eval'
*;
img-src'self''unsafe-inline''unsafe-eval'
*;
connect-srv'self''unsafe-inline''unsafe-eval'
*
>


I m building Cordova Application for Android using Cordova 5.0.0. and I m using Google Maps without Plugin and it must be without plugin. I include this script and meta tag .also Cordova using whitelist plugin.

  <!-- Meta tag -->
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
  
   <!-- Google Maps-->
 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>

it's give me this error:

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

解决方案

try this block to get that error away

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

这篇关于带有内容安全策略的Cordova 5.0.0 Google Maps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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