mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-15 00:05:35 +08:00
CHANGE postmessage frame lookup
This commit is contained in:
parent
19c2420db8
commit
2752631f22
@ -170,7 +170,7 @@ export class PostmsgTransport {
|
||||
? `<span style="color: #FF4785">${event.type}</span>`
|
||||
: `<span style="color: #FFAE00">${event.type}</span>`;
|
||||
|
||||
event.source = source || getEventSourceUrl(rawEvent);
|
||||
event.source = source || getEventSourceUrl(rawEvent, this.getFrames());
|
||||
|
||||
if (!event.source) {
|
||||
logger.error(
|
||||
@ -194,9 +194,7 @@ export class PostmsgTransport {
|
||||
}
|
||||
}
|
||||
|
||||
const getEventSourceUrl = (event: MessageEvent) => {
|
||||
const frames: HTMLIFrameElement[] = [...document.getElementsByTagName('iframe')];
|
||||
|
||||
const getEventSourceUrl = (event: MessageEvent, frames: HTMLIFrameElement[]) => {
|
||||
// try to find the originating iframe by matching it's contentWindow
|
||||
// This might not be cross-origin safe
|
||||
const [frame, ...remainder] = frames.filter((element) => {
|
||||
@ -223,9 +221,13 @@ const getEventSourceUrl = (event: MessageEvent) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
const src = frame.getAttribute('src');
|
||||
const { origin, pathname } = new URL(src, document.location);
|
||||
return origin + pathname;
|
||||
if (frame) {
|
||||
const src = frame.getAttribute('src');
|
||||
const { origin, pathname } = new URL(src, document.location);
|
||||
return origin + pathname;
|
||||
}
|
||||
|
||||
return event.origin;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user