• Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cross Domain utilities

Cross Domain Utils

build status code coverage npm version apache license

A set of utilities for dealing with cross-domain windows

Installation

As of version 3 this package will be published under the @krakenjs scope.

npm install @krakenjs/cross-domain-utils

Public methods

getDomain(win : Window) => string

Get the full domain of the specified window, as a string.

  • win must be a window on the same domain as the current window, or an exception will be raised
  • 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

getDomainFromUrl(url : string) => string

Get the full domain from the specified url, as a string.

  • 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)
  • if url string does not contain a known protocol, it will try to extract the domain calling getDomain using the current window as input

getActualDomain(win : Window) => string

Same as getDomain but overriding / mocking is disabled. it will return the real full domain of the specified window.

isBlankDomain(win : Window) => boolean

Returns if the domain for the specified window is blank, or about:blank

  • win must be a window on the same domain as the current window, or an exception will be raised
  • win may be a window or iframe that has been newly opened by the current window

isSameDomain(win : Window) => boolean

Returns if the specified window is on the same domain as the current window.

  • Does so without raising any errors or console warnings, even in Safari where wrapping the check try/catch still raises a console warning.

getParent(win : Window) => ?Window

Gets the parent of the specified window, if the window has a parent.

  • Only returns the parent of iframes
  • Returns void if the window is the top-level window

getOpener(win : Window) => ?Window

Gets the opener of the specified window, if the window has an opener.

  • Only returns the opener of windows opened with window.open
  • Returns void if the window is the top-level window

getParents(win : Window) => Array<Window>

Gets all of the hierarchical parents of the specified window.

  • Only returns the parents of iframes
  • Returns a blank array if the window is the top-level window

isAncestorParent(ancestor : Window, win : Window) => boolean

Returns true if the ancestor is a direct or non-direct parent of the specified window.

getFrames(win : Window) => Array<Window>

Returns an array of all direct child frames found in a given window.

  • Only returns direct children

getAllChildFrames(win : Window) => Array<Window>

Returns an array of all recursive child frames found in a given window, and in the child-frames of that window.

  • Recursively searches for all direct and indirect children

getTop(win : Window) => Window

Gets the top-level parent of the specified window.

getAllFramesInWindow(win : Window) => Array<Window>

Returns an array of all recursive child frames found in a given window, and in the child-frames of that window, including the specified window.

  • Recursively searches for all direct and indirect children

isTop(win : Window) => boolean

Returns true if the specified window is the top level window, without any parents.

isFrameWindowClosed(frame : HTMLIFrameElement) => boolean

Returns true if the window attached to an iframe element is closed, by checking if the frame is still attached to an open document.

  • Prefer isWindowClosed when possible

isWindowClosed(win : Window) => boolean

Returns true if a window has been closed

  • 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.

getUserAgent(win : Window) => string

Gets the user agent for the specified window

  • Window must be on the same domain as the current window
  • Uses win.navigator.mockUserAgent if specified, to allow for mocking / tests.

getFrameByName(win : Window, name : string) => ?Window

Gets a frame window with the given name, if it exists as a child of the specified window.

findChildFrameByName(win : Window, name : string) => ?Window

Recursively searches for a given frame window inside the children specified window.

findFrameByName(win : Window, name : string) => ?Window

Recursively searches for a given frame window inside the entire frame hierarchy of the specified window.

  • Searches both the children and the parent windows recursively for the frame.

isParent(parent : Window, child : Window) => boolean

Returns true if the specified parent window is the parent of the specified child window.

isOpener(opener : Window, child : Window) => boolean

Returns true if the specified opener window is the opener of the specified child window.

getAncestor(win : Window) => ?Window

Gets either the parent or the opener of the specified window, if either is present.

getAncestors(win : Window) => Array<Window>

Recursively gets either the parent or the opener of the specified window, if either is present, and returns an array of the entire ancestor hierarchy.

isAncestor(ancestor : Window, child : Window) => boolean

Returns true if the specified ancestor window is the parent or the opener of the specified child window.

isPopup(win : Window) => boolean

Returns true if the specified window has been opened with window.open (i.e. if it is a popup window)

isIframe(win : Window) => boolean

Returns true if the specified window has been opened as an iframe.

getDistanceFromTop(win : Window) => number

Gets the numerical distance from the specified window to the top level window in that window's hierarchy.

  • If the specified window is at the top, this will return 0.

getNthParent(win : Window, n : number) => ?Window

Gets the window n levels up from the specified window, if it exists.

isSameTopWindow(win1 : window, win2 : Window) => boolean

Returns true if the windows are in the same hierarchy, with the same top level window

  • Will return false if one of the windows is a popup and the other window is not a frame inside that popup.

isWindow(obj : Window) => boolean

Returns true if the specified object is a window instance

onCloseWindow(win : Window, callback : Function, interval : number) => { cancel : Function }

Calls the callback when the specified window closes, with checks running on the specified interval.

  • Returns a listener object with a .cancel() method, to stop the loop

matchDomain(pattern : (string | RegExp | Array<string>), domain : string) => boolean

Returns true if the specified domain matches the pattern. The pattern can be one of:

  • A literal string
  • A regular expression
  • An array of possible domains as strings

Tasks

All of the tasks are listed in the package.json file under the scripts section

Command Description
npm run build Builds the dist files
npm test Runs the test suite. Lint + Type + Karma

Debugging

Run the debug task and pass the next tasks as argument.

npm run debug -- npm run build
npm run debug -- npm test
npm run debug -- npm run karma -- --browsers=Chrome

More Repositories

1

kraken-js

An express-based Node.js web application bootstrapping module.
JavaScript
4,948
star
2

zoid

Cross domain components
JavaScript
2,008
star
3

lusca

Application security for express apps.
JavaScript
1,787
star
4

post-robot

Cross domain post-messaging on the client side using a simple listener/client pattern.
JavaScript
734
star
5

kappa

A hierarchical npm-registry proxy
JavaScript
557
star
6

swaggerize-express

Design-driven apis with swagger 2.0 and express.
JavaScript
354
star
7

grumbler

A template for writing distributable front-end javascript modules.
JavaScript
292
star
8

beaver-logger

Client-side logging w/ super powers
JavaScript
252
star
9

hapi-openapi

Build design-driven apis with OpenAPI (formerly swagger) 2.0 and hapi.
JavaScript
210
star
10

jsx-pragmatic

Build JSX structures, then decide at runtime which pragma you want to use to render them.
JavaScript
188
star
11

express-enrouten

An express route initialization and configuration module.
JavaScript
172
star
12

levee

A circuit-breaker pattern implementation with fallback support.
JavaScript
171
star
13

fetch-robot

Proxy fetch through an iframe
JavaScript
157
star
14

makara

An internationalization module for kraken and express
JavaScript
135
star
15

adaro

A Dust.js view renderer for express
JavaScript
127
star
16

kraken-example-with-shoppingcart

An example Kraken app showing off a shopping cart
JavaScript
116
star
17

generator-kraken

Yeoman generator for kraken.js apps
JavaScript
110
star
18

jwt-csrf

Stateless CSRF protection using jsonwebtoken (JWT)
JavaScript
108
star
19

shush

A simple module for reading JSON files that may have comments.
JavaScript
92
star
20

meddleware

Middleware configuration for express.
JavaScript
88
star
21

generator-swaggerize

Yeoman generator for design-driven apis with swagger 2.0 and krakenjs/swaggerize tools.
JavaScript
70
star
22

confit

Environment-aware configuration.
JavaScript
61
star
23

zoid-demo

A clonable demo project for xcomponent
JavaScript
61
star
24

swaggerize-routes

Swagger document driven route builder.
JavaScript
58
star
25

zalgo-promise

Release zalgo with synchronous promises
JavaScript
57
star
26

shortstop

Enables use of protocols in configuration.
JavaScript
55
star
27

kraken-example-with-passport

An example integrating kraken with passport authentication
JavaScript
53
star
28

caller

A node module for enabling a module to determine its caller.
JavaScript
47
star
29

nemo

node.js selenium-webdriver/mocha based combined testing framework
JavaScript
43
star
30

kraken-devtools

Development-time tools for kraken.js applications.
JavaScript
40
star
31

cross-domain-safe-weakmap

Cross-domain safe WeakMap shim
JavaScript
33
star
32

grabthar

Hot install and activation of npm modules
JavaScript
23
star
33

karka

A simple rule parser
JavaScript
21
star
34

belter

Miscellaneous browser utilities
JavaScript
17
star
35

good-influxdb

HapiJS good-reporter for use with InfluxDb
JavaScript
16
star
36

angular-remove-di-loaders

Webpack loaders to remove Angular DI (Dependency Injection)
JavaScript
16
star
37

freshy

An (admittedly naΓ―ve) node module (un|re)loader/refreshener.
JavaScript
15
star
38

endgame

A tiny module for ensuring uncaught exceptions are handled in Node.js
JavaScript
15
star
39

shortstop-handlers

Common protocol handlers for use with the shortstop node module.
JavaScript
15
star
40

passport-saml-encrypted

A strategy for Passport authentication that supports encrypted SAML responses
JavaScript
14
star
41

pine

A logging wrapper for winston.
JavaScript
14
star
42

react-redux-krakenjs-swaggerize-express

React client app, redux stage management, passport oauth2, paypal rest api and swagger based krakenjs node.js server
JavaScript
14
star
43

spud

A content store parser, reading a java .properties-like format
JavaScript
14
star
44

kraken-example-with-i18n

An example Kraken app showing off internationalization support
JavaScript
11
star
45

kraken-example-with-specialization

An example Kraken app showing off template specialization features.
JavaScript
11
star
46

bundalo

Manage localized sets of content files (be they property/json/etc) which may require rendering with data models
JavaScript
10
star
47

engine-munger

A helper module to insert specialization and i18n in the render workflow
JavaScript
10
star
48

memcookies

Persist cookies on the client-side, useful for supporting cookies disabled browsers
JavaScript
9
star
49

subprocess-robot

Create processes, process pools, and message between processes
JavaScript
8
star
50

grumbler-scripts

Build scripts for grumbler modules
JavaScript
6
star
51

universal-serialize

Universal serializer allowing for custom types
JavaScript
5
star
52

reverend

DEPRECATED: Merge an express-style path string with data to create a valid path.
JavaScript
5
star
53

sync-browser-mocks

Synchronous browser mocks for testing
JavaScript
4
star
54

webpack-mem-compile

Compile webpack to and from memory
TypeScript
3
star
55

hotware

JavaScript
3
star
56

localizr

A library and tool to apply localization to dust templates before rendering
JavaScript
3
star
57

neff

nconf & express based feature flags
JavaScript
3
star
58

krakenjs.github.io

Source for the kraken website
JavaScript
3
star
59

construx

Compile-on-the-fly and other development tools for use when building express applications.
JavaScript
2
star
60

spundle

command line tool and library to package localization files as json
JavaScript
2
star
61

dust-makara-helpers

Server-side configuration of helpers for makara
JavaScript
2
star
62

nodejs_deployment

Design and architecture details of node.js deployment solutions
JavaScript
2
star
63

node-benchmarker

Runs benchmarks and publishes results
JavaScript
2
star
64

grabthar-release

Release scripts for grabthar modules
JavaScript
2
star
65

express-promisified

Express with promises
JavaScript
2
star
66

webpack-promise-shim-plugin

Plugin to shim in Promise polyfill into webpack core
JavaScript
2
star
67

file-resolver

Used in kraken based projects for resolving files given the locale , file name, and the file extension.
JavaScript
2
star
68

beaver-logger-ios

Beaver Logger client for iOS
Swift
2
star
69

anemone-machina

express view engine and browser renderer for React and react-router
JavaScript
1
star
70

findatag

A specialized tokenizer for finding dust-style tags ({@tagname [attributes]})
JavaScript
1
star
71

construx-webpack

web pack dev middleware for krakenjs
JavaScript
1
star
72

express-bcp47

Locale handling middleware for Express
JavaScript
1
star
73

dustjacket

Loader middleware for dustjs
JavaScript
1
star
74

strict-merge

Strict deep merge of objects
JavaScript
1
star
75

makara-languagepackpath

Middleware for exposing the path to a language pack to templates
JavaScript
1
star