I am trying to use push notification in a pwa, but it is failing to receive the notification.
On the client side I am receiving the following error
Uncaught SyntaxError: Unexpected token P in JSON at position 0
at Driver.onPush (ngsw-worker.js:1967)
at ngsw-worker.js:1871
I add an image that includes the data that reaches the service worker
As you can see in the previous image, the data field is empty, however when I send it I am adding a text
To test the application I am releasing the notification with the following:
https://web-push-codelab.glitch.me/
I already appreciate any contribution.
The "Unexpected token u in JSON at position 0" error occurs when we pass an undefined value to the JSON. parse or $. parseJSON methods. To solve the error, inspect the value you're trying to parse and make sure it's a valid JSON string before parsing it.
Re: Unexpected token in JSON at position 0 This usually means that an error has been returned and that's not valid JSON. Check the browser developer tools console and network tabs. Turn on Debugging and (after reproducing the error) check the web server error logs.
If your payload is in any json format, like the one above, the error does not appear, but the notification is not shown in your client and no other error message is shown. You have to use a certain json format. One minimal working payload is:
{ "notification": {"title": "message title", "body": "message body"} }
I haven't found the exact and complete spec for this json, but here (search for "payload") you'll find a more complete example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With