WebPushError and UnauthorizedRegistration when try to send push notification to Chrome and Opera, Firefox is OK

风格不统一 提交于 2019-11-28 01:34:30
pesho hristov

I managed to figure it out. And now I'm sending PUSH with payload successfully :)

The problem was that when I was registering for PUSH - I was doing it like this:

reg.pushManager.subscribe({
    userVisibleOnly: true
})

When I did it like this:

reg.pushManager.subscribe({
    userVisibleOnly: true,
    applicationServerKey: new urlBase64ToUint8Array([VAPID public key)
})

then it worked just fine. Now I'm able to send normal PUSH or PUSH with payload, with no problems.

More info:

  1. https://rossta.net/blog/using-the-web-push-api-with-vapid.html
  2. https://web-push-book.gauntface.com/chapter-02/01-subscribing-a-user/

And regarding all the tutorials that tells you to use only the userVisibleOnly property...that doesn't work. I don't know why they would be recommending this.

  • One of situations you will meet this error described following:

    One will produce the wrong process

    And Google tutorial also mention following:

    open DevTools (Right Click > Inspect) and go to the Application panel, click the Service Workers tab and check the Update on Reload checkbox. When this checkbox is enabled the service worker is forcibly updated every time the page reloads.

  • If you want to push notification with payload in website:

    Add applicationServerKey in when you subscribe

  • If you add applicationServerKey in when subscribe

    1. Keys generated by openssl not work for me.
    2. Keys generated by vapid not work for me.
    3. Keys generated by website mentioned in google tutorial works.
  • Workable keys generator: Workable keys generator

  • Workable google tutorial: Workable google tutorial

Conclution

  1. I add applicationServerKey and cause errors
  2. I use Workable keys generator but still errors
  3. I follow Google tutorial to update service worker to prevent some error
  4. works
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!