-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
event.data is always null #355
Comments
After repeated attempts, I found a solution, using this notification format.
P256dh and auth are obtained from the result of javascript's pushManager.subscribe. |
I love u, this worked for me as well.
|
Documentation of Web Push PHP seems completely wrong as in the docs at https://github.com/web-push-libs/web-push-php it says: `<?php use Minishlink\WebPush\WebPush; // array of notifications $webPush = new WebPush(); // send multiple notifications with payload /**
/**
This will ALWAYS produce empty data though (tested in Chrome MacOS). Only by following the posters above I made it work. It manually takes the p256dh and auth key and inserts it into a nested array under keys. I believe the docs need to be changed because it took me hours to figure this out too! $webPushSubscriptionObject=Subscription::create([ |
Yes the readme is not very clear right now, because of all the old standards and/or browser implementations. Note that even when sending a payload, some browser implementations might not respect/handle it and you should handle the case where payload is undefined on the client-side. The Storing the whole client-side |
README updated, is it more clear? 156a3b6 |
I do that, but that does not work. Here's the saved JS subscription array from a Chrome client (with redacted keys):
Just submitting that as a subscription object into Web Push PHP fails to send data to a Chrome client. Data will always be null. Instead we have to do modify the subscription JS array from client and add publicKey and authToken in there again, like this: $webPushSubscriptionObject=Subscription::create([ Thanks! |
That's weird, this is exactly what's being done in the example and it works flawlessly with a payload. Do you decode with |
Yep I did, and it works because push events show up in client but event data is null in Chrome. See the other people with same problem.
…On Wed, Oct 18, 2023, at 22:41, Louis Lagrange wrote:
That's weird, this is exactly what's being done in the example <https://github.com/Minishlink/web-push-php-example/blob/master/src/send_push_notification.php#L9> and it works flawlessly with a payload. Do you decode with `json_decode($subscription, true)`? (in order to have an associative array)
—
Reply to this email directly, view it on GitHub <#355 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABWR2AD5U3K7Q3CLDN3PGYLYABEHLAVCNFSM5X4W73YKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZWHEZTMNBUGUZA>.
You are receiving this because you commented.Message ID: ***@***.***>
|
PHP Version: 7.4.26
web-push-php Version: 7.0.0
Browser: Microsoft Edge v104.0.1271.2
php code like this :
$notification = [
'subscription' => Subscription::create([
'endpoint' => 'https://sg2p.notify.windows.com/...', // Edge,
'publicKey' => '...', // base 64 encoded, should be 88 chars
'authToken' => '...', // base 64 encoded, should be 24 chars
]),
'payload' => json_encode([
"title"=>"have news"
]),
]
Problem
The browser can receive notification, but the event.data is always null.
The text was updated successfully, but these errors were encountered: