Skip to content

Commit 73b29c9

Browse files
committed
fix(vscode-theming): update postMessage to use resolved parent origin
1 parent 2a44175 commit 73b29c9

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

apps/web/src/common/utils/vscode-bridge.utils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@ type AnyHandler = (payload: unknown) => void;
1313

1414
const handlers = new Map<string, Set<AnyHandler>>();
1515

16+
const resolveParentOrigin = (): string => {
17+
if (!document.referrer) return '*';
18+
try {
19+
return new URL(document.referrer).origin;
20+
} catch {
21+
return '*';
22+
}
23+
};
24+
25+
const parentOrigin = resolveParentOrigin();
26+
1627
export const sendToExtension = (msg: AppMessage): void => {
1728
if (!isVSCodeEnv()) return;
18-
window.parent.postMessage(msg, '*');
29+
window.parent.postMessage(msg, parentOrigin);
1930
};
2031

2132
export const onMessage = <T extends HostMessage['type']>(

0 commit comments

Comments
 (0)