Is there a way to schedule offline notifications in a pwa? - javascript

I know you can send push notifications to a user who has installed the pwa. However, this always requires a server which sends that notification and also the end user device to be online to recieve and show it.
I was wondering if there is a way to "schedule" a push notification to be shown later, like it is possible on Android to be able to realize something like reminders for events, without the need to have an internet connections.
EDIT: Since Chrome 80, notification triggers are available as an origin trial.

There are at least 3 web APIs/specs in the development related to some form of the scheduled tasks. None of them are in production though.
Periodic Background Sync API
Explainer: https://github.com/beverloo/periodic-background-sync
Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=925297
Status: https://www.chromestatus.com/feature/5689383275462656 (in dev)
Main feature: it enables a web app to run tasks periodically while the device has network connectivity
Notification Triggers (a.k.a. Scheduled Notification API / Event Alarms)
Explainer: https://github.com/beverloo/notification-triggers
Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=891339
Status: https://www.chromestatus.com/feature/5133150283890688 (proposed, part of Project Fugu)
Main feature: this allows to show a notification (nothing else) reliably at a specific time in the future, even if the device is offline
Scheduled Task API (Generic Alarms)
Explainer: internal design docs only
Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=889077
Status: TBD, part of Project Fugu
Main feature: schedule code to run at a specified time in the future - cron for the Web
So answering the original question: your choice is Notification Triggers API. Hopefully this will land in the browsers soon.

Related

WebApplications, how to notify users when their device is sleeping

I've build a Javascript WebApp that is designed to work on tablets (using Web App Manifest file) and offline (aside from getting initial data from PHP backend). The app has custom notification system imitating Notifications API. Each notification is sent at given time (using setInterval). This leads to couple of problems:
there is no sound as the notifications are not effect of user interaction,
notifications can't be shown when the device is asleep.
First problem can be solved using Notifications API, but I'm not sure what could be done about the second. Keep in mind that the app should work offline - this eliminates the use of Push Notifications API.
Is using web application's container such as Cordova my only option?

Can a service worker update the cache without an open tab?

I want to give the user a speed feel when he accesses my website. If I cache the initial page in service worker, then I can achieve it. But I am having the following doubts.
Is there any way to update that cache even user does not have any tabs with my website?
Is there any memory limitation?
1) Not in a simple way - your Service Worker is suspended until something wakes it up, for example the user opening your app. Or the push message. So you might run your cache update flow in a push message handler and send the push to all subscribed users whenever the update should happen. But you have to be aware that there are limitations of how many pushes can the app receive and/or how long the handler can run.
"Normally" this is done when the new Service Worker version is installing and requires reload (or manual handling) to take effect.
2) Yes, the general storage limit applies. It is OS-specific and you can query for the estimate with Quota Estimation API (Chrome only by now).

Twilio TaskRouter: change worker activity when disconnected

Let's say worker X logged in to our call center app and went online in twilio. He will now be able to receive reservations and respond to people. X lives in a third world country where the internet connection is very unreliable. His internet suddenly cut off while online and he is no longer able to respond to reservations. His activity is still Online and he has no way of changing it because he doesn't have an internet connection. Is there a way to tell twilio to go Offline when the WebSocket connection is lost between the client and the server?
I'm aware that we have disconnectActivitySid in TaskRouter.js but it is only fired on window.unload event and doesn't cover the cases where the browser crashes or we have internet connectivity problems.
Twilio developer evangelist here.
The only way to do this today would be to have the Worker receive a next Reservation, but have a Workflow ReservationTimeout of a semi-low value (10-15 seconds) and to utilize the Workspace’s TimeoutActivitySid to push the Worker to Offline.
With that setup, if the Worker loses connection (but is Idle), and receives a Reservation and is able to reconnect before that Reservation Times out (in that 15 second window), they will presented the Reservation with the JS SDK. So nothing will be lost. If they do not reconnect within that timeout window, the Worker will be pushed to Offline, and another Worker will be eligible to pick up the Task.
Let me know if that helps at all.

Web Notification API example to notify everyday once

Im trying to use the web notification API (https://developer.mozilla.org/en-US/docs/Web/API/Notification) to show browser notification, something like the example of this link (in marked answer) Chrome desktop notification example
However, Im looking for something that will automatically show certain such notification on daily basis, on a particular time. Like i see such notification for facebook in chrome browser. Is that possible? how can i achieve that? I know there might some browser limitation, however i'll be happy if i can do that for chrome and firefox.
You would need to use the Push API, service workers, and some corresponding server infrastructure. That way, if users opt-in, you can wake up your service worker at a particular time and deliver a message to the user.

What's the best way for background polling in Windows 8 Metro apps?

I'm working on a Win 8 javascript app that has rss-reader-like capabilities. It should repeatedly check a server for new posts and display a toast, if a new post was found.
My question is, if I should use a background job with a time trigger (that is limited to an interval of 15 minutes) or if a setTimeout / setInterval wouldn't be the better way.
As far as I understand the app lifecycle, my app can be suspended by Windows at any time it is not focussed and Windows decides that timepoint on itself. And if the app is suspended once, neither background jobs will work, nor will the setTimeout / setInterval fire.
If I may, I'd suggest rethinking the notification mechanism here.
If you want to use a toast notification, I'd suggest a push notification. It does require a require a cloud service that does the polling of articles for you and then pushes the notification to subscribing clients; however, it won't tax the battery life of the client nearly as much as a polling trigger.
An issue with toast notifications is that they can be easily missed, so if you want to inform the user of unread articles, you may want to consider a badge notification that will persist on the application tile (like you see on the Mail application). Then at a glance the user will know there are unread articles, versus knowing that only if they happened to see the incoming toast.
Tile and badge notifications can also be updated periodically, which is similar to what you wanted to do with toast, but the mechanism for doing so is much easier. The challenge here though is that periodic notifications aren't generally personalized, that is every user of your app would see the same badge/tile unless you did a bit more work on the server side.

Categories

Resources