Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 'Service Worker' support offline HTML form data?

Service Workers essentially act as proxy servers that sit between web applications.

My concern: Is ServiceWorker also support for offline forms? - If so then my other list of concerns are:

  1. Where it stored the incomplete HTML form data at client side (Storage, Session, Local, Database)?
  2. In which form it stores user's filled data (encryption etc.)
  3. How the data security/privacy tackled? that the returning user is the same user? - if one user had filled out the form in public place and lost the internet connection and left the incomplete form and move on, now the next immediate user can see the incomplete form data, where the last user left the form.
like image 677
Dawood Butt Avatar asked Sep 03 '25 17:09

Dawood Butt


1 Answers

First off, service workers could potentially do a lot of things. They have access to IndexedDB, for instance, so there's always the possibility of saving and loading arbitrary data, from the context of either a controlled page or a service worker.

But none of that will happen automatically by virtue of having an service worker registered—a service worker will, by default, do absolutely nothing. It's only when you write code in the service worker to hook into different events (install, fetch, message, etc.) that things get interesting.

Hypothetically, if you were to write code in a service worker that cached an HTTP response for an HTML resource and then responded to fetch events for the request's URL with that cached response, then the browser would get back and render the same HTML as it would if the response had come from the network. There wouldn't be any special "form state" that gets cached along with the HTML response body.

If, for some reason, you did want to save "form state" so that users who leave a page with a form could return and continue editing it, you'd have to do that independently of the caches object that's exposed to the service worker. (caches requires that you use Request objects as keys and stores Response objects as values.)

So you could potentially do it using IndexedDB, or you could do it using localStorage, or really anything else. It's independent of the service worker, and the particular privacy/security considerations are up to the implementer.

like image 122
Jeff Posnick Avatar answered Sep 06 '25 10:09

Jeff Posnick