Ver código fonte

fix CORS issues on ScienceDirect (fix #1484)

Gildas 1 ano atrás
pai
commit
067914878f
1 arquivos alterados com 15 adições e 1 exclusões
  1. 15 1
      src/lib/single-file/fetch/content/content-fetch.js

+ 15 - 1
src/lib/single-file/fetch/content/content-fetch.js

@@ -146,7 +146,21 @@ export {
 async function fetchResource(url, options = {}) {
 	try {
 		const fetchOptions = { cache: "force-cache", headers: options.headers };
-		return await (options.referrer && USE_HOST_FETCH ? hostFetch(url, fetchOptions) : fetch(url, fetchOptions));
+		let response;
+		try {
+			if (options.referrer && !USE_HOST_FETCH) {
+				response = await fetch(url, fetchOptions);
+			} else {
+				response = await hostFetch(url, fetchOptions);
+			}
+		} catch (error) {
+			if (error && error.message == ERR_HOST_FETCH) {
+				response = await fetch(url, fetchOptions);
+			} else {
+				throw error;
+			}
+		}
+		return response;
 	}
 	catch (error) {
 		requestId++;