0

I already did an app in Android studio but I'm building a WebPage to send a notification to Firebase Messaging to push notifications on the app.

This is the module to get Firebase properties

//class name: network.js

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.1/firebase-app.js";
import {
  getMessaging,
  getToken,
} from "https://www.gstatic.com/firebasejs/9.22.1/firebase-messaging.js";

const firebaseConfig = {
  i have all information about my firebase project and keys
};

const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const getData = getDatabase(app);
const messaging = getMessaging(app);

export { messaging, getToken };

here is my script file to use they: // classname: script.js

import { messaging , getToken } from "./network.js"

const topic = "cozinha";

const message = {
  notification: {
    title: "Test Title",
    body: "Test Body example text",
  },
  topic: topic,
};

getMessaging()
  .send(message)
  .then((response) =\> {
    // Response is a message ID string.
    console.log("Successfully sent message:", response);
  })
  .catch((error) =\> {
    console.log("Error sending message:", error);
  });

When I try to use it I receive an error called:

Uncaught ReferenceError: getMessaging is not defined

I tried to use other ways like:

messaging.send() ....

Uncaught TypeError: messaging.send is not a function

messaging.getMessaging().send ...

Uncaught TypeError: messaging.getMessaging is not a function

I hope you guys can help me. Thank you and have a nice day.

Julia
  • 512
  • 6
  • You cannot send messages from the client-side. See [this answer](https://stackoverflow.com/a/37993724/283366) – Phil Jun 15 '23 at 01:43
  • hi @Philisonstrike thank you for a moment to help me. on android when i build it its works fine i can seend messages from my android app now im trying on my web page its getting hard. im did a post using postman its works fine but i cant find any documentation to use it fetch not works too – Tiago Silva Jun 16 '23 at 01:42

0 Answers0