Browse Source

avoid retrieving frame contents and loading defered images when saving the raw page

Gildas 7 years ago
parent
commit
a9389f803d
2 changed files with 20 additions and 18 deletions
  1. 17 15
      extension/core/content/content.js
  2. 3 3
      lib/single-file/single-file-core.js

+ 17 - 15
extension/core/content/content.js

@@ -72,22 +72,24 @@ this.singlefile.top = this.singlefile.top || (() => {
 		const preInitializationPromises = [];
 		options.insertSingleFileComment = true;
 		options.insertFaviconLink = true;
-		if (!options.removeFrames && this.frameTree) {
-			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);
+		if (!options.saveRawPage) {
+			if (!options.removeFrames && this.frameTree) {
+				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);
+			}
+			if (options.lazyLoadImages && options.shadowEnabled) {
+				const lazyLoadPromise = lazyLoader.process(options);
+				singlefile.ui.onLoadingDeferResources();
+				lazyLoadPromise.then(() => singlefile.ui.onLoadDeferResources());
+				preInitializationPromises.push(lazyLoadPromise);
 			}
-			singlefile.ui.onLoadingFrames();
-			frameTreePromise.then(() => singlefile.ui.onLoadFrames());
-			preInitializationPromises.push(frameTreePromise);
-		}
-		if (options.lazyLoadImages && options.shadowEnabled) {
-			const lazyLoadPromise = lazyLoader.process(options);
-			singlefile.ui.onLoadingDeferResources();
-			lazyLoadPromise.then(() => singlefile.ui.onLoadDeferResources());
-			preInitializationPromises.push(lazyLoadPromise);
 		}
 		let index = 0, maxIndex = 0;
 		options.onprogress = event => {

+ 3 - 3
lib/single-file/single-file-core.js

@@ -332,7 +332,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 		initialize() {
 			this.maxResources = this.batchRequest.getMaxResources();
-			if (!this.options.removeFrames) {
+			if (!this.options.saveRawPage && !this.options.removeFrames) {
 				this.options.framesData.forEach(frameData => this.maxResources += frameData.maxResources || 0);
 			}
 			this.stats.set("processed", "resources", this.maxResources);
@@ -524,7 +524,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 						imgElement.setAttribute("src", imgData.currentSrc);
 					}
 				});
-				if (this.options.lazyLoadImages) {
+				if (!this.options.saveRawPage && this.options.lazyLoadImages) {
 					this.doc.querySelectorAll("img[data-src]").forEach(imgElement => {
 						const imgData = this.options.imageData[Number(imgElement.getAttribute(dataAttributeName))];
 						if ((!imgElement.getAttribute("src") || imgElement.getAttribute("src") == EMPTY_IMAGE) && imgElement.getAttribute("data-src")) {
@@ -889,7 +889,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		}
 
 		async resolveFrameURLs() {
-			if (this.options.framesData) {
+			if (!this.options.saveRawPage && this.options.framesData) {
 				const frameElements = Array.from(this.doc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"));
 				await Promise.all(frameElements.map(async frameElement => {
 					ProcessorHelper.setFrameEmptySrc(frameElement);