|
|
@@ -60,7 +60,7 @@ this.singlefile.lib.frameTree.content.frames = this.singlefile.lib.frameTree.con
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- addEventListener.call(window, "message", event => {
|
|
|
+ addEventListener.call(window, "message", async event => {
|
|
|
if (typeof event.data == "string" && event.data.startsWith(MESSAGE_PREFIX)) {
|
|
|
event.preventDefault();
|
|
|
event.stopPropagation();
|
|
|
@@ -70,7 +70,7 @@ this.singlefile.lib.frameTree.content.frames = this.singlefile.lib.frameTree.con
|
|
|
if (message.options.loadDeferredImages && singlefile.lib.lazy.content.loader) {
|
|
|
singlefile.lib.lazy.content.loader.process(message.options);
|
|
|
}
|
|
|
- initRequest(message);
|
|
|
+ await initRequestAsync(message);
|
|
|
} else if (message.method == CLEANUP_REQUEST_MESSAGE) {
|
|
|
cleanupRequest(message);
|
|
|
} else if ((!browser || !browser.runtime) && message.method == INIT_RESPONSE_MESSAGE) {
|
|
|
@@ -83,16 +83,16 @@ this.singlefile.lib.frameTree.content.frames = this.singlefile.lib.frameTree.con
|
|
|
getAsync: async options => {
|
|
|
const sessionId = options.sessionId || 0;
|
|
|
options = JSON.parse(JSON.stringify(options));
|
|
|
- return new Promise(resolve => {
|
|
|
+ return new Promise(async resolve => {
|
|
|
sessions.set(sessionId, { frames: [], resolve });
|
|
|
- initRequest({ windowId, sessionId, options });
|
|
|
+ await initRequestAsync({ windowId, sessionId, options });
|
|
|
});
|
|
|
},
|
|
|
getSync: options => {
|
|
|
const sessionId = options.sessionId || 0;
|
|
|
options = JSON.parse(JSON.stringify(options));
|
|
|
sessions.set(sessionId, { frames: [] });
|
|
|
- initRequest({ windowId, sessionId, options });
|
|
|
+ initRequestSync({ windowId, sessionId, options });
|
|
|
return sessions.get(sessionId).frames;
|
|
|
},
|
|
|
cleanup: options => {
|
|
|
@@ -103,14 +103,40 @@ this.singlefile.lib.frameTree.content.frames = this.singlefile.lib.frameTree.con
|
|
|
TIMEOUT_INIT_REQUEST_MESSAGE
|
|
|
};
|
|
|
|
|
|
- function initRequest(message) {
|
|
|
+ function initRequestSync(message) {
|
|
|
+ const waitForUserScript = singlefile.lib.helper.waitForUserScript;
|
|
|
const sessionId = message.sessionId;
|
|
|
if (!TOP_WINDOW) {
|
|
|
windowId = window.frameId = message.windowId;
|
|
|
}
|
|
|
processFrames(document, message.options, windowId, sessionId);
|
|
|
if (!TOP_WINDOW) {
|
|
|
+ if (message.options.userScriptEnabled && waitForUserScript) {
|
|
|
+ waitForUserScript(singlefile.lib.helper.ON_BEFORE_CAPTURE_EVENT_NAME);
|
|
|
+ }
|
|
|
sendInitResponse({ frames: [getFrameData(document, window, windowId, message.options)], sessionId, requestedFrameId: document.documentElement.dataset.requestedFrameId && windowId });
|
|
|
+ if (message.options.userScriptEnabled && waitForUserScript) {
|
|
|
+ waitForUserScript(singlefile.lib.helper.ON_AFTER_CAPTURE_EVENT_NAME);
|
|
|
+ }
|
|
|
+ delete document.documentElement.dataset.requestedFrameId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function initRequestAsync(message) {
|
|
|
+ const waitForUserScript = singlefile.lib.helper.waitForUserScript;
|
|
|
+ const sessionId = message.sessionId;
|
|
|
+ if (!TOP_WINDOW) {
|
|
|
+ windowId = window.frameId = message.windowId;
|
|
|
+ }
|
|
|
+ processFrames(document, message.options, windowId, sessionId);
|
|
|
+ if (!TOP_WINDOW) {
|
|
|
+ if (message.options.userScriptEnabled && waitForUserScript) {
|
|
|
+ await waitForUserScript(singlefile.lib.helper.ON_BEFORE_CAPTURE_EVENT_NAME);
|
|
|
+ }
|
|
|
+ sendInitResponse({ frames: [getFrameData(document, window, windowId, message.options)], sessionId, requestedFrameId: document.documentElement.dataset.requestedFrameId && windowId });
|
|
|
+ if (message.options.userScriptEnabled && waitForUserScript) {
|
|
|
+ await waitForUserScript(singlefile.lib.helper.ON_AFTER_CAPTURE_EVENT_NAME);
|
|
|
+ }
|
|
|
delete document.documentElement.dataset.requestedFrameId;
|
|
|
}
|
|
|
}
|