From b1b33f8beb26f97d91cb282682472c65f6eccae8 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 2 Aug 2020 13:30:55 -0400 Subject: 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 --- ext/bg/js/translator.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'ext/bg/js/translator.js') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 3fd329d1..a1f30bd2 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -29,7 +29,6 @@ * dictTermsSort * dictTermsUndupe * jp - * requestJson */ class Translator { @@ -40,8 +39,7 @@ class Translator { } async prepare() { - const url = chrome.runtime.getURL('/bg/lang/deinflect.json'); - const reasons = await requestJson(url, 'GET'); + const reasons = await this._fetchJsonAsset('/bg/lang/deinflect.json'); this.deinflector = new Deinflector(reasons); } @@ -657,4 +655,19 @@ class Translator { return text; } + + 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(); + } } -- cgit v1.2.3