Bläddra i källkod

fixed incognito issue in Chrome

Gildas 7 år sedan
förälder
incheckning
206465e51a
1 ändrade filer med 14 tillägg och 5 borttagningar
  1. 14 5
      extension/core/bg/core.js

+ 14 - 5
extension/core/bg/core.js

@@ -68,7 +68,13 @@ singlefile.core = (() => {
 					request.url = URL.createObjectURL(new Blob([request.content], { type: "text/html" }));
 				}
 				return downloadPage(request, { confirmFilename: request.confirmFilename, incognito: sender.tab.incognito })
-					.catch(() => ({ notSupported: true }));
+					.catch(error => {
+						if (error.message && error.message.indexOf("'incognito'")) {
+							return downloadPage(request, { confirmFilename: request.confirmFilename })
+						} else {
+							return { notSupported: true };
+						}
+					});
 			} catch (error) {
 				return Promise.resolve({ notSupported: true });
 			}
@@ -132,12 +138,15 @@ singlefile.core = (() => {
 	}
 
 	async function downloadPage(page, options) {
-		const downloadId = await browser.downloads.download({
+		const downloadInfo = {
 			url: page.url,
 			saveAs: options.confirmFilename,
-			filename: page.filename.replace(/[/\\?%*:|"<>]+/g, "_"),
-			incognito: options.incognito
-		});
+			filename: page.filename.replace(/[/\\?%*:|"<>]+/g, "_")
+		};
+		if (options.incognito) {
+			downloadInfo.incognito = true;
+		}
+		const downloadId = await browser.downloads.download(downloadInfo);
 		return new Promise(resolve => {
 			URL.revokeObjectURL(page.url);
 			browser.downloads.onChanged.addListener(onChanged);