Gildas 7 anni fa
parent
commit
3e1e2d3ae8
2 ha cambiato i file con 22 aggiunte e 23 eliminazioni
  1. 18 19
      extension/core/scripts/bg/fetch.js
  2. 4 4
      extension/core/scripts/content/fetch.js

+ 18 - 19
extension/core/scripts/bg/fetch.js

@@ -27,23 +27,6 @@
 	let requestId = 1;
 
 	chrome.runtime.onMessage.addListener((request, sender, send) => {
-
-		function sendResponse(response) {
-			if (request.method.startsWith("fetch.")) {
-				fetchResponses.delete(request.requestId);
-			}
-			send(response);
-		}
-
-		function sendFetchResponse(responseId, response) {
-			fetchResponses.set(responseId, response);
-			const headers = {};
-			for (let headerName of response.headers.keys()) {
-				headers[headerName] = response.headers.get(headerName);
-			}
-			sendResponse({ responseId, headers });
-		}
-
 		if (request.method) {
 			if (request.method == "fetch") {
 				const responseId = requestId;
@@ -58,10 +41,10 @@
 					.catch(error => sendResponse({ error: error.toString() }));
 				requestId = requestId + 1;
 			}
-			if (request.method == "fetch.uint8array") {
+			if (request.method == "fetch.array") {
 				const content = fetchResponses.get(request.requestId);
 				content.arrayBuffer()
-					.then(buffer => sendResponse({ uint8array: Array.from(new Uint8Array(buffer)) }))
+					.then(buffer => sendResponse({ array: Array.from(new Uint8Array(buffer)) }))
 					.catch(error => sendResponse({ error: error.toString() }));
 			}
 			if (request.method == "fetch.text") {
@@ -72,6 +55,22 @@
 			}
 			return true;
 		}
+
+		function sendResponse(response) {
+			if (request.method.startsWith("fetch.")) {
+				fetchResponses.delete(request.requestId);
+			}
+			send(response);
+		}
+
+		function sendFetchResponse(responseId, response) {
+			fetchResponses.set(responseId, response);
+			const headers = {};
+			for (let headerName of response.headers.keys()) {
+				headers[headerName] = response.headers.get(headerName);
+			}
+			sendResponse({ responseId, headers });
+		}
 	});
 
 })();

+ 4 - 4
extension/core/scripts/content/fetch.js

@@ -27,12 +27,12 @@ window.superFetch = (() => {
 		return {
 			headers: { get: headerName => responseFetch.headers[headerName] },
 			arrayBuffer: async () => {
-				const response = await chromeRuntimeSendMessage({ method: "fetch.uint8array", requestId: responseFetch.responseId });
-				return new Uint8Array(response.uint8array).buffer;
+				const response = await chromeRuntimeSendMessage({ method: "fetch.array", requestId: responseFetch.responseId });
+				return new Uint8Array(response.array).buffer;
 			},
 			blob: async () => {
-				const response = await chromeRuntimeSendMessage({ method: "fetch.uint8array", requestId: responseFetch.responseId });
-				return new Blob([new Uint8Array(response.uint8array)]);
+				const response = await chromeRuntimeSendMessage({ method: "fetch.array", requestId: responseFetch.responseId });
+				return new Blob([new Uint8Array(response.array)]);
 			},
 			text: async () => {
 				const response = await chromeRuntimeSendMessage({ method: "fetch.text", requestId: responseFetch.responseId });