summaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <FooSoft@users.noreply.github.com>2019-08-28 19:41:30 -0700
committerGitHub <noreply@github.com>2019-08-28 19:41:30 -0700
commitcd75f5b97dd47e252854d6381b49d2b7bc77c3ce (patch)
treed2152125ba1216acf2ac888bbda4d8326903d361 /ext/bg/js/util.js
parent7bf215617c9e54228bd5f5fe44b29f7b99de1abc (diff)
parenta39a1fa9e4700d1189dfc5073b5fcb2557965671 (diff)
Merge pull request #188 from toasted-nutbread/edge-support
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);
+ });
+}