From bbc9fae4291d0c2cb3976d158ecd20e0bd2a8ea0 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 15 Mar 2022 10:12:06 +0100 Subject: serialize and deserialize entire Response object when relaying fetch() calls to other contexts using sendMessage --- content/repo_query_cacher.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'content') diff --git a/content/repo_query_cacher.js b/content/repo_query_cacher.js index 3f62be7..be97c39 100644 --- a/content/repo_query_cacher.js +++ b/content/repo_query_cacher.js @@ -43,10 +43,12 @@ */ #FROM common/browser.js IMPORT browser +#FROM common/misc.js IMPORT error_data_jsonifiable /* * Map URLs to objects containing parsed responses, error info or promises - * resolving to those. + * resolving to those. The use of promises helps us prevent multiple requests + * for the same resource from starting concurrently. */ const cache = new Map(); @@ -58,12 +60,11 @@ async function perform_download(url) { cache.set(url, new Promise(cb => resolve_cb = cb)); try { - const opts = {url, to_get: ["ok", "status"], to_call: ["json"]}; - var result = await browser.runtime.sendMessage(["CORS_bypass", opts]); + var result = await browser.runtime.sendMessage(["CORS_bypass", {url}]); if (result === undefined) - result = {error: "Couldn't communicate with background script."}; + throw new Error("Couldn't communicate with background script."); } catch(e) { - var result = {error: e + ""}; + return {error: error_data_jsonifiable(e)}; } cache.set(url, result); -- cgit v1.2.3