Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

70
Views
Listening to "notificationclick" in browsing context

I have set up desktop notifications using:

Notification.requestPermission((result) => {
  if (result === "granted") {
    navigator.serviceWorker.register("/dummy.js").then((registration) => {
      registration.showNotification("Hello", {
        body: "Buzz! Buzz!",
        actions: [{...}],
      });
    });
  }
});

I can't use the Notification constructor, as I need to show buttons (actions) on the notifications, and for some reason the constructor doesn't support this.

I have no intention of firing or listening to the these notifications when the app is not open in a browser tab.

Is there a way to listen to the "notificationclick" and other notification related events from the main browsing context, and not from within the worker?

Alternatively is there any way to use the full set of features on the Notification constructor without having a worker?

To clarify further: I don't need the worker for anything other than using actions on the notifications. I only need to fire notifications / listen to notifications while the app is running in the browser, so I want to interact with the worker as little as possible. Writing logic for notification events in the worker itself is highly undesirable.

7 months ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.