Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request persistent storage permissions

Users of my web app have requested an "offline mode" that stores their work on the hard drive while an Internet connection is not available. They could be offline for anywhere from a few minutes to multiple weeks, so in order to prevent loss of their work, I'll need to be able to persist the data, even when under storage pressure (using IndexedDB without the proper permissions could result in data loss).

I read on Google Developers that the asynchronous navigator.storage.persist() method can be used to request the user's permission to store files, but that doesn't work on Chrome - the promise always returns false without prompting the user.

Then I read here that Chrome may decide not to show a permissions popout, but instead grant or deny persistent storage permission based on a precalculated decision. This appears to be based on the following:

  • The site is bookmarked (and the user has 5 or less bookmarks)
  • The site has high site engagement
  • The site has been added to home screen
  • The site has push notifications enabled

If any of the above are true, the permission is already granted, and if not it's automatically rejected. This means that in Chrome, there's no difference between navigator.storage.persist() and navigator.storage.persisted(), even though the first is supposed to be a permissions request and the second is supposed to be a permissions check.

I've already built in-app UI for requesting persistent storage permissions, so all I need is a sure-fire way to get the permissions popout to show in Chrome so the user can grant or deny that permission. Since I can't control the first three conditions, or reasonably ask the user to satisfy them, it seems like my only option is to ask for permission to show push notifications, which is unfortunate because that is not the permission I need and I have no interest in showing push notifications. A permissions request like that would likely confuse users.

Is there a more clear, user-friendly way to get permission to use persistent storage in Chrome?

like image 678
Isaac Lyman Avatar asked Aug 02 '18 15:08

Isaac Lyman


People also ask

What is persistent storage?

Persistent storage is any data storage device that retains data after power to that device is shut off. It is also sometimes referred to as nonvolatile storage.

What is Firefox persistent storage?

In Firefox, when persistent storage is used, the user is given a UI popup to alert them that this data will persist, and asks if they are happy with that. Temporary data storage does not elicit any user prompts.

What is a persistent storage in Java?

Persistence, in computer science, is a noun describing data that outlives the process that created it. Java persistence could be defined as storing anything to any level of persistence using the Java programming language, but obviously this would be too broad a definition to cover in a single book.


2 Answers

If any of the above are true, the permission is already granted, and if not it's automatically rejected.

This is incorrect; the permission must still be requested. Until it is requested/granted the origin will still be treated as "best effort". The site must explicitly request the permission. You can observe this by calling persisted() prior to calling persist() on a site that has never requested the permission.

all I need is a sure-fire way to get the permissions popout to show in Chrome so the user can grant or deny that permission

Chrome does not have a permission popup for this permission, so there is no such way.

The preferred model is to not offer guarantees about offline capability until the permission is granted; that is, request the permission and only show any sort of "your data is absolutely definitely available offline" assurance once it has been granted.

like image 120
Joshua Bell Avatar answered Nov 15 '22 10:11

Joshua Bell


As mentioned by Joshua Chrome does not have a permission popup for this permission.

What I did was manually enabled the push notification in the site settings for my website.

Way to manually enable push notification in Chrome

This was enough for Chrome to grant my website persistence storage permission.

like image 31
Arnab Avatar answered Nov 15 '22 12:11

Arnab