Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
Error with 'click_action' to send notification

I am trying to send a push notification with PHP + Firebase. I get the notification fine but the 'click-action' event doesn't work. When I click on the notification, it disappears and does not redirect me to the PWA.

Could you help me?

File sendNotification.php

$severKey="MY_KEY";
$url="https://fcm.googleapis.com/fcm/send";

$message = "Test message";
$tokenId="MY_TOKEN";
$icon="MY_ICON";
$favicon = "FAVICON";


$field=array(
    
    'data'=>array(
        'notification'=>array(
            'title'=>'Notify',
            'body'=>$message,
            'icon'=>$icon,
            'badge' => $favicon,
            'click_action' => 'https://www.google.es' //Here the url of my app
        )
        ),
    'to'=>$tokenId
);
$fields=json_encode($field);

$header=array(
    'Authorization: key='.$severKey,
    'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

$result=curl_exec($ch);
echo $result;
curl_close($ch);

Part of my file firebase-messaging-sw.js

importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-messaging.js');

firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();


messaging.onBackgroundMessage(function(payload) {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);
    const {title, ...options}=JSON.parse(payload.data.notification);
    self.registration.showNotification(title, options);
});
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda