UNPKG

912 BJavaScriptView Raw
1// Load in our dependencies
2var ContextKarma = require('./karma')
3
4// Resolve our parent window
5var parentWindow = window.opener || window.parent
6
7// Define a remote call method for Karma
8var callParentKarmaMethod = ContextKarma.getDirectCallParentKarmaMethod(parentWindow)
9
10// If we don't have access to the window, then use `postMessage`
11// DEV: In Electron, we don't have access to the parent window due to it being in a separate process
12// DEV: We avoid using this in Internet Explorer as they only support strings
13// http://caniuse.com/#search=postmessage
14var haveParentAccess = false
15try { haveParentAccess = !!parentWindow.window } catch (err) { /* Ignore errors (likely permisison errors) */ }
16if (!haveParentAccess) {
17 callParentKarmaMethod = ContextKarma.getPostMessageCallParentKarmaMethod(parentWindow)
18}
19
20// Define a window-scoped Karma
21window.__karma__ = new ContextKarma(callParentKarmaMethod)