Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [] Add origins for editor postMessage #312

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/live-preview-sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export const MAX_DEPTH = 10;

export const LIVE_PREVIEW_EDITOR_SOURCE = 'live-preview-editor' as const;
export const LIVE_PREVIEW_SDK_SOURCE = 'live-preview-sdk' as const;

export const CONTENTFUL_ORIGINS = ['https://app.contentful.com', 'https://app.eu.contentful.com'];
9 changes: 4 additions & 5 deletions packages/live-preview-sdk/src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as packageJson from '../../package.json';
import { LIVE_PREVIEW_SDK_SOURCE } from '../constants';
import { CONTENTFUL_ORIGINS, LIVE_PREVIEW_SDK_SOURCE } from '../constants';
import { PostMessageMethods } from '../messages';
import type { EditorMessage, MessageFromSDK } from '../messages';
import { debug } from './debug';
Expand All @@ -20,10 +20,9 @@ export function sendMessageToEditor(method: PostMessageMethods, data: EditorMess

debug.log('Send message', message);

window.top?.postMessage(
message,
'*' // TODO: check if there is any security risk with this
);
CONTENTFUL_ORIGINS.forEach((origin) => {
window.top?.postMessage(message, origin);
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down