Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background Geolocation ServiceWorker - onMessage Event order when Web App regains focus [closed]

For complete details, and a more lengthy description, please refer to this W3C Service worker issue.

This is my HTML5 Web App scenario: -

  • My Web App has been backgrounded and stuck in my pocket while I go for a ride
  • As I clock up the KMs my Service Worker(s) is regularly receiving GPS updates and invoking postMessage() to queue them up for my App to eventually plot on the Google map
  • At the end of the ride I order a beer and foreground the Web App so I can see where I've been, average speed, and so on.

My question are these: -

1) Will the Focus event fire before or after all of the Message events triggered by the ServiceWorkers?

2) If Focus is first will a setTimer(0,backlogCleared) suffice as a heuristic mechanism to establish "all background stuff dealt with"?

3) Is there anyway to collapse the postMessage() messages (al la mode Firebase's push notifications) so that only the last/current message is received?

4) If you have ideas about the permissions required to authorize background geolocation please add them over at W3C.

Cheers and good riding, running, sailing, driving!

like image 787
McMurphy Avatar asked May 29 '17 01:05

McMurphy


People also ask

When is a background service worker loaded or unloaded?

A background service worker is loaded when it is needed, and unloaded when it goes idle. Some examples of events include: The extension is first installed or updated to a new version. The background page was listening for an event, and the event is dispatched.

What are events in a background service worker?

A background service worker is loaded when it is needed, and unloaded when it goes idle. Some examples of events include: The extension is first installed or updated to a new version. The background page was listening for an event, and the event is dispatched. A content script or other extension sends a message.

How do I monitor the lifetime of a background service worker?

The lifetime of a background service worker is observable by monitoring when an entry for the extension appears and disappears from Chrome's task manager. Open the task manager by clicking the Chrome Menu, hovering over more tools and selecting "Task Manager". Service workers unload on their own after a few seconds of inactivity.

How do service workers work in the Chrome extension?

Another view in the extension, such as a popup, calls runtime.getBackgroundPage. Once it has been loaded, a service worker keeps running as long as it is performing an action, such as calling a Chrome API or issuing a network request.


1 Answers

My Brotkrumen Ultimate Web App is now complete. All source/image files can be found at https://drive.google.com/open?id=0B7Rmd3Rn8_hDNW1zSWRoXzBTclU

Most important design/proposed-specification change is that TravelManager subscription should now be Client specific. The TravelEvent must contain the intended Client.id (TravelEvent.source.id). This means that the UA must monitor and filter GeoLocation updates per client. I have also added new demo functionality such as a Trip Summary that is displayed when you press the "Arrive" button. The trip can also be replayed onto Google Maps by pressing "Map Trip" or "Replay". If the last and next geolocation updates for the trip are both visible in the Map window then smooth Marker movement is achieved via CSS transitions.

PLEASE help Background GeoLocation get up and help Web Apps compete with Native Apps!

If there is something wrong with my TravelManager solution design then let me know. Tear holes in it!

like image 107
McMurphy Avatar answered Sep 29 '22 14:09

McMurphy