Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the OS as well as javascript/HTML5 access localstorage?

I would like to read the browser's "localstorage" when the browser is off using the OS !

I want to save client data in localstorage and then switch off the browser and the internet and then let an OS program (a windows exe) access and analyse that data and then write new data into that localstorage area so that when the browser restars the new data is in localstorage.

This should be possible because my OS (i.e. windows) can read can delete cookies from the browser "files" ... so presumably once i know the format of the localstorage "file" then the OS is boss of all of its files and so it should be able to alter them !

So: how do i read and write to JavaScript/HTML5/DOM "localstorage" using "client side .exe programs" ?

FAILING THAT: is there any other way that the OS can pass simple data into (and out of) the browser ?

Obviously all of this has both huge potential POWER and huge potential DANGER !

The browser can only become the "virtual OS of the future" if the real OS can interact safely with it !!

Thank You.

like image 548
Clive Williams Avatar asked Feb 03 '13 21:02

Clive Williams


1 Answers

Of course an app running locally with the appropriate permissions can access any file on disk. However, the real question is what to do with that file once it's open?

Consider the following:

  • Each browser (Chrome, Firefox, IE, Opera) is likely to store localstorage data in its own proprietary format. You'd have to reverse engineer those formats.
  • Since those formats are an implementation detail (not a documented API), they are liable to change. This will break your app and/or corrupt user data.
  • What happens if you modify those data files while the browser is open (even if the page in question isn't open)? The browsers don't expect their data files to change out from underneath them, so it's likely you'd see strange behavior.

All of this is to say that this is a very bad idea. You're messing with the internals of someone else's application; that's a big no-no.

Have you considered an alternative approach? When I was faced with a similar problem, I simply implemented a very simple HTTP server in my app that was bound to a specific port on 127.0.0.1.

With XHR and the appropriate CORS headers, your browser-based application can communicate with your desktop app in a safe manner.

like image 55
josh3736 Avatar answered Sep 29 '22 20:09

josh3736