Agm-map dando erro em localhost e no servidor

30 respostas
angular2
guilhermebhte

Estou usando o AgmCoreModule, para marcar endereços no google maps.

No module, no import

imports: [
    AgmCoreModule.forRoot({
      apiKey: 'xxxxxxxxxxx'
   }),
]

no export

exports: [
       AgmCoreModule
]

No ts

texto = 'teste';
  lat = -19.91506;
  lng = -44.00752;
  zoom = 15;

No html

<agm-map [latitude]="lat" [zoom]="zoom" [longitude]="lng">
  <agm-marker [latitude]="lat" [longitude]="lng"></agm-marker>
</agm-map>

A principio ele mostra


Mas depois dá este erro

Ou este erro

O Chave key está liberada

O que pode ser ?

30 Respostas

guilhermebhte

Atualizei no servidor, ai não funciona mesmo.

main.49c677484d95e163b289.bundle.js:2 Refused to load the script 'https://maps.googleapis.com/maps/api/js?v=quarterly&callback=agmLazyMapsAPILoader&key=xxxxxxxxxx&language=pt' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

load @ main.49c677484d95e163b289.bundle.js:2
Z @ main.49c677484d95e163b289.bundle.js:2
Z.ɵfac @ main.49c677484d95e163b289.bundle.js:2
si @ main.49c677484d95e163b289.bundle.js:2
ii @ main.49c677484d95e163b289.bundle.js:2
ti @ main.49c677484d95e163b289.bundle.js:2
Bc @ main.49c677484d95e163b289.bundle.js:2
pe.ɵfac @ main.49c677484d95e163b289.bundle.js:2
si @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
co @ main.49c677484d95e163b289.bundle.js:2
qc @ main.49c677484d95e163b289.bundle.js:2
template @ 14.49c677484d95e163b289.chunk.js:1
ao @ main.49c677484d95e163b289.bundle.js:2
ro @ main.49c677484d95e163b289.bundle.js:2
zo @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
ro @ main.49c677484d95e163b289.bundle.js:2
create @ main.49c677484d95e163b289.bundle.js:2
createComponent @ main.49c677484d95e163b289.bundle.js:2
activateWith @ main.49c677484d95e163b289.bundle.js:2
activateRoutes @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
activateChildRoutes @ main.49c677484d95e163b289.bundle.js:2
activateRoutes @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
activateChildRoutes @ main.49c677484d95e163b289.bundle.js:2
activate @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
notifyNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
_trySubscribe @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
o @ main.49c677484d95e163b289.bundle.js:2
_innerSub @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
notifyNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
notifyNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
_trySubscribe @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
o @ main.49c677484d95e163b289.bundle.js:2
_innerSub @ main.49c677484d95e163b289.bundle.js:2
_tryNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
_trySubscribe @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
o @ main.49c677484d95e163b289.bundle.js:2
_innerSub @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
notifyNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
notifyNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
_trySubscribe @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
o @ main.49c677484d95e163b289.bundle.js:2
_innerSub @ main.49c677484d95e163b289.bundle.js:2
_tryNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
_complete @ main.49c677484d95e163b289.bundle.js:2
complete @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
_trySubscribe @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
o @ main.49c677484d95e163b289.bundle.js:2
_innerSub @ main.49c677484d95e163b289.bundle.js:2
_tryNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
notifyNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
_trySubscribe @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
o @ main.49c677484d95e163b289.bundle.js:2
_innerSub @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
notifyNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
notifyNext @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
_next @ main.49c677484d95e163b289.bundle.js:2
next @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
_trySubscribe @ main.49c677484d95e163b289.bundle.js:2
subscribe @ main.49c677484d95e163b289.bundle.js:2
call @ main.49c677484d95e163b289.bundle.js:2
Promise.then (async)
b @ main.49c677484d95e163b289.bundle.js:2
e.scheduleTask @ main.49c677484d95e163b289.bundle.js:2
onScheduleTask @ main.49c677484d95e163b289.bundle.js:2
e.scheduleTask @ main.49c677484d95e163b289.bundle.js:2
t.scheduleTask @ main.49c677484d95e163b289.bundle.js:2
t.scheduleMicroTask @ main.49c677484d95e163b289.bundle.js:2
I @ main.49c677484d95e163b289.bundle.js:2
x @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ main.49c677484d95e163b289.bundle.js:2
t @ main.49c677484d95e163b289.bundle.js:2
(anonymous) @ 14.49c677484d95e163b289.chunk.js:1
Show 170 more frames
main.49c677484d95e163b289.bundle.js:2 ERROR Error: Uncaught (in promise): Event: {"isTrusted":true}
    at x (main.49c677484d95e163b289.bundle.js:2)
    at x (main.49c677484d95e163b289.bundle.js:2)
    at main.49c677484d95e163b289.bundle.js:2
    at e.invokeTask (main.49c677484d95e163b289.bundle.js:2)
    at Object.onInvokeTask (main.49c677484d95e163b289.bundle.js:2)
    at e.invokeTask (main.49c677484d95e163b289.bundle.js:2)
    at t.runTask (main.49c677484d95e163b289.bundle.js:2)
    at y (main.49c677484d95e163b289.bundle.js:2)
    at t.invokeTask [as invoke] (main.49c677484d95e163b289.bundle.js:2)
    at u (main.49c677484d95e163b289.bundle.js:2)
guilhermebhte

Algo ?

guilhermebhte

Algo nesse sentido ?

guilhermebhte

@Lucas_Camara pode me ajudar neste também

Na verdade o que entendo que é mais configuração do sistema acessar estes sites que os navegadores estão barrando.

este https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700 e o do google mapas (https://maps.googleapis.com/maps/api/js)

Lucas_Camara

Pelo que li, de acordo com esse link. Você deve adicionar uma regra CSP para que os scripts funcionem:

<meta http-equiv="Content-Security-Policy" content="script-src 'self' https://maps.googleapis.com https://maps.gstatic.com; object-src 'self'">
guilhermebhte

Já feito isso. Mas deu este erro em anexo.

Lucas_Camara

Tenta assim:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' https://maps.googleapis.com https://maps.gstatic.com 'unsafe-inline' 'unsafe-eval';" />
guilhermebhte

Erro.

No caso o projeto é com jhipster

guilhermebhte

No caso o projeto é com jhipster. Spring com Angular 9

Lucas_Camara

A questão é que vc tem que montar a tag meta para o http-equiv=“Content-Security-Policy” com as configurações para permitir execução de scripts de outra origem no atributo content. Com isso é preciso entender como esse CSP funciona (conforme links que passei). Eu não manjo muito disso, tanto que os exemplos que mandei foi com base numa rápida leitura que fiz na documentação.

guilhermebhte

Entendi isso também. Então estou no caminho certo.

guilhermebhte

Mas estranho que tudo que vejo como solução não funciona.

Lucas_Camara

Até tentei dá uma lida melhor para tentar entender e montar, mas não entendi 100% e estou meio apertado no trampo. Qdo tiver um tempinho mais suave, vou ler a doc com mais calma.

Lucas_Camara

O que mais vc tentou?

guilhermebhte

Quase tudo de pesquisa relacionada a este assunto.
Foi tanta coisa que nem lembro mais.

guilhermebhte

Pesquisada no google

guilhermebhte

@Lucas_Camara, neste link https://stackoverflow.com/questions/33984908/google-fonts-violates-content-security-policy, eles falam em:

Authorize https://fonts.googleapis.com in style-src directive and https://fonts.gstatic.com in font-src directive: `“style-src ‘self’ https://fonts.googleapis.com; font-src ‘self’ https://fonts.gstatic.com

Ai coloquei assim:

<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet" />

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />

<meta http-equiv="Content-Security-Policy" content="style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com;" />

E perdeu tudo. Muito estranho

Tem esta página também: https://developers.google.com/web/fundamentals/security/csp?hl=pt-br

Coloquei todos que ele fala em Política aplicável a diversos recursos, mas nada.

Lucas_Camara

Acho que tu tem que colocar um 'unsafe-line' após a url:

<meta http-equiv="Content-Security-Policy" content="style-src 'self' https://fonts.googleapis.com 'unsafe-inline'; font-src 'self' https://fonts.gstatic.com; 'unsafe-inline'" />
guilhermebhte

Continua dando erro no console.

Quando acesso por: http://localhost:9000/#/

Quando acesso por: http://localhost:8080/#/

No servidor, é como dá o mesmo erro que na imagem 8080

guilhermebhte

<meta http-equiv="Content-Security-Policy" content="script-src 'self' https://fonts.googleapis.com https://fonts.gstatic.com 'unsafe-inline' 'unsafe-eval'">

Este funciona com localhost:9090, mas não com localhost:8080.

Porque está dando está diferença ?

Lucas_Camara

Oxi, pela porta não deveria ter diferença não. Será que pode ser algum tipo de cache?

guilhermebhte

Já abri em todos os navegadores. com janela anonima ou não. Mas quando faço o build no servidor, ele não funciona e dá erro de permissão. Como o exemplo da porta 8080.

Lucas_Camara

Como esses estilos estão sendo importados no projeto? Vou ver se consigo simular esse problema aqui.

guilhermebhte
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />

Mas teria que ser com o jhipster

guilhermebhte

Tudo bem que tem que ter segurança, mas tudo que faço não está adiantando. :rage:

guilhermebhte

Dentro do public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

http.csrf().disable().addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class)
				.exceptionHandling().authenticationEntryPoint(problemSupport).accessDeniedHandler(problemSupport).and()
				.headers()
				.contentSecurityPolicy(
						"default-src 'self'; frame-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:")
				.and().referrerPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN).and()
				.featurePolicy(
						"geolocation 'none'; midi 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'")
				.and().frameOptions().deny().and().sessionManagement()
				.sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests()

Ai tirei esta parte e funcionou:

.contentSecurityPolicy(
						"default-src 'self'; frame-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:")
				.and()

Só que fica chamando esta parte de tempo em tempo.

http://localhost:9060/sockjs-node/info?t=1593652208370

Atrapalho a segurança ou algo parecido ?

Lucas_Camara

Em termos de segurança, esse contentSecurityPolicy é para evitar ataques de Cross Site Scripting. O que vc pode tentar é, em vez de tirar essa linha, alterar com as devidas permissões. Pois estava tentando adicionar isso numa tag meta no html. Acredito que vc teria que adicionar a url https://fonts.googleapis.com nessa configuração do web security, assim:

"default-src 'self'; frame-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data:; font-src 'self' data:"
guilhermebhte

Tentei, mas adivinha. kkkkk não funcionou,

Mas vou tentar com este que vc passou

Lucas_Camara

Pelo que entendi, a sintaxe é algo assim:

"<<tipo-do-recurso>> '<<diretiva>>'; <<tipo-do-recurso>> '<<diretiva>>'; ...''
  • O tipo do recurso diz se é um script, um estilo, uma fonte, etc. E esse default-src é um fallback caso não encaixe em nenhum outro declarado (li isso na documentação);
  • Já a diretiva, diz como será permitido ler o recurso utilizado. Como exemplo, um script carregado via eval. E ainda definir de qual host o recurso está vindo.
guilhermebhte

Então este exemplo funcionaria ?

Criado 23 de junho de 2020
Ultima resposta 4 de jul. de 2020
Respostas 30
Participantes 2