{"id":13396846,"url":"https://github.com/krakenjs/cross-domain-utils","last_synced_at":"2025-04-04T22:07:39.090Z","repository":{"id":41198743,"uuid":"93441537","full_name":"krakenjs/cross-domain-utils","owner":"krakenjs","description":"Cross Domain utilities","archived":false,"fork":false,"pushed_at":"2023-06-12T20:27:18.000Z","size":554,"stargazers_count":131,"open_issues_count":3,"forks_count":18,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-10-13T15:14:54.425Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krakenjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-06-05T20:00:33.000Z","updated_at":"2024-08-13T15:20:37.000Z","dependencies_parsed_at":"2024-01-15T22:42:59.720Z","dependency_job_id":"677c684d-03f9-44ba-ac98-f63f2d4b0038","html_url":"https://github.com/krakenjs/cross-domain-utils","commit_stats":{"total_commits":286,"total_committers":17,"mean_commits":"16.823529411764707","dds":"0.34615384615384615","last_synced_commit":"98333d0bbe5ec97050886313b623cb61c5ab98d6"},"previous_names":[],"tags_count":69,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakenjs%2Fcross-domain-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakenjs%2Fcross-domain-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakenjs%2Fcross-domain-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakenjs%2Fcross-domain-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krakenjs","download_url":"https://codeload.github.com/krakenjs/cross-domain-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256112,"owners_count":20909240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-07-30T18:01:04.659Z","updated_at":"2025-04-04T22:07:39.072Z","avatar_url":"https://github.com/krakenjs.png","language":"JavaScript","funding_links":[],"categories":["Packages","JavaScript"],"sub_categories":[],"readme":"## Cross Domain Utils\n\n[![build status][build-badge]][build]\n[![code coverage][coverage-badge]][coverage]\n[![npm version][version-badge]][package]\n[![apache license][license-badge]][license]\n\n[build-badge]: https://img.shields.io/github/actions/workflow/status/krakenjs/cross-domain-utils/main.yml?branch=main\u0026logo=github\u0026style=flat-square\n[build]: https://github.com/krakenjs/cross-domain-utils/actions/workflows/main.yml?query=workflow:build\n[coverage-badge]: https://img.shields.io/codecov/c/github/krakenjs/cross-domain-utils.svg?style=flat-square\n[coverage]: https://codecov.io/github/krakenjs/cross-domain-utils\n[version-badge]: https://img.shields.io/npm/v/@krakenjs/cross-domain-utils.svg?style=flat-square\n[package]: https://www.npmjs.com/package/@krakenjs/cross-domain-utils\n[license-badge]: https://img.shields.io/npm/l/@krakenjs/cross-domain-utils.svg?style=flat-square\n[license]: https://github.com/krakenjs/cross-domain-utils/blob/main/LICENSE\n\nA set of utilities for dealing with cross-domain windows\n\n## Installation\n\nAs of version 3 this package will be published under the `@krakenjs` scope.\n\n```\nnpm install @krakenjs/cross-domain-utils\n```\n\n## Public methods\n\n### `getDomain(win : Window) =\u003e string`\n\nGet the full domain of the specified window, as a string.\n\n- `win` must be a window on the same domain as the current window, or an exception will be raised\n- This can be overridden / mocked by setting `win.mockDomain = 'mock://some-domain.com';`. `mock://` is required to ensure the window can not spoof actual `http://` or `https://` domains\n\n### `getDomainFromUrl(url : string) =\u003e string`\n\nGet the full domain from the specified url, as a string.\n\n- it will try to extract the domain from the url string if it starts with well known protocols (`http://`, `https://`, `file://`, and additionally `mock://` urls)\n- if url string does not contain a known protocol, it will try to extract the domain calling `getDomain` using the current window as input\n\n### `getActualDomain(win : Window) =\u003e string`\n\nSame as `getDomain` but overriding / mocking is disabled. it will return the real full domain of the specified window.\n\n### `isBlankDomain(win : Window) =\u003e boolean`\n\nReturns if the domain for the specified window is blank, or `about:blank`\n\n- `win` must be a window on the same domain as the current window, or an exception will be raised\n- `win` may be a window or iframe that has been newly opened by the current window\n\n### `isSameDomain(win : Window) =\u003e boolean`\n\nReturns if the specified window is on the same domain as the current window.\n\n- Does so without raising any errors or console warnings, even in Safari where wrapping the check `try/catch` still raises a console warning.\n\n### `getParent(win : Window) =\u003e ?Window`\n\nGets the parent of the specified window, if the window has a parent.\n\n- Only returns the parent of iframes\n- Returns void if the window is the top-level window\n\n### `getOpener(win : Window) =\u003e ?Window`\n\nGets the opener of the specified window, if the window has an opener.\n\n- Only returns the opener of windows opened with `window.open`\n- Returns void if the window is the top-level window\n\n### `getParents(win : Window) =\u003e Array\u003cWindow\u003e`\n\nGets all of the hierarchical parents of the specified window.\n\n- Only returns the parents of iframes\n- Returns a blank array if the window is the top-level window\n\n### `isAncestorParent(ancestor : Window, win : Window) =\u003e boolean`\n\nReturns true if the `ancestor` is a direct or non-direct parent of the specified window.\n\n### `getFrames(win : Window) =\u003e Array\u003cWindow\u003e`\n\nReturns an array of all direct child frames found in a given window.\n\n- Only returns direct children\n\n### `getAllChildFrames(win : Window) =\u003e Array\u003cWindow\u003e`\n\nReturns an array of all recursive child frames found in a given window, and in the child-frames of that window.\n\n- Recursively searches for all direct and indirect children\n\n### `getTop(win : Window) =\u003e Window`\n\nGets the top-level parent of the specified window.\n\n### `getAllFramesInWindow(win : Window) =\u003e Array\u003cWindow\u003e`\n\nReturns an array of all recursive child frames found in a given window, and in the child-frames of that window, including the specified window.\n\n- Recursively searches for all direct and indirect children\n\n### `isTop(win : Window) =\u003e boolean`\n\nReturns true if the specified window is the top level window, without any parents.\n\n### `isFrameWindowClosed(frame : HTMLIFrameElement) =\u003e boolean`\n\nReturns true if the window attached to an iframe element is closed, by checking if the frame is still attached to an open document.\n\n- Prefer `isWindowClosed` when possible\n\n### `isWindowClosed(win : Window) =\u003e boolean`\n\nReturns true if a window has been closed\n\n- In IE/Edge, this check is not 100% reliable for frame windows where the frame has been removed from the DOM. Such window objects give no indication that they are closed.\n\n### `getUserAgent(win : Window) =\u003e string`\n\nGets the user agent for the specified window\n\n- Window must be on the same domain as the current window\n- Uses `win.navigator.mockUserAgent` if specified, to allow for mocking / tests.\n\n### `getFrameByName(win : Window, name : string) =\u003e ?Window`\n\nGets a frame window with the given name, if it exists as a child of the specified window.\n\n### `findChildFrameByName(win : Window, name : string) =\u003e ?Window`\n\nRecursively searches for a given frame window inside the children specified window.\n\n### `findFrameByName(win : Window, name : string) =\u003e ?Window`\n\nRecursively searches for a given frame window inside the entire frame hierarchy of the specified window.\n\n- Searches both the children and the parent windows recursively for the frame.\n\n### `isParent(parent : Window, child : Window) =\u003e boolean`\n\nReturns true if the specified parent window is the parent of the specified child window.\n\n### `isOpener(opener : Window, child : Window) =\u003e boolean`\n\nReturns true if the specified opener window is the opener of the specified child window.\n\n### `getAncestor(win : Window) =\u003e ?Window`\n\nGets either the parent or the opener of the specified window, if either is present.\n\n### `getAncestors(win : Window) =\u003e Array\u003cWindow\u003e`\n\nRecursively gets either the parent or the opener of the specified window, if either is present, and returns an array of the entire ancestor hierarchy.\n\n### `isAncestor(ancestor : Window, child : Window) =\u003e boolean`\n\nReturns true if the specified ancestor window is the parent or the opener of the specified child window.\n\n### `isPopup(win : Window) =\u003e boolean`\n\nReturns true if the specified window has been opened with `window.open` (i.e. if it is a popup window)\n\n### `isIframe(win : Window) =\u003e boolean`\n\nReturns true if the specified window has been opened as an iframe.\n\n### `getDistanceFromTop(win : Window) =\u003e number`\n\nGets the numerical distance from the specified window to the top level window in that window's hierarchy.\n\n- If the specified window is at the top, this will return 0.\n\n### `getNthParent(win : Window, n : number) =\u003e ?Window`\n\nGets the window `n` levels up from the specified window, if it exists.\n\n### `isSameTopWindow(win1 : window, win2 : Window) =\u003e boolean`\n\nReturns true if the windows are in the same hierarchy, with the same top level window\n\n- Will return false if one of the windows is a popup and the other window is not a frame inside that popup.\n\n### `isWindow(obj : Window) =\u003e boolean`\n\nReturns true if the specified object is a window instance\n\n### `onCloseWindow(win : Window, callback : Function, interval : number) =\u003e { cancel : Function }`\n\nCalls the callback when the specified window closes, with checks running on the specified interval.\n\n- Returns a listener object with a `.cancel()` method, to stop the loop\n\n### `matchDomain(pattern : (string | RegExp | Array\u003cstring\u003e), domain : string) =\u003e boolean`\n\nReturns true if the specified domain matches the pattern. The pattern can be one of:\n\n- A literal string\n- A regular expression\n- An array of possible domains as strings\n\n# Tasks\n\nAll of the tasks are listed in the package.json file under the scripts section\n\n| Command       |               Description                |\n| ------------- | :--------------------------------------: |\n| npm run build |          Builds the dist files           |\n| npm test      | Runs the test suite. Lint + Type + Karma |\n\n# Debugging\n\nRun the debug task and pass the next tasks as argument.\n\n```\nnpm run debug -- npm run build\nnpm run debug -- npm test\nnpm run debug -- npm run karma -- --browsers=Chrome\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakenjs%2Fcross-domain-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrakenjs%2Fcross-domain-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakenjs%2Fcross-domain-utils/lists"}