Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
PushManger.subscribe returns a NULL result

We use push notifications on the site. The worker code is pretty straightforward.

const subscribe = async () => {
    let sub = await self.registration.pushManager.getSubscription();
    if(!sub) {
        sub = await self.registration.pushManager.subscribe({
            applicationServerKey: serverKey(),
            userVisibleOnly: true
        });
    }
    let resp;
    try {
        resp = await fetch('/subscribe', {
            method: 'post',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(sub)
        });
        const body = await resp.json();
        if(body.status !== 'ok') resp = null;
    } catch(e) {
        resp = null;
    }
    if(resp) return;
    if(sub.unsubscribe) {
        sub.unsubscribe();
    } else {
        self.registration.pushManager.unregister(sub.endpoint);
    }
    await self.registration.unregister();
};

The code above is processed by Babel before landing on the production of cause. It works pretty well for us and for the majority of our users.

But from time to time we receive error reports from the back-end saying the just received subscription data is 'null'. I mean literally: the '/subscribe' endpoint gets 'null' string instead of a JSON encoded subscription object.

Is it possible for pushManager.subscribe to return NULL instead of the subscription object?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda