With the local storage API, you can store data in the browser's local storage. To use the local storage API, the customer's local storage admin switch has to be enabled.
Local storage is isolated so that each type of visual has its own separate storage access.
Note
It’s developer’s responsibility to ensure that the stored data conforms to the consumer’s organizational policies, and to inform users about what information is stored, if the sensitivity of the data requires it. In particular, custom visual developers should encrypt the data if business goals or scenarios expect it.
This version of the local storage API is scheduled for deprecation. We're not accepting any more requests. When possible, use Version 2.
In the following example, a counter is increased whenever the update method is called. The counter value is saved locally and called each time the visual starts. This way, the counter continues counting from where it left off instead of starting over each time the visual is started:
PrivilegeStatus.DisabledByAdmin: the tenant admin switch is off
PrivilegeStatus.NotDeclared: the visual has no declaration for the local storage in the privileges array
PrivilegeStatus.NotSupported: the API isn't supported (see limitations for more information)
PrivilegeStatus.Allowed: the API is supported and allowed
Before using the get, set, or remove methods, it's best practice to use the status method to check the status of the API and ensure that your visual behaves as expected.
get:
This method expects one parameter:
key – the key whose value you want to get.
Returns a promise that resolves with the value if the key exists, and rejects otherwise.
set:
This method expects two parameters:
key – the key you want to set its value
data – the value for the key
Returns a promise that resolves to a struct of the type StorageV2ResultInfo, or rejects if an error occurred.
Data can be shared between visuals with the same GUID only.
Data can't be shared with another instance of Power BI Desktop.
The local storage API isn't activated by default. To activate it for your Power BI visual, send a request to Power BI visuals support, pbicvsupport@microsoft.com.
The local storage API doesn't support await constructions. Only then and catch methods are allowed.
The key (parameter provided to set, get, Remove) has the following restrictions:
Length must be fewer than 128 characters
Can't contain the character '|'
If the browser is in kiosk mode, local storage availability might differ between browsers, and by the kiosk owner's settings.
There are many reasons this API might not be supported. For example, the environment might not be supported or the browser’s local storage isn't available. We recommend checking the status of the API before using the set/get/remove methods. Error handling is important since even if the API is supported, it might fail.