Cross Domain Utils is a JavaScript utility library designed to simplify and secure interactions between browser windows across different domains. It provides a robust set of functions for safely querying window properties like domain, parent, opener, and child frames, while mitigating common browser security restrictions (e.g., `SecurityError` exceptions). The current stable version for the unscoped `cross-domain-utils` package is 2.0.38, published approximately four years ago. For versions 3.0.0 and above, the package has been migrated to the `@krakenjs/cross-domain-utils` scope. This library is particularly useful for complex iframe communication, secure window management, and scenarios requiring precise control over cross-origin window relationships without triggering browser errors or warnings.
npm install cross-domain-utilsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates key utilities like `getDomain`, `isSameDomain`, `getTop`, `getParent`, and `isWindowClosed` in both same-domain and simulated cross-domain scenarios, highlighting how the library handles security boundaries.
Update your `package.json` dependency and all import statements from `import { ... } from 'cross-domain-utils'` to `import { ... } from '@krakenjs/cross-domain-utils'`.Always use `isSameDomain(win)` before attempting to call domain-sensitive functions like `getDomain(win)` if the origin of `win` is uncertain. For cross-origin windows, some information is inherently inaccessible due to browser security policies.
Be aware of this limitation, especially when targeting older IE/Edge environments. Consider alternative or supplementary checks for iframe removal from the DOM for critical scenarios.
Only use `mockDomain` or `mockUserAgent` within test environments to simulate different window origins or user agents. Never use these properties in live application code.
Instead of direct access, use `cross-domain-utils` methods like `isSameDomain(win)`, `isWindowClosed(win)`, `getTop(win)` which are designed to handle cross-origin security boundaries gracefully.
Before calling `getDomain(win)`, ensure that `isSameDomain(win)` returns `true`. If `isSameDomain(win)` is `false`, you cannot retrieve the domain for security reasons unless the library provides a specific, safe cross-origin method (which `getDomain` does not for direct access).
No dependency data recorded yet.