Compare commits
6 Commits
252bba2cdb
...
2e2754a41f
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2e2754a41f | ||
![]() |
9d00695be8 | ||
![]() |
8c0f2f8018 | ||
![]() |
bad6385270 | ||
![]() |
26edba3504 | ||
![]() |
bd4c9205d9 |
@ -12,6 +12,9 @@ function Iframe({ showIframe = false }: IframeProps) {
|
|||||||
if (iframeRef.current) {
|
if (iframeRef.current) {
|
||||||
IframeReference.setIframe(iframeRef.current);
|
IframeReference.setIframe(iframeRef.current);
|
||||||
}
|
}
|
||||||
|
return () => {
|
||||||
|
IframeReference.setIframe(null);
|
||||||
|
};
|
||||||
}, [iframeRef.current]);
|
}, [iframeRef.current]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -5,11 +5,6 @@ export default class IframeReference {
|
|||||||
private constructor() { }
|
private constructor() { }
|
||||||
|
|
||||||
public static setTargetOrigin(targetOrigin: string): void {
|
public static setTargetOrigin(targetOrigin: string): void {
|
||||||
if (this.targetOrigin) {
|
|
||||||
console.debug("targetOrigin is already set");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new URL(targetOrigin);
|
new URL(targetOrigin);
|
||||||
this.targetOrigin = targetOrigin;
|
this.targetOrigin = targetOrigin;
|
||||||
|
@ -809,10 +809,17 @@ export default class MessageBus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const iframe = IframeReference.getIframe();
|
||||||
|
|
||||||
|
if (event.source !== iframe.contentWindow) {
|
||||||
|
console.error('[MessageBus] handleMessage: source not match');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const targetOrigin = IframeReference.getTargetOrigin();
|
const targetOrigin = IframeReference.getTargetOrigin();
|
||||||
|
|
||||||
if (event.origin !== targetOrigin) {
|
if (event.origin !== targetOrigin) {
|
||||||
throw new Error(`origin don't match: expected ${targetOrigin}, got ${event.origin} with type ${event.data.type}`);
|
throw new Error('origin not match');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event.data || typeof event.data !== 'object') {
|
if (!event.data || typeof event.data !== 'object') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user