Revision 13a707c6
Added by koszko over 1 year ago
content/repo_query_cacher.js | ||
---|---|---|
43 | 43 |
*/ |
44 | 44 |
|
45 | 45 |
#FROM common/browser.js IMPORT browser |
46 |
#FROM common/misc.js IMPORT error_data_jsonifiable |
|
46 | 47 |
|
47 | 48 |
/* |
48 | 49 |
* Map URLs to objects containing parsed responses, error info or promises |
49 |
* resolving to those. |
|
50 |
* resolving to those. The use of promises helps us prevent multiple requests |
|
51 |
* for the same resource from starting concurrently. |
|
50 | 52 |
*/ |
51 | 53 |
const cache = new Map(); |
52 | 54 |
|
... | ... | |
58 | 60 |
cache.set(url, new Promise(cb => resolve_cb = cb)); |
59 | 61 |
|
60 | 62 |
try { |
61 |
const opts = {url, to_get: ["ok", "status"], to_call: ["json"]}; |
|
62 |
var result = await browser.runtime.sendMessage(["CORS_bypass", opts]); |
|
63 |
var result = await browser.runtime.sendMessage(["CORS_bypass", {url}]); |
|
63 | 64 |
if (result === undefined) |
64 |
result = {error: "Couldn't communicate with background script."};
|
|
65 |
throw new Error("Couldn't communicate with background script.");
|
|
65 | 66 |
} catch(e) { |
66 |
var result = {error: e + ""};
|
|
67 |
return {error: error_data_jsonifiable(e)};
|
|
67 | 68 |
} |
68 | 69 |
|
69 | 70 |
cache.set(url, result); |
Also available in: Unified diff
serialize and deserialize entire Response object when relaying fetch() calls to other contexts using sendMessage