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

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 :frowning: .
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.

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.

2 Likes

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

@PGriffith

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

1 Like

Did you manage to find something about this?

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

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?

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

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

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

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)))
1 Like