Преглед изворни кода

added support of iframes found into web components

Gildas пре 6 година
родитељ
комит
25687ce223
1 измењених фајлова са 17 додато и 6 уклоњено
  1. 17 6
      lib/frame-tree/content/content-frame-tree.js

+ 17 - 6
lib/frame-tree/content/content-frame-tree.js

@@ -27,6 +27,7 @@ this.frameTree = this.frameTree || (() => {
 
 	const MESSAGE_PREFIX = "__frameTree__::";
 	const FRAMES_CSS_SELECTOR = "iframe, frame, object[type=\"text/html\"][data]";
+	const ALL_ELEMENTS_CSS_SELECTOR = "*";
 	const INIT_REQUEST_MESSAGE = "initRequest";
 	const CLEANUP_REQUEST_MESSAGE = "cleanupRequest";
 	const INIT_RESPONSE_MESSAGE = "frameTree.initResponse";
@@ -97,7 +98,7 @@ this.frameTree = this.frameTree || (() => {
 		if (!TOP_WINDOW) {
 			windowId = message.windowId;
 		}
-		processFrames(document, document.querySelectorAll(FRAMES_CSS_SELECTOR), message.options, windowId, sessionId);
+		processFrames(document, message.options, windowId, sessionId);
 		if (!TOP_WINDOW) {
 			sendInitResponse({ framesData: [getFrameData(document, window, windowId, message.options)], sessionId, requestedFrameId: document.documentElement.dataset.requestedFrameId && windowId });
 			delete document.documentElement.dataset.requestedFrameId;
@@ -106,8 +107,7 @@ this.frameTree = this.frameTree || (() => {
 
 	function cleanupRequest(message) {
 		const sessionId = message.sessionId;
-		const frameElements = document.querySelectorAll(FRAMES_CSS_SELECTOR);
-		cleanupFrames(frameElements, message.windowId, sessionId);
+		cleanupFrames(getFrames(document), message.windowId, sessionId);
 	}
 
 	function initResponse(message) {
@@ -152,7 +152,8 @@ this.frameTree = this.frameTree || (() => {
 			}
 		}
 	}
-	function processFrames(doc, frameElements, options, parentWindowId, sessionId) {
+	function processFrames(doc, options, parentWindowId, sessionId) {
+		const frameElements = getFrames(doc);
 		processFramesAsync(doc, frameElements, options, parentWindowId, sessionId);
 		if (frameElements.length) {
 			processFramesSync(doc, frameElements, options, parentWindowId, sessionId);
@@ -190,7 +191,7 @@ this.frameTree = this.frameTree || (() => {
 				try {
 					const frameWindow = frameElement.contentWindow;
 					frameWindow.stop();
-					processFrames(frameDoc, frameDoc.querySelectorAll(FRAMES_CSS_SELECTOR), options, windowId, sessionId);
+					processFrames(frameDoc, options, windowId, sessionId);
 					framesData.push(getFrameData(frameDoc, frameWindow, windowId, options));
 				} catch (error) {
 					framesData.push({ windowId, processed: true });
@@ -221,7 +222,7 @@ this.frameTree = this.frameTree || (() => {
 			}
 			if (frameDoc) {
 				try {
-					cleanupFrames(frameDoc.querySelectorAll(FRAMES_CSS_SELECTOR), windowId, sessionId);
+					cleanupFrames(getFrames(frameDoc), windowId, sessionId);
 				} catch (error) {
 					// ignored
 				}
@@ -273,4 +274,14 @@ this.frameTree = this.frameTree || (() => {
 		};
 	}
 
+	function getFrames(document) {
+		let frames = Array.from(document.querySelectorAll(FRAMES_CSS_SELECTOR));
+		document.querySelectorAll(ALL_ELEMENTS_CSS_SELECTOR).forEach(element => {
+			if (element.shadowRoot) {
+				frames = frames.concat(...element.shadowRoot.querySelectorAll(FRAMES_CSS_SELECTOR));
+			}
+		});
+		return frames;
+	}
+
 })();