Parcourir la source

get frame contents later when saving deferred images

Gildas il y a 7 ans
Parent
commit
d2597e236a
2 fichiers modifiés avec 11 ajouts et 5 suppressions
  1. 9 4
      extension/core/content/content.js
  2. 2 1
      lib/frame-tree/frame-tree.js

+ 9 - 4
extension/core/content/content.js

@@ -18,7 +18,7 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global browser, SingleFileBrowser, singlefile, frameTree, document, Blob, MouseEvent, getSelection, prompt, addEventListener, Node, window, lazyLoader, URL */
+/* global browser, SingleFileBrowser, singlefile, frameTree, document, Blob, MouseEvent, getSelection, prompt, addEventListener, Node, window, lazyLoader, URL, timeout */
 
 this.singlefile.top = this.singlefile.top || (() => {
 
@@ -87,7 +87,12 @@ this.singlefile.top = this.singlefile.top || (() => {
 		options.insertSingleFileComment = true;
 		options.insertFaviconLink = true;
 		if (!options.removeFrames && this.frameTree) {
-			const frameTreePromise = frameTree.getAsync(options);
+			let frameTreePromise;
+			if (options.lazyLoadImages) {
+				frameTreePromise = new Promise(resolve => timeout.set(() => resolve(frameTree.getAsync(options)), options.maxLazyLoadImagesIdleTime - frameTree.TIMEOUT_INIT_REQUEST_MESSAGE));
+			} else {
+				frameTreePromise = frameTree.getAsync(options);
+			}
 			singlefile.ui.onLoadingFrames();
 			frameTreePromise.then(() => singlefile.ui.onLoadFrames());
 			preInitializationPromises.push(frameTreePromise);
@@ -98,8 +103,6 @@ this.singlefile.top = this.singlefile.top || (() => {
 			lazyLoadPromise.then(() => singlefile.ui.onLoadDeferResources());
 			preInitializationPromises.push(lazyLoadPromise);
 		}
-		options.doc = document;
-		options.win = window;
 		let index = 0, maxIndex = 0;
 		options.onprogress = event => {
 			if (event.type == event.RESOURCES_INITIALIZED) {
@@ -134,6 +137,8 @@ this.singlefile.top = this.singlefile.top || (() => {
 			}
 		};
 		[options.framesData] = await Promise.all(preInitializationPromises);
+		options.doc = document;
+		options.win = window;
 		await processor.initialize();
 		await processor.run();
 		if (options.confirmInfobar) {

+ 2 - 1
lib/frame-tree/frame-tree.js

@@ -72,7 +72,8 @@ this.frameTree = this.frameTree || (() => {
 			initRequest({ windowId, sessionId, options });
 			return sessions.get(sessionId).frames;
 		},
-		initResponse
+		initResponse,
+		TIMEOUT_INIT_REQUEST_MESSAGE
 	};
 
 	function initRequest(message) {