The value stored under key, or undefined when there is none.
After a reload the plugin resumes the item it was working on. get
asks the player and resolves with the value parsed from JSON, or
undefined when nothing is stored; the value is not checked, so its
shape is checked here.
const current = await plugin.storage.session.get<{ url: string }>("current");
if (typeof current?.url === "string") await plugin.osd.show("Resuming {}", [current.url]);
Store or replace value under key. invalid for a bad key or a value
that is not JSON, limit when the plugin's values would be over 1 MiB
or the request over the 1 MiB message limit.
limit (rejects) The plugin's values would pass 1 MiB, or the
request the 1 MiB message limit; nothing changes.
Remove a key; removing a missing one is fine.
The keys stored, in code point order.
plugin.storage.session: JSON values that live as long as the player, not as long as the plugin's process (likechrome.storage.session).activatecan run more than once in one player session: the player stops and starts a plugin's process again when the plugin is reloaded (also a development load with--plugin) or upgraded, and after a crash or a failed start; the player also restarts plugins that share a process, and stops an idle plugin after 30 s and starts it on its next use. Variables, timers,fetchcalls, sockets and pending promises do not survive that (nor do they keep the plugin running): keep state that must survive a restart here (or in storage.json when it must also survive the player quitting) and pick it up again inactivate.packages.setEnabled(id, false)), disables the pluginenabled: falseswitches an enabled plugin offreplace) is dropped because the player keeps only so many--plugin) has its own.setstores whatJSON.stringify(value)writes, andgetreturns that, parsed:undefinedobject properties are dropped, aDatecomes back as a string,NaNasnull. The order of an object's properties is not kept: they may come back in another order. A valueJSON.stringifycannot write (undefined, a function, a cycle, aBigInt) or a string with a lone surrogate ("\uD800") fails withinvalid. The value is not checked when it comes back: after an upgrade an older version's value may be read, so check its shape when it matters.setbeyond it fails withlimitand changes nothing. Onesetis also one message to the player, at most 1 MiB with its key, so a single value is a little smaller than that; a larger one fails withlimit. Split large state over several keys.setis kept once its promise resolves, so a crash right after loses nothing; there is no debounce. Calls answer in order.Example: Keep a work queue across a plugin restart
A download queue survives the plugin being reloaded or crashing, and is empty again when the player starts next time. Session storage lives in the player process for one player run; each
setis kept once its promise resolves, so nothing is lost if the plugin dies right after.Since
1.5.25
Remarks
The player keeps the values in its own memory, per plugin, until it quits; the plugin's process may restart in between. Each call is one request to the player, answered in order, with no debounce.