Просмотр исходного кода

don't send twice initResponse when the doc has no frames

Gildas 7 лет назад
Родитель
Сommit
4d23ef0730
1 измененных файлов с 18 добавлено и 16 удалено
  1. 18 16
      lib/single-file/frame-tree.js

+ 18 - 16
lib/single-file/frame-tree.js

@@ -111,24 +111,26 @@ this.frameTree = this.frameTree || (() => {
 			timeout.set(() => top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData: [{ windowId: frameWindowId, processed: true }], windowId: frameWindowId, sessionId }), "*"), TIMEOUT_INIT_REQUEST_MESSAGE);
 		});
 		top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData, windowId, sessionId }), "*");
-		framesData = [];
-		frameElements.forEach((frameElement, frameIndex) => {
-			const frameWindowId = windowId + "." + frameIndex;
-			const frameWindow = frameElement.contentWindow;
-			const frameDoc = frameElement.contentDocument;
-			if (frameDoc) {
-				try {
-					processFrames(frameDoc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"), options, frameWindowId, sessionId, frameWindow);
-					const docData = docHelper.preProcessDoc(frameDoc, frameWindow, options);
-					framesData.push({ windowId: frameWindowId, content: docHelper.serialize(frameDoc), baseURI: frameDoc.baseURI, title: frameDoc.title, emptyStyleRulesText: docData.emptyStyleRulesText, canvasData: docData.canvasData, processed: true });
-					docHelper.postProcessDoc(frameDoc, frameWindow, options);
-				} catch (error) {
-					/* ignored */
+		if (frameElements.length) {
+			framesData = [];
+			frameElements.forEach((frameElement, frameIndex) => {
+				const frameWindowId = windowId + "." + frameIndex;
+				const frameWindow = frameElement.contentWindow;
+				const frameDoc = frameElement.contentDocument;
+				if (frameDoc) {
+					try {
+						processFrames(frameDoc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"), options, frameWindowId, sessionId, frameWindow);
+						const docData = docHelper.preProcessDoc(frameDoc, frameWindow, options);
+						framesData.push({ windowId: frameWindowId, content: docHelper.serialize(frameDoc), baseURI: frameDoc.baseURI, title: frameDoc.title, emptyStyleRulesText: docData.emptyStyleRulesText, canvasData: docData.canvasData, processed: true });
+						docHelper.postProcessDoc(frameDoc, frameWindow, options);
+					} catch (error) {
+						/* ignored */
+					}
 				}
-			}
 
-		});
-		top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData, windowId, sessionId }), "*");
+			});
+			top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData, windowId, sessionId }), "*");
+		}
 	}
 
 })();