1 | // Load in our dependencies
|
2 | var ContextKarma = require('./karma')
|
3 |
|
4 | // Resolve our parent window
|
5 | var parentWindow = window.opener || window.parent
|
6 |
|
7 | // Define a remote call method for Karma
|
8 | var 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
|
14 | var haveParentAccess = false
|
15 | try { haveParentAccess = !!parentWindow.window } catch (err) { /* Ignore errors (likely permisison errors) */ }
|
16 | if (!haveParentAccess) {
|
17 | callParentKarmaMethod = ContextKarma.getPostMessageCallParentKarmaMethod(parentWindow)
|
18 | }
|
19 |
|
20 | // Define a window-scoped Karma
|
21 | window.__karma__ = new ContextKarma(callParentKarmaMethod)
|