Переглянути джерело

fixed issue where SingleFile could be stuck when trying to get frame contents

Former-commit-id: 2f5678cbd3cd29372fcfdea0f5d1c1dd35d237e8
Gildas 6 роки тому
батько
коміт
744babdf3c

+ 11 - 0
lib/single-file/processors/frame-tree/content/content-frame-tree.js

@@ -36,6 +36,7 @@ this.singlefile.lib.processors.frameTree.content.frames = this.singlefile.lib.pr
 	const INIT_RESPONSE_MESSAGE = "singlefile.frameTree.initResponse";
 	const TARGET_ORIGIN = "*";
 	const TIMEOUT_INIT_REQUEST_MESSAGE = 750;
+	const TIMEOUT_INIT_RESPONSE_MESSAGE = 10000;
 	const TOP_WINDOW_ID = "0";
 	const WINDOW_ID_SEPARATOR = ".";
 	const TOP_WINDOW = window == window.top;
@@ -60,6 +61,7 @@ this.singlefile.lib.processors.frameTree.content.frames = this.singlefile.lib.pr
 					return Promise.resolve({});
 				} else if (message.method == ACK_INIT_REQUEST_MESSAGE) {
 					clearFrameTimeout(message.sessionId, message.windowId);
+					createFrameResponseTimeout(message.sessionId, message.windowId);
 					return Promise.resolve({});
 				}
 			});
@@ -81,6 +83,7 @@ this.singlefile.lib.processors.frameTree.content.frames = this.singlefile.lib.pr
 				}
 			} else if (message.method == ACK_INIT_REQUEST_MESSAGE) {
 				clearFrameTimeout(message.sessionId, message.windowId);
+				createFrameResponseTimeout(message.sessionId, message.windowId);
 			} else if (message.method == CLEANUP_REQUEST_MESSAGE) {
 				cleanupRequest(message);
 			} else if ((!browser || !browser.runtime) && message.method == INIT_RESPONSE_MESSAGE) {
@@ -157,6 +160,7 @@ this.singlefile.lib.processors.frameTree.content.frames = this.singlefile.lib.pr
 	}
 
 	function initResponse(message) {
+		message.frames.forEach(frameData => clearFrameTimeout(message.sessionId, frameData.windowId));
 		const windowData = sessions.get(message.sessionId);
 		if (windowData) {
 			if (message.requestedFrameId) {
@@ -271,6 +275,13 @@ this.singlefile.lib.processors.frameTree.content.frames = this.singlefile.lib.pr
 		}
 	}
 
+	function createFrameResponseTimeout(sessionId, windowId) {
+		const session = sessions.get(sessionId);
+		if (session && session.timeouts) {
+			session.timeouts[windowId] = setTimeout.call(window, () => sendInitResponse({ frames: [{ windowId: windowId, processed: true }], sessionId: sessionId }), TIMEOUT_INIT_RESPONSE_MESSAGE);
+		}
+	}
+
 	function cleanupFrames(frameElements, parentWindowId, sessionId) {
 		frameElements.forEach((frameElement, frameIndex) => {
 			const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;