aboutsummaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-03-15 10:12:06 +0100
committerWojtek Kosior <koszko@koszko.org>2022-03-24 20:43:40 +0100
commitbbc9fae4291d0c2cb3976d158ecd20e0bd2a8ea0 (patch)
tree9d72c3184f85b61d3d71bc2d65cddb8058d9222a /content
parent65351e8c69659455096d1e37c4b78d1298fb7021 (diff)
downloadbrowser-extension-bbc9fae4291d0c2cb3976d158ecd20e0bd2a8ea0.tar.gz
browser-extension-bbc9fae4291d0c2cb3976d158ecd20e0bd2a8ea0.zip
serialize and deserialize entire Response object when relaying fetch() calls to other contexts using sendMessage
Diffstat (limited to 'content')
-rw-r--r--content/repo_query_cacher.js11
1 files changed, 6 insertions, 5 deletions
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);