diff --git a/client/coral-embed-stream/src/index.js b/client/coral-embed-stream/src/index.js index 2226f46ab..45fc4c034 100644 --- a/client/coral-embed-stream/src/index.js +++ b/client/coral-embed-stream/src/index.js @@ -14,16 +14,8 @@ import reducers from './reducers'; import TalkProvider from 'coral-framework/components/TalkProvider'; import pluginsConfig from 'pluginsConfig'; -function inIframe() { - try { - return window.self !== window.top; - } catch (e) { - return true; - } -} - // TODO: move init code into `bootstrap` service after auth has been refactored. -function preInit({ store, pym }) { +function preInit({ store, pym, inIframe }) { // TODO: This is popup specific code and needs to be refactored. if (!inIframe()) { store.dispatch(addExternalConfig({})); diff --git a/client/coral-framework/services/bootstrap.js b/client/coral-framework/services/bootstrap.js index 416666e89..4d811a870 100644 --- a/client/coral-framework/services/bootstrap.js +++ b/client/coral-framework/services/bootstrap.js @@ -43,6 +43,14 @@ const getAuthToken = (store, storage) => { return null; }; +function areWeInIframe() { + try { + return window.self !== window.top; + } catch (e) { + return true; + } +} + /** * createContext setups and returns Talk dependencies that should be * passed to `TalkProvider`. @@ -63,11 +71,16 @@ export async function createContext({ preInit, init = noop, } = {}) { + const inIframe = areWeInIframe(); const eventEmitter = new EventEmitter({ wildcard: true }); const localStorage = createStorage('localStorage'); const sessionStorage = createStorage('sessionStorage'); - const pymLocalStorage = createPymStorage(pym, 'localStorage'); - const pymSessionStorage = createPymStorage(pym, 'sessionStorage'); + const pymLocalStorage = inIframe + ? createPymStorage(pym, 'localStorage') + : localStorage; + const pymSessionStorage = inIframe + ? createPymStorage(pym, 'sessionStorage') + : localStorage; const history = createHistory(BASE_PATH); const introspection = createIntrospection(introspectionData); let store = null; @@ -124,6 +137,7 @@ export async function createContext({ introspection, pymLocalStorage, pymSessionStorage, + inIframe, }; // Load framework fragments.