How to request persistent storage permissions in Chrome?

google-chrome
javascript

#1

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 don’t want to confuse my users.

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