aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/audio-downloader.js12
-rw-r--r--ext/bg/js/native-simple-dom-parser.js4
2 files changed, 14 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');
+ }
+ }
}
diff --git a/ext/bg/js/native-simple-dom-parser.js b/ext/bg/js/native-simple-dom-parser.js
index 2aa4134d..4e0d89ea 100644
--- a/ext/bg/js/native-simple-dom-parser.js
+++ b/ext/bg/js/native-simple-dom-parser.js
@@ -43,4 +43,8 @@ class NativeSimpleDOMParser {
getTextContent(element) {
return element.textContent;
}
+
+ static isSupported() {
+ return typeof DOMParser !== 'undefined';
+ }
}