summaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-02 22:27:53 -0500
committerGitHub <noreply@github.com>2021-03-02 22:27:53 -0500
commit3fe825cf30776b754ac6992dca3c8cc100870fb2 (patch)
tree6ca4ca296814efc4885fbc1e915ffbee9d9da938 /ext/js
parentb0bc7dc08fd05fbfc45679fbad9aee82a9f2248e (diff)
Request persistent storage on Firefox (#1480)
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/background/backend.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index 715b916b..498b94db 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -183,6 +183,8 @@ class Backend {
const onPermissionsChanged = this._onWebExtensionEventWrapper(this._onPermissionsChanged.bind(this));
chrome.permissions.onAdded.addListener(onPermissionsChanged);
chrome.permissions.onRemoved.addListener(onPermissionsChanged);
+
+ chrome.runtime.onInstalled.addListener(this._onInstalled.bind(this));
}
async _prepareInternal() {
@@ -372,6 +374,11 @@ class Backend {
this._checkPermissions();
}
+ _onInstalled({reason}) {
+ if (reason !== 'install') { return; }
+ this._requestPersistentStorage();
+ }
+
// Message handlers
_onApiRequestBackendReadySignal(_params, sender) {
@@ -2103,4 +2110,25 @@ class Backend {
_hasRequiredPermissionsForSettings(options) {
return this._permissions === null || this._permissionsUtil.hasRequiredPermissionsForOptions(this._permissions, options);
}
+
+ async _requestPersistentStorage() {
+ try {
+ if (await navigator.storage.persisted()) { return; }
+
+ // Only request this permission for Firefox versions >= 77.
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1630413
+ const {vendor, version} = await browser.runtime.getBrowserInfo();
+ if (vendor !== 'Mozilla') { return; }
+
+ const match = /^\d+/.exec(version);
+ if (match === null) { return; }
+
+ const versionNumber = Number.parseInt(match[0]);
+ if (!(Number.isFinite(versionNumber) && versionNumber >= 77)) { return; }
+
+ await navigator.storage.persist();
+ } catch (e) {
+ // NOP
+ }
+ }
}