Skip to content

Commit

Permalink
ADD document location
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Mar 30, 2020
1 parent f810a18 commit 7e18c2e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/channel-postmessage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class PostmsgTransport {
this.flush();
}

frames.forEach(f => {
frames.forEach((f) => {
try {
f.postMessage(data, '*');
} catch (e) {
Expand All @@ -99,10 +99,8 @@ export class PostmsgTransport {
private flush(): void {
const { buffer } = this;
this.buffer = [];
buffer.forEach(item => {
this.send(item.event)
.then(item.resolve)
.catch(item.reject);
buffer.forEach((item) => {
this.send(item.event).then(item.resolve).catch(item.reject);
});
}

Expand All @@ -113,14 +111,14 @@ export class PostmsgTransport {
];

const list = nodes
.filter(e => {
.filter((e) => {
try {
return !!e.contentWindow && e.dataset.isStorybook !== undefined && e.id === target;
} catch (er) {
return false;
}
})
.map(e => e.contentWindow);
.map((e) => e.contentWindow);

return list.length ? list : this.getCurrentFrames();
}
Expand All @@ -136,7 +134,7 @@ export class PostmsgTransport {
const list: HTMLIFrameElement[] = [
...document.querySelectorAll('[data-is-storybook="true"]'),
];
return list.map(e => e.contentWindow);
return list.map((e) => e.contentWindow);
}
if (window && window.parent) {
return [window.parent];
Expand All @@ -148,7 +146,7 @@ export class PostmsgTransport {
private getLocalFrame(): Window[] {
if (this.config.page === 'manager') {
const list: HTMLIFrameElement[] = [...document.querySelectorAll('#storybook-preview-iframe')];
return list.map(e => e.contentWindow);
return list.map((e) => e.contentWindow);
}
if (window && window.parent) {
return [window.parent];
Expand Down Expand Up @@ -201,7 +199,7 @@ const getEventSourceUrl = (event: MessageEvent) => {

// try to find the originating iframe by matching it's contentWindow
// This might not be cross-origin safe
const [frame, ...remainder] = frames.filter(element => {
const [frame, ...remainder] = frames.filter((element) => {
try {
return element.contentWindow === event.source;
} catch (err) {
Expand All @@ -226,7 +224,7 @@ const getEventSourceUrl = (event: MessageEvent) => {
}

const src = frame.getAttribute('src');
const { origin, pathname } = new URL(src);
const { origin, pathname } = new URL(src, document.location);
return origin + pathname;
};

Expand Down

0 comments on commit 7e18c2e

Please sign in to comment.