# \[bug-3835\] Vision web browser does not save local storage?

**URL:** <https://forum.inductiveautomation.com/t/bug-3835-vision-web-browser-does-not-save-local-storage/49600>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 5, 2021, 3:02pm UTC](https://forum.inductiveautomation.com/t/bug-3835-vision-web-browser-does-not-save-local-storage/49600 "2021-08-05T15:02:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [August 5, 2021, 3:02pm UTC](https://forum.inductiveautomation.com/t/bug-3835-vision-web-browser-does-not-save-local-storage/49600/1 "2021-08-05T15:02:24Z")

</div>

Hey,

Ive build some custom modules that use the localstorage of the browser. They all work fine in chrome and the perspective designer.  
But now i tried to use them in perspective workstation and vision web browser. But its not working as expected ☹ .  
Only on startup things get saved, but in runtime the localstorage doesnt get updated, nor does it ever seem to use it.

Anyone an idea if its just a setting somewhere that could be turned on or is it just not possible?  
the vision web browser i kinda expected, but that the workstation app doesnt work is kinda strange.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 5, 2021, 11:18pm UTC](https://forum.inductiveautomation.com/t/bug-3835-vision-web-browser-does-not-save-local-storage/49600/2 "2021-08-05T23:18:08Z")

</div>

LocalStorage is supposed to be enabled by default in JxBrowser, and we’re not specifically disabling it anywhere…  
I’ll make a ticket to investigate.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [August 6, 2021, 6:31am UTC](https://forum.inductiveautomation.com/t/bug-3835-vision-web-browser-does-not-save-local-storage/49600/3 "2021-08-06T06:31:01Z")

</div>

Thanks !  
i will investigate a bit further myself too and post if i find something that seems interesting

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [August 6, 2021, 8:16am UTC](https://forum.inductiveautomation.com/t/bug-3835-vision-web-browser-does-not-save-local-storage/49600/5 "2021-08-06T08:16:35Z")

</div>

@paul-griffith

Update.  
Seems its working on perspective workstation but the localstorage doesnt get saved in vision after relaunching the app.

Ive added some textfields that read the localstorage and its there during runtime in both apps (and browser).  
But after restarting the vision app its all empty again. In perspective it persists tho. So its just vision that is doing weird

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [February 21, 2023, 7:11am UTC](https://forum.inductiveautomation.com/t/bug-3835-vision-web-browser-does-not-save-local-storage/49600/6 "2023-02-21T07:11:08Z")

</div>

Did you manage to find something about this?

It still doesnt seem to save the storage when the vision client is restarted:(

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 21, 2023, 4:17pm UTC](https://forum.inductiveautomation.com/t/bug-3835-vision-web-browser-does-not-save-local-storage/49600/7 "2023-02-21T16:17:11Z")

</div>

The ticket is marked as 'green' in our backlog, and we've got a lot of those, so no one has actually done any investigative work.

I _suspect_ that it's something with how we're restarting the entire browser engine every time you open/close the page. Does changing the cache policy of the window you're using the browser component on change anything?

It might also be possible to workaround with scripting; you might be able to ask JxBrowser for localstorage when the window is shutting down, store it in e.g. `system.util.getGlobals()`, and then reapply it if the window opens back up?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 21, 2023, 4:38pm UTC](https://forum.inductiveautomation.com/t/bug-3835-vision-web-browser-does-not-save-local-storage/49600/8 "2023-02-21T16:38:03Z")

</div>

Victor is talking about relaunching the entire app, not reopening windows. Perhaps a local file for localstorage needs to be involved.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [February 22, 2023, 7:42am UTC](https://forum.inductiveautomation.com/t/bug-3835-vision-web-browser-does-not-save-local-storage/49600/9 "2023-02-22T07:42:28Z")

</div>

It works for the windows, but not when restarting the entire app.

Yestarday I have created a workaround by read/write to a file. Not fully tested yet, but so far it seems to work.

It was a bit of a pain making use of the jxbrowser functions in jython xd as the callback function didnt want to get recoginzed without a class wrapper. Took me a while to find that out xd

InternalFrameClosing

```auto
from java.util.function import Consumer
class jc(Consumer):
    def __init__ (self, fn):
        self.accept=fn

def writeStorage(frame):
	storage= frame.localStorage()
	row={}
	for x in range(storage.length()):		
		key = storage.key(x).get()
		item = storage.item(key).get()
		row[key] = item		
		
	userFolder = system.tag.readBlocking("[System]Client/User/HomeFolder")[0].value
	jsonFile = system.util.jsonEncode(row)
	system.file.writeFile(userFolder+"/LocalStorage.txt", jsonFile)
	
	
browser = system.gui.getParentWindow(event).getComponentForPath('Root Container.Web Browser').browser
browser.mainFrame().ifPresent(jc(lambda frame: writeStorage(frame)))

```

InternalFrameOpened

```auto
from com.teamdev.jxbrowser.navigation.event import NavigationFinished
from com.teamdev.jxbrowser.event import Observer

class obs(Observer):	
	def __init__ (self,fn):   		
   		self.on=fn 
		
def readStorage(ev):	
	storage= ev.frame().localStorage()
	userFolder = system.tag.readBlocking("[System]Client/User/HomeFolder")[0].value	
	if system.file.fileExists(userFolder+"/LocalStorage.txt"):	

		jsonObj = system.util.jsonDecode(system.file.readFileAsString(userFolder+"/LocalStorage.txt"))	
		for key in jsonObj:	
			storage.putItem(key,jsonObj[key])
	
browser = system.gui.getParentWindow(event).getComponentForPath('Root Container.Web Browser').browser
browser.navigation().on(NavigationFinished,obs(lambda ev: readStorage(ev)))

```
