Home > widget-integration > FilterStorageHelper > setSessionStorage

FilterStorageHelper.setSessionStorage() method

Sets a value in sessionStorage with JSON serialization.

Serializes the value to JSON and stores it in sessionStorage. Catches and logs errors from quota exceeded, circular references, or private browsing mode restrictions.

Signature:

setSessionStorage<T>(key: string, value: T): void;

Parameters

Parameter

Type

Description

key

string

The sessionStorage key to set

value

T

The value to store (will be JSON stringified)

Returns:

void

Remarks

Errors are logged to console but don't throw. Common error scenarios: - QuotaExceededError: Storage limit reached - TypeError: Circular structure in value - SecurityError: Private browsing mode restrictions

Example

Override to add compression for large values:

setSessionStorage<T>(key, value) {
  const serialized = JSON.stringify(value);
  if (serialized.length > 10000) {
    // Compress large values
    const compressed = this.compress(serialized);
    super.setSessionStorage(key + ':compressed', compressed);
  } else {
    super.setSessionStorage(key, value);
  }
}