|
@@ -22,10 +22,11 @@
|
|
|
|
|
|
|
|
this.frameTree = this.frameTree || (() => {
|
|
this.frameTree = this.frameTree || (() => {
|
|
|
|
|
|
|
|
- const MESSAGE_PREFIX = "__frameTree__";
|
|
|
|
|
|
|
+ const MESSAGE_PREFIX = "__frameTree__::";
|
|
|
const FRAMES_CSS_SELECTOR = "iframe, frame, object[type=\"text/html\"][data]";
|
|
const FRAMES_CSS_SELECTOR = "iframe, frame, object[type=\"text/html\"][data]";
|
|
|
const INIT_REQUEST_MESSAGE = "initRequest";
|
|
const INIT_REQUEST_MESSAGE = "initRequest";
|
|
|
const INIT_RESPONSE_MESSAGE = "initResponse";
|
|
const INIT_RESPONSE_MESSAGE = "initResponse";
|
|
|
|
|
+ const TARGET_ORIGIN = "*";
|
|
|
const TIMEOUT_INIT_REQUEST_MESSAGE = 500;
|
|
const TIMEOUT_INIT_REQUEST_MESSAGE = 500;
|
|
|
const TOP_WINDOW_ID = "0";
|
|
const TOP_WINDOW_ID = "0";
|
|
|
const TOP_WINDOW = window == top;
|
|
const TOP_WINDOW = window == top;
|
|
@@ -36,8 +37,8 @@ this.frameTree = this.frameTree || (() => {
|
|
|
windowId = TOP_WINDOW_ID;
|
|
windowId = TOP_WINDOW_ID;
|
|
|
}
|
|
}
|
|
|
addEventListener("message", event => {
|
|
addEventListener("message", event => {
|
|
|
- if (typeof event.data == "string" && event.data.startsWith(MESSAGE_PREFIX + "::")) {
|
|
|
|
|
- const message = JSON.parse(event.data.substring(MESSAGE_PREFIX.length + 2));
|
|
|
|
|
|
|
+ if (typeof event.data == "string" && event.data.startsWith(MESSAGE_PREFIX)) {
|
|
|
|
|
+ const message = JSON.parse(event.data.substring(MESSAGE_PREFIX.length));
|
|
|
if (message.method == INIT_REQUEST_MESSAGE) {
|
|
if (message.method == INIT_REQUEST_MESSAGE) {
|
|
|
initRequest(message);
|
|
initRequest(message);
|
|
|
} else if (message.method == INIT_RESPONSE_MESSAGE) {
|
|
} else if (message.method == INIT_RESPONSE_MESSAGE) {
|
|
@@ -130,12 +131,12 @@ this.frameTree = this.frameTree || (() => {
|
|
|
framesData.push({ windowId });
|
|
framesData.push({ windowId });
|
|
|
if (!frameElement.contentDocument) {
|
|
if (!frameElement.contentDocument) {
|
|
|
try {
|
|
try {
|
|
|
- frameElement.contentWindow.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: INIT_REQUEST_MESSAGE, windowId, sessionId, options }), "*");
|
|
|
|
|
|
|
+ frameElement.contentWindow.postMessage(MESSAGE_PREFIX + JSON.stringify({ method: INIT_REQUEST_MESSAGE, windowId, sessionId, options }), TARGET_ORIGIN);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
/* ignored */
|
|
/* ignored */
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- timeout.set(() => sendInitResponse({ framesData: [{ windowId, processed: true, timeout: true }], windowId, sessionId }, "*"), TIMEOUT_INIT_REQUEST_MESSAGE);
|
|
|
|
|
|
|
+ timeout.set(() => sendInitResponse({ framesData: [{ windowId, processed: true, timeout: true }], windowId, sessionId }), TIMEOUT_INIT_REQUEST_MESSAGE);
|
|
|
});
|
|
});
|
|
|
sendInitResponse({ framesData, parentWindowId, sessionId });
|
|
sendInitResponse({ framesData, parentWindowId, sessionId });
|
|
|
}
|
|
}
|
|
@@ -169,7 +170,7 @@ this.frameTree = this.frameTree || (() => {
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
const channel = new MessageChannel();
|
|
const channel = new MessageChannel();
|
|
|
const port = channel.port1;
|
|
const port = channel.port1;
|
|
|
- top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: INIT_RESPONSE_MESSAGE }), "*", [channel.port2]);
|
|
|
|
|
|
|
+ top.postMessage(MESSAGE_PREFIX + JSON.stringify({ method: INIT_RESPONSE_MESSAGE }), TARGET_ORIGIN, [channel.port2]);
|
|
|
port.postMessage(message);
|
|
port.postMessage(message);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|