Parcourir la source

send Referer header on Firefox when needed

Gildas il y a 7 ans
Parent
commit
ba354fa946
2 fichiers modifiés avec 11 ajouts et 2 suppressions
  1. 8 2
      lib/fetch/content/fetch.js
  2. 3 0
      lib/single-file/single-file-browser.js

+ 8 - 2
lib/fetch/content/fetch.js

@@ -18,11 +18,11 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global browser, fetch */
+/* global browser, fetch, XPCNativeWrapper, wrappedJSObject */
 
 this.superFetch = this.superFetch || (() => {
 
-	return {
+	const superFetch = {
 		fetch: async url => {
 			try {
 				return await fetch(url);
@@ -38,6 +38,12 @@ this.superFetch = this.superFetch || (() => {
 			}
 		}
 	};
+	if (typeof XPCNativeWrapper != "undefined" && typeof wrappedJSObject != "undefined") {
+		superFetch.hostFetch = async url => {
+			return await XPCNativeWrapper(wrappedJSObject.fetch)(url);
+		};
+	}
+	return superFetch;
 
 	async function sendMessage(message) {
 		const response = await browser.runtime.sendMessage(message);

+ 3 - 0
lib/single-file/single-file-browser.js

@@ -62,6 +62,9 @@ this.SingleFile = this.SingleFile || (() => {
 			} catch (error) {
 				return options && options.asDataURI ? "data:base64," : "";
 			}
+			if (resourceContent.status >= 400 && superFetch.hostFetch) {
+				resourceContent = await superFetch.hostFetch(resourceURL);
+			}
 			if (resourceContent.status >= 400) {
 				resourceContent = options && options.asDataURI ? "data:base64," : "";
 			}