Skip to content

Broadcasting

W. ❝Mac❞ McMeans edited this page Jan 1, 2024 · 7 revisions

By design, the localDataStorage interface sends custom events locally to the same tab/window in which the storage change event occurred. Yet equally as convenient, it also broadcasts to any other tabs or windows on the same origin via the Broadcast Channel API. In this way, browsing contexts can be kept in sync, if necessary.

(Web content's origin is defined by the scheme (protocol), hostname (domain), and port of the URL used to access it. Two objects have the same origin only when the scheme, hostname, and port all match.)

The default channel name is localDataStorage and can be renamed using the broadcast method. The channel name is stored in the channel property.

To listen on the channel, use code like this

const myChannel = new BroadcastChannel( 'localDataStorage' );
myChannel.addEventListener( 'message', (event) => {
    console.log( event.data );
});

where the subscriber will receive a JSON detailing the change event, for example:

image

localStorage Keys

The usual suspects:

set / get      clear      key      remove

The esoteric ones:

Array Keys:
push / pull, pullall      poke      contains      where

Broadcasting:
broadcast

Bypass:
forceset / forceget

Data Transfer:
import / export

Duplicates:
countdupes, showdupes, listdupes

Internals:
cancrunch      crunch / uncrunch

shufflestring / unshufflestring

xorstring

Management:
keys

Memory Consumption:

Memory Quota:
showquota

Query:
haskey, hasval, hastype

Security:
safeset / safeget

setscramblekey / getscramblekey

Type Check:
isarray      isbigint      isboolean      iscrunch

isdate      isfloat      isinteger      isnull

isnumber      isobject      isstring

showtype

Utility:
chopget      copy      softset      rename

Properties:

channel      length      quota      version

Settings:

verbosity

Memory Keys

Standard:

_set / _get      _clear      _key      _remove

Unconventional:

Data Sync:
_backup / _restore

Management:
_keys

Security:
_safeset / _safeget

Type Check:
_isarray      _isbigint      _isboolean      _iscrunch

_isdate      _isfloat      _isinteger      _isnull

_isnumber      _isobject      _isstring

_showtype

Utility:
_chopget      _copy      _softset      _rename

Clone this wiki locally