web-push-libs / web-push-php

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

Microsoft Edge not receiving notifications #312

Closed PINHOf closed 3 years ago

PINHOf commented 3 years ago

Setup

Please check that you have installed and enabled these PHP extensions :

Please select any browsers that you are experiencing problems with:

Microsoft Edge

Problem

Although the output from $webPush->sendOneNotification($subscription, $payload); is a success, the notification is never received in Microsoft Edge. It works great though with Firefox & Chrome!

Expected

I expect to receive a browser notification in Microsoft Edge.

Features Used

Example / Reproduce Case

First of all, I ask for browser notifications & register the service worker in JS:

navigator.serviceWorker.register('/sw.js');
navigator.serviceWorker.ready.then(function(registration)
{
    var publicKey = urlB64ToUint8Array(getVAPIDPublicKey());

    registration.pushManager.subscribe(
    {
        userVisibleOnly: true,
        applicationServerKey: publicKey
    }).then(function(subscription)
    {
        var data = JSON.stringify(subscription);

        console.log(data);
    }).catch(function(err)
    {
        console.log('Error: ', err);
    });
});

With the result of the variable data, I use it to send a browser notification in PHP with web-push library.

// $data holds the value returned from console.log(data)
$subscription = \Minishlink\WebPush\Subscription::create(json_decode($data, true));

$auth = 
[
    'VAPID' => 
    [
        'subject' => 'myemail@myemail.com',
        'publicKey' => '....',
        'privateKey' => '....'
    ]
];

$webPush = new \Minishlink\WebPush\WebPush($auth);

$payload =
[
    'title' => 'The title',
    'body' => 'The body',
    'icon' => '...',
    'data' =>
    [
        'url' => '...',
    ]
];

$payload = json_encode($payload);

$report = $webPush->sendOneNotification($subscription, $payload);
$endpoint = $report->getRequest()->getUri()->__toString();

if ($report->isSuccess())
    echo "[v] Message sent successfully for subscription {$endpoint}.";
else
    echo "[x] Message failed to sent for subscription {$endpoint}: {$report->getReason()}";

The output is the expected:

[v] Message sent successfully for subscription https://db5p.notify.windows.com/w/?token=BQYAAACltt2C%2f%2bkdnW...

But unfortunately Edge browser does not receive any notification!

PINHOf commented 3 years ago

Well, it seems it's a version problem. I'm using the version Microsoft Edge 44.18362.449.0 and I just tried with a recent version 87.0.664.66 and it worked great!