aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/audio-downloader.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/audio-downloader.js')
-rw-r--r--ext/bg/js/audio-downloader.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/ext/bg/js/audio-downloader.js b/ext/bg/js/audio-downloader.js
index ddddfe18..839eab7b 100644
--- a/ext/bg/js/audio-downloader.js
+++ b/ext/bg/js/audio-downloader.js
@@ -109,7 +109,7 @@ class AudioDownloader {
});
const responseText = await response.text();
- const dom = new NativeSimpleDOMParser(responseText);
+ const dom = this._createSimpleDOMParser(responseText);
for (const row of dom.getElementsByClassName('dc-result-row')) {
try {
const audio = dom.getElementByTagName('audio', row);
@@ -149,7 +149,7 @@ class AudioDownloader {
});
const responseText = await response.text();
- const dom = new NativeSimpleDOMParser(responseText);
+ const dom = this._createSimpleDOMParser(responseText);
try {
const audio = dom.getElementById(`audio_${expression}:${reading}`);
if (audio !== null) {
@@ -237,4 +237,12 @@ class AudioDownloader {
_arrayBufferToBase64(arrayBuffer) {
return btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
}
+
+ _createSimpleDOMParser(content) {
+ if (NativeSimpleDOMParser.isSupported()) {
+ return new NativeSimpleDOMParser(content);
+ } else {
+ throw new Error('DOM parsing not supported');
+ }
+ }
}