From 86bc0a29320cf7fef513678d178ff5ac60b25477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Tue, 7 Jan 2025 13:53:04 +0100 Subject: [PATCH] fix: avoid postMessage warnings in console MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- src/entry.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/entry.ts b/src/entry.ts index 6643eb1..e884a64 100644 --- a/src/entry.ts +++ b/src/entry.ts @@ -11,6 +11,7 @@ interface AppState { config: { canFixError: boolean }, + ancestorOrigin: string, } // Page is loaded directly @@ -26,12 +27,18 @@ const ALLOWED_ORIGINS = (import.meta.env.VITE_ALLOWED_FRAME_ANCESTORS ?? '').spl }, theme: 'light', fullscreen: false, + ancestorOrigin: ALLOWED_ORIGINS[0], }; let app: any; async function updateState(stateChange: Partial) { const oldState = { ...state }; + + // validate ancestorOrigin + if(!ALLOWED_ORIGINS.includes(stateChange.ancestorOrigin)) stateChange.ancestorOrigin = undefined; + + // update state state = { ...state, ...stateChange }; // set fullscreen @@ -86,11 +93,11 @@ const ALLOWED_ORIGINS = (import.meta.env.VITE_ALLOWED_FRAME_ANCESTORS ?? '').spl const data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data; switch (data.type) { case 'bee:ready': - ALLOWED_ORIGINS.forEach((origin: string) => parent.postMessage({ type: 'bee:ready' }, origin)) + parent.postMessage({ type: 'bee:ready' }, state.ancestorOrigin); return; case 'bee:request': - ALLOWED_ORIGINS.forEach((origin: string) => parent.postMessage(data, origin)); + parent.postMessage(data, state.ancestorOrigin); return; default: