Răsfoiți Sursa

added credentials option

Former-commit-id: 779dcd1f69fa44a72dab98887bd9415070ae801f
Gildas 6 ani în urmă
părinte
comite
e021e09fc4

+ 2 - 1
extension/core/bg/config.js

@@ -73,7 +73,8 @@ singlefile.extension.core.bg.config = (() => {
 		groupDuplicateImages: true,
 		saveRawPage: false,
 		saveToClipboard: false,
-		referrerPolicy: "origin-when-cross-origin"
+		referrerPolicy: "origin-when-cross-origin",
+		credentials: "include"
 	};
 
 	let pendingUpgradePromise = upgrade();

+ 5 - 8
lib/fetch/content/content-fetch-resources.js

@@ -30,22 +30,19 @@ this.singlefile.lib.fetch.content.resources = this.singlefile.lib.fetch.content.
 			if (!options.referrerPolicy) {
 				options.referrerPolicy = "origin-when-cross-origin";
 			}
+			if (!options.credentials) {
+				options.credentials = "include";
+			}
 			try {
 				let response = await fetch(url, { cache: "force-cache" });
 				if (response.status == 403) {
 					response = await fetch(url, { cache: "force-cache", referrerPolicy: options.referrerPolicy });
 				}
 				if (response.status == 403) {
-					response = await fetch(url, { credentials: "same-origin", cache: "force-cache", referrerPolicy: options.referrerPolicy });
-				}
-				if (response.status == 403) {
-					response = await fetch(url, { credentials: "include", cache: "force-cache", referrerPolicy: options.referrerPolicy });
-				}
-				if (response.status == 403) {
-					response = await fetch(url, { mode: "cors", credentials: "same-origin", cache: "force-cache", referrerPolicy: options.referrerPolicy });
+					response = await fetch(url, { cache: "force-cache", credentials: options.credentials, referrerPolicy: options.referrerPolicy });
 				}
 				if (response.status == 403) {
-					response = await fetch(url, { mode: "cors", credentials: "include", cache: "force-cache", referrerPolicy: options.referrerPolicy });
+					response = await fetch(url, { cache: "force-cache", mode: "cors", credentials: options.credentials, referrerPolicy: options.referrerPolicy });
 				}
 				if (response.status == 403) {
 					response = await xhrFetch(url);

+ 10 - 5
lib/single-file/single-file-core.js

@@ -309,7 +309,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 						asDataURI,
 						maxResourceSize: options.maxResourceSize,
 						maxResourceSizeEnabled: options.maxResourceSizeEnabled,
-						referrerPolicy: options.referrerPolicy
+						referrerPolicy: options.referrerPolicy,
+						credentials: options.credentials
 					});
 					indexResource = indexResource + 1;
 					onloadListener({ url: resourceURL });
@@ -374,7 +375,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 					maxResourceSize: this.options.maxResourceSize,
 					maxResourceSizeEnabled: this.options.maxResourceSizeEnabled,
 					charset,
-					referrerPolicy: this.options.referrerPolicy
+					referrerPolicy: this.options.referrerPolicy,
+					credentials: this.options.credentials
 				});
 				pageContent = content.data;
 			}
@@ -1084,7 +1086,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 						asDataURI: true,
 						maxResourceSize: this.options.maxResourceSize,
 						maxResourceSizeEnabled: this.options.maxResourceSizeEnabled,
-						referrerPolicy: this.options.referrerPolicy
+						referrerPolicy: this.options.referrerPolicy,
+						credentials: this.options.credentials
 					});
 					scriptElement.setAttribute("src", content.data);
 				}
@@ -1363,7 +1366,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 								maxResourceSize: options.maxResourceSize,
 								maxResourceSizeEnabled: options.maxResourceSizeEnabled,
 								validateTextContentType: true,
-								referrerPolicy: options.referrerPolicy
+								referrerPolicy: options.referrerPolicy,
+								credentials: options.credentials
 							});
 							resourceURL = content.resourceURL;
 							let importedStylesheetContent = Util.removeCssComments(content.data);
@@ -1432,7 +1436,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 					maxResourceSize: options.maxResourceSize,
 					maxResourceSizeEnabled: options.maxResourceSizeEnabled,
 					charset: options.charset,
-					referrerPolicy: options.referrerPolicy
+					referrerPolicy: options.referrerPolicy,
+					credentials: options.credentials
 				});
 				resourceURL = content.resourceURL;
 				let stylesheetContent = Util.removeCssComments(content.data);

+ 4 - 1
lib/single-file/single-file-util.js

@@ -168,7 +168,10 @@ this.singlefile.lib.util = this.singlefile.lib.util || (() => {
 					log("  // STARTED download url =", resourceURL, "asDataURI =", options.asDataURI);
 				}
 				try {
-					resourceContent = await util.getResourceContent(resourceURL, { referrerPolicy: options.referrerPolicy });
+					resourceContent = await util.getResourceContent(resourceURL, {
+						referrerPolicy: options.referrerPolicy,
+						credentials: options.credentials
+					});
 				} catch (error) {
 					return { data: options.asDataURI ? "data:base64," : "", resourceURL };
 				}

+ 4 - 1
lib/single-file/single-file.js

@@ -62,7 +62,10 @@ this.singlefile.lib.SingleFile = this.singlefile.lib.SingleFile || (() => {
 	};
 
 	async function getResourceContent(resourceURL, options) {
-		const resourceContent = await fetchResource(resourceURL, { referrerPolicy: options.referrerPolicy });
+		const resourceContent = await fetchResource(resourceURL, {
+			referrerPolicy: options.referrerPolicy,
+			credentials: options.credentials
+		});
 		const buffer = await resourceContent.arrayBuffer();
 		return {
 			getUrl() {