web-push-libs / web-push-php

Web Push library for PHP
MIT License
1.68k stars 295 forks source link

Successfull message but nothing happens #366

Closed sophiehf35 closed 4 months ago

sophiehf35 commented 1 year ago

Hello, I am using the web-push-php-example library, already generated the keys via linux, but for some reason when I press the button to Send notification, I don't receive notification at desktop (chrome) and phone (fireforx)... At console, I receive the return from send_push_notification file, which says:

"[v] Message sent successfully for subscription https://fcm.googleapis.com/fcm/send/e_Y1_jLWHoc:APA91bHb60sfgiIjtKJ2X9WiuXoQJqO4QZVVoSa47KQZ7ElgrAcOMLOz4qZGKKF2TO6z0Dt0e9nECT1GbPsX82Hdp74ottrsXjC6jONYFlzpRyTj1Se0kCuIX3FJlV6mP-NdV8oWNHKy."

I am testing at this URL: https://www.advogadosaqui.com.br/web-push-php-example/src/index/

I have tested at my android phone using chrome and there worked, but using my desktop (chrome too) It doesnt show nothing... Tried at firefox at my phone and didn't worked neither.

Someone could help me? ;(

bootexe commented 1 year ago

after you've send your push your serviceWorker in your javascript should receive a push event where your eventlistener should trigger a notification here is the apple example of their serviceWorker :

// BrowserPetsWorker.js

self.addEventListener('push', (event) => {
    let pushMessageJSON = event.data.json();

    // Our server puts everything needed to show the notification
    // in our JSON data.
    event.waitUntil(self.registration.showNotification(pushMessageJSON.title, {
        body: pushMessageJSON.body,
        tag: pushMessageJSON.tag,
        actions: [{
            action: pushMessageJSON.actionURL,
            title: pushMessageJSON.actionTitle,
        }]
    }));
}

you can check out their full tutorial here