aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-08-22 19:44:31 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-08-26 21:58:03 -0400
commita39a1fa9e4700d1189dfc5073b5fcb2557965671 (patch)
treea803e03e64285d3c2b1c6d4c0e4ee87eee2cb266 /ext/bg/js/util.js
parent8ebac935e8c0ee167514d5726b1e2e16921e4957 (diff)
Add support for Edge browser
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 34b06ddb..3dc7c900 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -87,6 +87,20 @@ function utilDatabasePurge() {
return utilBackend().translator.database.purge();
}
-function utilDatabaseImport(data, progress, exceptions) {
+async function utilDatabaseImport(data, progress, exceptions) {
+ // Edge cannot read data on the background page due to the File object
+ // being created from a different window. Read on the same page instead.
+ if (EXTENSION_IS_BROWSER_EDGE) {
+ data = await utilReadFile(data);
+ }
return utilBackend().translator.database.importDictionary(data, progress, exceptions);
}
+
+function utilReadFile(file) {
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.onload = () => resolve(reader.result);
+ reader.onerror = () => reject(reader.error);
+ reader.readAsBinaryString(file);
+ });
+}