LaunchDarkly: how to access flag values from `localStorage` - javascript

I'm using LaunchDarkly in a web app and am playing around with using the 'localStorage' bootstrap option on initialization.
With this option I clearly see my flags in localStorage and they look to be under a key formed with my clientId and then some long, base64 string - I'm curious if there is a clear pattern I can use to access the flag values in localStorage with getItem or if I'm perhaps completely misinterpreting the use case?
What I tried was adding the optional bootstrap option and then logging out my localStorage to see what key the flag values were being stored in, and they appear to be mapped to a key that includes my LD client ID and then some long, seemingly random string.
What I expected was for my keys to be stored under a key of maybe just my LD client ID or some other, easily found property name.
Thank you for any and all insight!
Best,
Zach

The JavaScript client SDK already caches flags in localstorage for you. When the SDK initializes, the flag values for the context (i.e. user) you provide are pulled and cached in localStorage. From that point on, LaunchDarkly's SDK uses localStorage for getting flag values, speeding up flag evaluations and ensuring that flags can be evaluated in the circumstance where LaunchDarkly is temporarily unavailable. Updates to this localStorage cache are streamed by default (though you an configure this for polling).
My point is, there may be no need for bootstrapping off localStorage. Bootstrapping on the client-side is useful for situations where you are writing these values prior to the response hitting the client's browser (for example, you are writing bootstrapped values at the edge).

Related

What happens when local / Session Storage is full?

I know its near to impossible but I have a question in my mind.
what will be the behavior of the web application if all the web storage(local / session) is full in angular web app ?
Does it effect the performance of the web app ? if yes then how it will effect ?
how the application will react in the following browsers chrome, firefox and Opera ?
I'm reading a blog which discuss the session and local storage but i did't find my Answer there.
(https://krishankantsinghal.medium.com/local-storage-vs-session-storage-vs-cookie-22655ff75a8)
If storage is full when you try to add something to it, according to the specification the method that's adding the new/updated item must throw a QuotaExceededError. So your app/page will work just fine if storage is full but if it tries to add anything, that action will fail with an error.
From that link:
The setItem(key, value) method must first check if a key/value pair with the given key already exists in the list associated with the object.
If it does not, then a new key/value pair must be added to the list, with the given key and with its value set to value.
If the given key does exist in the list, and its value is not equal to value, then it must have its value updated to value. If its previous value is equal to value, then the method must do nothing.
If it couldn't set the new value, the method must throw a QuotaExceededError exception. (Setting could fail if, e.g., the user has disabled storage for the site, or if the quota has been exceeded.)
(my emphasis)
There is a special exception for that: quota exceeded.
You can read about it here: https://chrisberkhout.com/blog/localstorage-errors/

How to determine if TURN server is being used (WebRTC)?

I want to gather stats on the number of users having to fallback to TURN servers. Thus is there a way to find if a RTCPeerConnection is using a TURN server instead of "directly" communicating with a remote peer?
I've tried using pc.getStats() but that only gives me an object with a size property.
You want to use getSelectedCandidatePair. This will return the local/remote candidate that is being used. Each candidate will have a type host, srflx, prflx or relay. relay means it is using TURN.
Make sure to check both candidates. It is possible that both pairs are TURN (or maybe just one)
the getStats() result is a Javascript Map object. You can iterate it to find what you need. To get the active candidate pair (and then determine its type) it is best to follow the code from this sample (which works around the quirks of some browsers) and then check whether either the local or remote candidateType is 'relay'.

Not allow localstorage to be changed by user

I use localstorage to store things like highscore in this game: http://wacky2048.ga/
If you inspect element and on the top navigation bar (where you see Elements ... Performance), then click the >> button, click Application, you can see all the localstorage items, and if you double click, you can change it. You may need to make a move and refresh.
A lot of people know this trick so the highscore becomes meaningless.
Is there any way to stop this? I store integers and JSON stringified things (in case you want to suggest a encoding method).
The better solution would be store the data in the server. But if you really want to use localstorage consider storing the JSON as a jwt token and encrypt it using a private key which user doesn't have access.
Also when your app access that data in the localstorage always check for validity. If the token is invalid, what you can do is re fetch the information from the server.
Like i said before this is more of a dumb approach. Storing data in the server would be a better solution.
Edit: To hide the private key you could use environment variables like NODE_ENV (this depends on the framework you are using)

Store in PouchDb without need of revision

I'm using PouchDB to store values that come from a database (values sent by the server) but also for some values that are only set by the user from front-side (and so should stay local).
Those front-side values should persist accross multiple connections to the app. That's why I store them in PouchDB.
Since I don't care about the revision system (only one user can modify them from one location - its browser), I'm wondering if there is a way to tell PouchDB to say so. I know there is a force parameter for calls, but there is still a need for _rev property in those cases...
Is there a way to get rid of the notion of revision and conflict for one table ?
Cheers

localStorage not storing persistently between two pages

I'm developing an application and, at certain point, I need to store information that requires to be persistent between multiple pages, more probably, it will only be 2 pages.
The amount of information varies between just a few bytes and about 15KB (It will never be more than 20KB, ever). I can't really properly predict beforehand how much it will be.
For that I decided to use localStorage.
For now I'm only working on localhost:8080.
The pages, for now have only generic names: pageA.php and pageB.php.
The pages reside on the root of the domain. I.e.
http://localhost:8080/pageA.php
http://localhost:8080/pageB.php
...
At certain times, I store data on localStorage, on pageA.php (I do use the setItem() method).
When the user moves to pageB.php, pageB.php's script then tries to get the data that was stored in pageA.php.
The problem is that getItem() always returns null on pageB.php
I did check the keys I'm using and they are the same, so there should be no problems there.
I've checked, data stored is persisting between page loads as long as the url does not change.
What am I doing wrong here?
Note: tested only on Firefox 19 and on chrome 24
The problem here was that the editor I was using had been changed such that it was searching with case sensitivity.
When I changed the string i was using for the key, the replacer didn't match all the strings due to case sensivity.
I solved it by searching and adapting each key such that all keys had the same characters with the same case, not the same characters regardless of case.
In the in the end, it was just lack of attention. As expected, strings in javascript are case sensitive and that also applies to the key for localStorage and sessionStorage

Categories