Skip to content

Instantly share code, notes, and snippets.

@dominwong4
dominwong4 / .js
Created Feb 20, 2021
Javascript overriding LocalStorage and SessionStorage for hiding data
View .js
//For React, just put this into anyway inside the react project
const _setItem = Storage.prototype.setItem;
const _getItem = Storage.prototype.getItem;
Storage.prototype.setItem = function(key, value) {
if (this === sessionStorage) { //example of specific Storage type
_setItem.call(this, key, btoa(encodeURIComponent(value)));//encodingURI is for language other than Latin
} else {
_setItem.call(this, arguments[0], arguments[1]);