Skip to content

Instantly share code, notes, and snippets.

@thecompez
Created October 21, 2025 19:33
Show Gist options
  • Save thecompez/592d59b52b4e6b3d6897b3d9920ec862 to your computer and use it in GitHub Desktop.
Save thecompez/592d59b52b4e6b3d6897b3d9920ec862 to your computer and use it in GitHub Desktop.
Notify Usage
/**
* Sends a test notification by calling the backend endpoint.
* Uses the notificationDetails passed from the frameAdded event.
* @param {Object} notificationDetails - An object containing { url, token }.
*/
async function sendTestNotification(notificationDetails) {
try {
// Send a POST request to store the notification details.
const storeResponse = await fetch("send-notification.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(notificationDetails)
});
const storeData = await storeResponse.json();
console.log("Notification details stored in file:", storeData);
// Only trigger the test notification if storage was successful.
if (storeData.status === "success") {
const notifyResponse = await fetch("send-notification.php");
const notifyResult = await notifyResponse.text();
console.log("Send notification response:", notifyResult);
}
} catch (error) {
console.error("Error in sendTestNotification:", error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment