WebExeBuilder Documentation

get

Category: Storage

Namespace: web.storage.get

Description

Read a value from the app's persistent key-value store by key name. Returns null if the key has never been set.

Syntax

const value = await web.storage.get({ key: 'keyName' });

Parameters

Parameter Type Required Description
key string Yes The key name to retrieve

Returns

Promise<string|null> - The stored string value, or null if the key does not exist

Example

Simple example

const name = await web.storage.get({ key: 'username' });
console.log(name);  // "Alice" or null

Practical example — load with default fallback

const difficulty = await web.storage.get({ key: 'difficulty' }) || 'normal';
const soundEnabled = (await web.storage.get({ key: 'soundEnabled' })) !== 'false';
const highScore = parseInt(await web.storage.get({ key: 'highScore' }) || '0', 10);

Advanced example — restore a saved object

async function loadPlayer() {
    const raw = await web.storage.get({ key: 'player' });
    if (!raw) {
        // First run — return defaults
        return { name: 'Player', level: 1, xp: 0 };
    }
    try {
        return JSON.parse(raw);
    } catch {
        return { name: 'Player', level: 1, xp: 0 };
    }
}
  • web.storage.set() - Save a value by key
  • web.storage.remove() - Delete a key
  • web.storage.keys() - List all key names

Notes

  • Returns null (not an empty string) when a key does not exist — always check for null before using the value
  • Values are always returned as strings — parse numbers and objects as needed
  • Keys are case-sensitive