see what's being returned with the browser's devto...
# javascript
s
see what's being returned with the browser's devtool?
c
That's the response that CF receives from the http call:
Copy code
{
  "ErrorDetail": "",
  "Mimetype": "application/json",
  "Statuscode": "200 OK",
  "Filecontent": "{\"multicast_id\":8596430052349615309,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"3ea2ac14-002f-4221-92a1-ab2a308de87f\"}]}",
  "Responseheader": {
    "Cache-Control": "private, max-age=0",
    "Content-Security-Policy": "frame-ancestors 'self'",
    "Alt-Svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
    "Status_Code": 200,
    "Http_Version": "HTTP/1.1",
    "X-Frame-Options": "SAMEORIGIN",
    "Explanation": "OK",
    "Connection": "close",
    "Date": "Mon, 21 Nov 2022 15:07:39 GMT",
    "Transfer-Encoding": "chunked",
    "X-XSS-Protection": "1; mode=block",
    "Expires": "Mon, 21 Nov 2022 15:07:39 GMT",
    "Server": "GSE",
    "Content-Type": "application/json; charset=UTF-8",
    "X-Content-Type-Options": "nosniff"
  },
  "Text": true,
  "Charset": "UTF-8",
  "Header": "HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\nDate: Mon, 21 Nov 2022 15:07:39 GMT\r\nExpires: Mon, 21 Nov 2022 15:07:39 GMT\r\nCache-Control: private, max-age=0\r\nX-Content-Type-Options: nosniff\r\nX-Frame-Options: SAMEORIGIN\r\nContent-Security-Policy: frame-ancestors 'self'\r\nX-XSS-Protection: 1; mode=block\r\nServer: GSE\r\nAlt-Svc: h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"\r\nConnection: close\r\nTransfer-Encoding: chunked\r\n"
}
s
that doesn't matter to that onMessage function, it's what CF actually spits back if i understand this correctly
open up dev tool and perform the action and check under network to see what you have cf returning
then check what onMessage is expecting and see if it's aligned. Could be return type, maybe there's debugging output, expecting json, etc.
c
So I do an Ajax call to CF and in the callback function I
console.log()
the response from the http call that CF makes to Google. I thought that with Firebase Cloud Messaging, the backend server (CF) sends a request to Google and Google then in turns sends a push message to the registered client. It's not the CF server that hand's back the response to the client. Or am I misunderstanding what you said? Maybe my approach is all wrong, ultimately I need a way to send a msg to one specific client without the other clients seeing (or even receiving) the message. I wanted to go with web sockets, but, due to the setup my client is using with his servers, this proves to be a major pain, too. 😞
s
ok, if that's how it works, then not sure, a api question that i'm not familiar with
m
i would take CF completely out of the picture and try to send straight from the FCM Console ... after you have proven you can receive messages then go a step forward and solidifying sending messages from CF
s
Looks like this stuff relies on the browser's notification API which requires the user to grant notification permission. Unless you've already done that somewhere else.
a
@chris-schmitz You’re conceptually right. Your backend, whatever that might be pushes into Firebase via a Google endpoint. If you get a 200 with a
message_id
back then your communication between CF/Lucee and Firebase was ok and you should expect the message to be delivered. So, I’d look into the client side of things on why the message is not being received or displayed. I’ve never done this with JS but only in native apps and Flutter, but from experience any issue I had was almost every time one of: • Somehow mismatching or missing device token from Firebase • Data format being passed into the FCM/GC endpoint and what the other side expect.
c
@Michael Schmidt I'll try that, thanks
@s1deburn I've already implemented that, at this point in the PWA the user has granted permission to show notifications
@agentk that's what I was thinking. I got a feeling it may be a combination of both, will have to dig deeper
s
@chris-schmitz I mucked around with this the other day. Definitely use the firebase console to fire the test, you just need the token from the browser. So you know where the issue could be. The other thing is that there's are 2 paths for web. One where the page is in the foreground which is what you have. The other is background and you'd need to implement code in the defaulted filename of "firebase-messaging-sw.js". All new to me as well, but I did manage to get the basics of this working. For the foreground code to get the message, the browser has to have the page in the active tab from what I saw, won't fire if not in the active tab. In background, it'll fire the code in a service worker which will use code from that other file.
c
yeah I saw that, too. I have not been able to work on this over the last days, as it is just a PoC for now and more urgent things have come up. Will get back to this either today or tomorrow