aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/dictionary-importer.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-02 13:30:55 -0400
committerGitHub <noreply@github.com>2020-08-02 13:30:55 -0400
commitb1b33f8beb26f97d91cb282682472c65f6eccae8 (patch)
tree1a7b5027a0f5208135f856759cb7935beac7911a /ext/bg/js/dictionary-importer.js
parenta562a1149808b49f60346c82409f292290fbdd77 (diff)
Fix fetch requests (#708)
* Revert audio fetching functionality to use XMLHttpRequest * Replace requestJson * Replace requestJson * Replace requestJson * Replace requestJson and requestText * Fix tests * Include support for vulgar word searches * Remove request.js
Diffstat (limited to 'ext/bg/js/dictionary-importer.js')
-rw-r--r--ext/bg/js/dictionary-importer.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/ext/bg/js/dictionary-importer.js b/ext/bg/js/dictionary-importer.js
index 69d5c386..4374ff40 100644
--- a/ext/bg/js/dictionary-importer.js
+++ b/ext/bg/js/dictionary-importer.js
@@ -19,7 +19,6 @@
* JSZip
* JsonSchema
* mediaUtility
- * requestJson
*/
class DictionaryImporter {
@@ -235,7 +234,7 @@ class DictionaryImporter {
return schemaPromise;
}
- schemaPromise = requestJson(chrome.runtime.getURL(fileName), 'GET');
+ schemaPromise = this._fetchJsonAsset(fileName);
this._schemas.set(fileName, schemaPromise);
return schemaPromise;
}
@@ -365,4 +364,19 @@ class DictionaryImporter {
return newData;
}
+
+ async _fetchJsonAsset(url) {
+ const response = await fetch(chrome.runtime.getURL(url), {
+ method: 'GET',
+ mode: 'no-cors',
+ cache: 'default',
+ credentials: 'omit',
+ redirect: 'follow',
+ referrerPolicy: 'no-referrer'
+ });
+ if (!response.ok) {
+ throw new Error(`Failed to fetch ${url}: ${response.status}`);
+ }
+ return await response.json();
+ }
}