summaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-02 18:58:19 -0400
committerGitHub <noreply@github.com>2020-08-02 18:58:19 -0400
commitbdcdf9b1f5430760be605a7a5e84440e324de7b5 (patch)
tree467b9284ce27eaaee5ac27d8c28b95ed32dea775 /ext/mixed
parenta37ca1d378ae0bf3e78d1e2858d3dd6f6982c061 (diff)
Strip request origin (#710)
* Add web request permissions * Create fetch wrapper that anonymizes the request * Fix Firefox not supporting 'extraHeaders' option
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/audio-system.js33
1 files changed, 17 insertions, 16 deletions
diff --git a/ext/mixed/js/audio-system.js b/ext/mixed/js/audio-system.js
index fdfb0b10..07e1a79b 100644
--- a/ext/mixed/js/audio-system.js
+++ b/ext/mixed/js/audio-system.js
@@ -66,10 +66,11 @@ class TextToSpeechAudio {
}
class AudioSystem {
- constructor({audioUriBuilder, useCache}) {
+ constructor({audioUriBuilder, requestBuilder=null, useCache}) {
this._cache = useCache ? new Map() : null;
this._cacheSizeMaximum = 32;
this._audioUriBuilder = audioUriBuilder;
+ this._requestBuilder = requestBuilder;
if (typeof speechSynthesis !== 'undefined') {
// speechSynthesis.getVoices() will not be populated unless some API call is made.
@@ -169,22 +170,22 @@ class AudioSystem {
});
}
- _createAudioBinaryFromUrl(url) {
- return new Promise((resolve, reject) => {
- const xhr = new XMLHttpRequest();
- xhr.responseType = 'arraybuffer';
- xhr.addEventListener('load', async () => {
- const arrayBuffer = xhr.response;
- if (!await this._isAudioBinaryValid(arrayBuffer)) {
- reject(new Error('Could not retrieve audio'));
- } else {
- resolve(arrayBuffer);
- }
- });
- xhr.addEventListener('error', () => reject(new Error('Failed to connect')));
- xhr.open('GET', url);
- xhr.send();
+ async _createAudioBinaryFromUrl(url) {
+ const response = await this._requestBuilder.fetchAnonymous(url, {
+ method: 'GET',
+ mode: 'cors',
+ cache: 'default',
+ credentials: 'omit',
+ redirect: 'follow',
+ referrerPolicy: 'no-referrer'
});
+ const arrayBuffer = await response.arrayBuffer();
+
+ if (!await this._isAudioBinaryValid(arrayBuffer)) {
+ throw new Error('Could not retrieve audio');
+ }
+
+ return arrayBuffer;
}
_isAudioValid(audio) {