Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capacitor local notification in pwa with Ionic 5

As related to this documentation :

https://capacitorjs.com/docs/apis/local-notifications

It seems possible to use Capacitor local notification plugin for the web as pwa also.

I try to push "test" a local notification every 10 seconds but nothing happen even with service worker enabled

import { Plugins } from '@capacitor/core';
const { LocalNotifications } = Plugins;

const notifs = await LocalNotifications.schedule({
  notifications: [
    {
      title: "Title",
      body: "Body",
      id: 1,
      schedule: {
            repeats: true,
            every: "second",
            count: 10
          },
      sound: null,
      attachments: null,
      actionTypeId: "",
      extra: null
    }
  ]
});
console.log('scheduled notifications', notifs);
like image 958
de albuquerque frank Avatar asked Oct 12 '25 08:10

de albuquerque frank


1 Answers

In the source code of the LocalNotification plugin for web it seems as though the notification is only scheduled if the schedule option has the "at" property. Even then I can't get it to work on chrome for android.

Notification scheduling for PWAs is currently in trial using the TimestampTrigger so I think the lack of browser support is the issue. Possibly getting out of trial during 2021. Just have to wait and see I guess.

like image 89
GustafHultgren Avatar answered Oct 14 '25 13:10

GustafHultgren