googlearchive / web-push-encryption

[Deprecated] Encryption Utilities for Web Push protocol
Apache License 2.0
84 stars 23 forks source link

No notification with data #53

Closed koderyoda closed 8 years ago

koderyoda commented 8 years ago

Here is my little test script that is supposed to send the chrome notification:

import * as chromePusher from 'web-push-encryption';

export function sendChromeNotification() {
  let subscription = {
     "endpoint":"https://android.googleapis.com/gcm/send/**********",
     "keys":{"p256dh":"***********-*********=",
     "auth":"*******=="}
  };

  chromePusher.setGCMAPIKey("**********");

  let dataPayload = "test string";
  chromePusher.sendWebPush(dataPayload, subscription)
    .then((response) => console.log("push response=", JSON.stringify(response)))
    .catch((err) => console.log("push error=", JSON.stringify(err)));
}

This is the response printed in console: "push response= {\"statusCode\":201,\"statusMessage\":\"Created\",\"body\":\"\"}

But no notification is received in the browser.

But but, if I set dataPayload to blank, then the notification is received. Except of course it defeats the purpose.

Don't know if this is a library problem or GCM but any pointers would help.

This whole setup is running on localhost, not sure if that could be a problem for the browser to reject the notification and how to fix it.

koderyoda commented 8 years ago

ok I switched to my domain with https and local host file mapping and this worked, getting the data alright. Thanks.