aboutsummaryrefslogtreecommitdiff
path: root/ext/js/background/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2022-05-28 21:55:37 -0400
committerGitHub <noreply@github.com>2022-05-28 21:55:37 -0400
commit4e4fa49b0b1fd6ec5a018e742eb9910aa32e7637 (patch)
tree53ff2717de5c0654b0050c58f86fe49b8c89c6a4 /ext/js/background/backend.js
parent756cfc027696901f0afc9b84bb439c67c8b620ad (diff)
Audio request errors (#2161)
* Generalize _onBeforeSendHeadersAddListener * Simplify filter assignment * Use requestId rather than done * Properly support Firefox addListener without arguments * Add details to fetchAnonymous errors * Refactor * Enable support for no header modifications * Update MV3 support for error details * Expose errors in downloadTermAudio * Throw an error if audio download fails due to potential permissions reasons
Diffstat (limited to 'ext/js/background/backend.js')
-rw-r--r--ext/js/background/backend.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index b25b6033..c0f286f8 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -1803,6 +1803,8 @@ class Backend {
reading
));
} catch (e) {
+ const error = this._getAudioDownloadError(e);
+ if (error !== null) { throw error; }
// No audio
return null;
}
@@ -1894,6 +1896,28 @@ class Backend {
return {results, errors};
}
+ _getAudioDownloadError(error) {
+ if (isObject(error.data)) {
+ const {errors} = error.data;
+ if (Array.isArray(errors)) {
+ for (const error2 of errors) {
+ if (!isObject(error2.data)) { continue; }
+ const {details} = error2.data;
+ if (!isObject(details)) { continue; }
+ if (details.error === 'net::ERR_FAILED') {
+ // This is potentially an error due to the extension not having enough URL privileges.
+ // The message logged to the console looks like this:
+ // Access to fetch at '<URL>' from origin 'chrome-extension://<ID>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
+ const result = new Error('Audio download failed due to possible extension permissions error');
+ result.data = {errors};
+ return result;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
_generateAnkiNoteMediaFileName(prefix, extension, timestamp, definitionDetails) {
let fileName = prefix;