|
|
@@ -25,6 +25,7 @@ this.frameTree = this.frameTree || (() => {
|
|
|
const MESSAGE_PREFIX = "__frameTree__::";
|
|
|
const FRAMES_CSS_SELECTOR = "iframe, frame, object[type=\"text/html\"][data]";
|
|
|
const INIT_REQUEST_MESSAGE = "initRequest";
|
|
|
+ const CLEANUP_REQUEST_MESSAGE = "cleanupRequest";
|
|
|
const INIT_RESPONSE_MESSAGE = "initResponse";
|
|
|
const TARGET_ORIGIN = "*";
|
|
|
const TIMEOUT_INIT_REQUEST_MESSAGE = 750;
|
|
|
@@ -48,6 +49,8 @@ this.frameTree = this.frameTree || (() => {
|
|
|
if (message.options.loadDeferredImages && window.lazyLoader) {
|
|
|
lazyLoader.process(message.options);
|
|
|
}
|
|
|
+ } else if (message.method == CLEANUP_REQUEST_MESSAGE) {
|
|
|
+ cleanupRequest(message);
|
|
|
} else if (message.method == INIT_RESPONSE_MESSAGE) {
|
|
|
const port = event.ports[0];
|
|
|
port.onmessage = event => initResponse(event.data);
|
|
|
@@ -72,6 +75,11 @@ this.frameTree = this.frameTree || (() => {
|
|
|
initRequest({ windowId, sessionId, options });
|
|
|
return sessions.get(sessionId).frames;
|
|
|
},
|
|
|
+ cleanup: options => {
|
|
|
+ const sessionId = options.sessionId || 0;
|
|
|
+ options = JSON.parse(JSON.stringify(options));
|
|
|
+ cleanupRequest({ windowId, sessionId, options });
|
|
|
+ },
|
|
|
initResponse,
|
|
|
TIMEOUT_INIT_REQUEST_MESSAGE
|
|
|
};
|
|
|
@@ -86,6 +94,15 @@ this.frameTree = this.frameTree || (() => {
|
|
|
processFrames(frameElements, message.options, windowId, sessionId);
|
|
|
}
|
|
|
|
|
|
+ function cleanupRequest(message) {
|
|
|
+ const sessionId = message.sessionId;
|
|
|
+ const frameElements = document.querySelectorAll(FRAMES_CSS_SELECTOR);
|
|
|
+ if (!TOP_WINDOW) {
|
|
|
+ windowId = message.windowId;
|
|
|
+ }
|
|
|
+ cleanupFrames(frameElements, message.options, windowId, sessionId);
|
|
|
+ }
|
|
|
+
|
|
|
function initResponse(message) {
|
|
|
const windowData = sessions.get(message.sessionId);
|
|
|
if (windowData) {
|
|
|
@@ -177,6 +194,34 @@ this.frameTree = this.frameTree || (() => {
|
|
|
sendInitResponse({ framesData, sessionId });
|
|
|
}
|
|
|
|
|
|
+ function cleanupFrames(frameElements, options, parentWindowId, sessionId) {
|
|
|
+ frameElements.forEach((frameElement, frameIndex) => {
|
|
|
+ const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;
|
|
|
+ frameElement.removeAttribute(docHelper.WIN_ID_ATTRIBUTE_NAME);
|
|
|
+ try {
|
|
|
+ sendMessage(frameElement.contentWindow, { method: CLEANUP_REQUEST_MESSAGE, windowId, sessionId, options });
|
|
|
+ } catch (error) {
|
|
|
+ /* ignored */
|
|
|
+ }
|
|
|
+ });
|
|
|
+ frameElements.forEach((frameElement, frameIndex) => {
|
|
|
+ const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;
|
|
|
+ let frameDoc;
|
|
|
+ try {
|
|
|
+ frameDoc = frameElement.contentDocument;
|
|
|
+ } catch (error) {
|
|
|
+ // ignored
|
|
|
+ }
|
|
|
+ if (frameDoc) {
|
|
|
+ try {
|
|
|
+ cleanupFrames(frameDoc.querySelectorAll(FRAMES_CSS_SELECTOR), options, windowId, sessionId);
|
|
|
+ } catch (error) {
|
|
|
+ // ignored
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
function sendInitResponse(message) {
|
|
|
message.method = INIT_RESPONSE_MESSAGE;
|
|
|
try {
|