summaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
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);
+ });
+}