Registry / storage / xdlocalstorage

xdlocalstorage

JSON →
library2.0.5jsnpmunverified

Cross Domain Local Storage is a lightweight JavaScript library that implements the standard localStorage interface using iframe postMessage communication to share data across subdomains. Current version is 2.0.5. It provides async API with callbacks or promises (v2+), and supports Angular integration. Unlike cookies, it does not send data to the server on every request. However, note that Safari 7+ blocks third-party data, making the library unusable on that browser.

npm install xdlocalstorage
INSTALL
IMPORT
SIG · XDLOCALSTORAGE
X
xdlocalstorage
storagejavascriptv2.0.5
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.

xdLocalStorage
import xdLocalStorage from 'xdlocalstorage'
const xdLocalStorage = require('xdlocalstorage')
The package is primarily browser-oriented and expects a global script rather than ES modules. However, if imported via bundler, use default import.
init
xdLocalStorage.init({ iframeUrl: '...' })
init({ iframeUrl: '...' })
init is a method on the xdLocalStorage object, not a standalone function.
setItem
xdLocalStorage.setItem('key', 'value', callback)
xdLocalStorage.setItem('key', 'value')
Callback is optional in v2+ with promises, but originally required for success notification.

Initializes cross-domain localStorage, sets and gets an item using callbacks.

// Ensure you have included xdLocalStorage.min.js script in your HTML // Initialize with the URL of the iframe page (hosted on the target domain) xdLocalStorage.init({ iframeUrl: 'https://otherdomain.com/iframe.html', initCallback: function() { console.log('Ready'); } }); // Store a value xdLocalStorage.setItem('user', 'John', function(data) { if (data.success) console.log('Stored'); }); // Retrieve a value xdLocalStorage.getItem('user', function(data) { if (data.success) console.log(data.value); });
Debug
Known issues
gotchaSafari 7+ blocks third-party localStorage, making cross-domain storage impossible on that browser.
fix
Consider using server-side storage or cookies for cross-domain needs on Safari.
affects: >=0.1
breakingVersion 2.0.0 changed the API to support promises, which may break existing callback-only code.
fix
Update callbacks to use promise .then() or continue using callbacks as they are still supported.
affects: >=2.0.0
gotchaThe iframe page must include the xdLocalStoragePostMessageApi.min.js script exactly as described.
fix
Ensure the iframe HTML includes the correct script tag for postMessage API.
affects: >=0.1
gotchaAll operations are asynchronous; the callback/promise must be used to get results.
fix
Always provide a callback or handle promise for read/write operations.
affects: >=0.1
Errors
Common errors & fixes
xdLocalStorage is not defined
The xdLocalStorage.min.js script was not loaded before calling its methods.
fix
Include the script tag <script src='path/to/xdLocalStorage.min.js'></script> before any xdLocalStorage calls.
Uncaught DOMException: Blocked a frame with origin "http://example.com" from accessing a cross-origin frame.
The iframe page is not hosted on the correct domain or CORS is misconfigured.
fix
Ensure the iframe URL points to a page on the target domain and that both pages use the same protocol (http/https).
init is not a function
The xdLocalStorage object was not properly initialized or the wrong script was included (e.g., PostMessage API on client page).
fix
Ensure you include xdLocalStorage.min.js (not the PostMessage API script) on the client page and call init with correct config.
Upgrade
Version history
2.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
46 hits · last 30 days
node
42
OpenAI (training)
1
Resources
xdlocalstorage — npm install xdlocalstorage · libregistry