Registry / storage / cross-domain-storage

cross-domain-storage

JSON →
library2.0.7jsnpmunverified

cross-domain-storage v2.0.7 enables browser-localStorage sharing across subdomains and parent/child windows via postMessage. Low-maintenance, no new releases since 2016. Ideal for simple cross-origin persistence without server-side setup. Minimal API, uses iframe or window messaging. Lightweight, no external dependencies.

npm install cross-domain-storage
INSTALL
IMPORT
SIG · CROSS-DOMAIN-STORA
C
cross-domain-storage
storagejavascriptv2.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CrossDomainStorage
import CrossDomainStorage from 'cross-domain-storage'
const CrossDomainStorage = require('cross-domain-storage')
ESM default export. CJS requires default import workaround: const CrossDomainStorage = require('cross-domain-storage').default.
CrossDomainStorage
import CrossDomainStorage from 'cross-domain-storage'
import { CrossDomainStorage } from 'cross-domain-storage'
Named export does not exist; only default export.
CrossDomainStorage
const CrossDomainStorage = require('cross-domain-storage').default || require('cross-domain-storage')
const CrossDomainStorage = require('cross-domain-storage')
CJS require returns an object with default property in ESM interop. Older bundlers may need the fallback.

Creates an iframe-based cross-domain storage, sets a key with TTL, and retrieves it on connection.

import CrossDomainStorage from 'cross-domain-storage'; const storage = new CrossDomainStorage({ type: 'iframe', origin: 'https://parent.example.com', path: '/cross-domain-storage.html', }); storage.on('connected', () => { storage.set('key', { value: 'test', ttl: 3600 }); storage.get('key', (err, data) => { if (err) console.error(err); else console.log('Retrieved:', data); }); }); storage.on('error', console.error);
Debug
Known issues
gotchaThe 'origin' must exactly match the target window origin, including protocol and port.
fix
Ensure origin string matches parent window (e.g., 'https://example.com:443').
affects: >=0.0.0
gotchaData is not encrypted; sensitive values are transmitted via postMessage in plaintext.
fix
Encrypt data manually before setting, or use a secure origin with HTTPS.
affects: >=0.0.0
gotchaThe library has no built-in timeout for get requests; if the target window doesn't respond, the callback never fires, causing silent failures.
fix
Implement a manual timeout wrapper around the get method.
affects: >=0.0.0
gotchaThe 'path' option must point to an HTML file that includes the library's helper script on the target origin.
fix
Place cross-domain-storage.html (from /dist) on the remote origin, or host it yourself.
affects: >=0.0.0
Errors
Common errors & fixes
Uncaught DOMException: Blocked a frame with origin "http://localhost:3000" from accessing a cross-origin frame.
The origin option does not match the actual origin of the target window.
fix
Check that the origin includes the correct protocol, host, and port (e.g., 'http://localhost:8080').
TypeError: CrossDomainStorage is not a constructor
Default import in ESM or missing .default in CJS.
fix
Use import CrossDomainStorage from 'cross-domain-storage' (ESM) or const CrossDomainStorage = require('cross-domain-storage').default (CJS).
Upgrade
Version history
2.0.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
16
Resources