You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Chrome中以编程方式撤销持久化存储权限?

How to Revoke Persistent Storage Permission Programmatically in Chrome

Hey there! Great question about reversing persistent storage permissions in Chrome. Let's walk through this step by step.

First, just a quick recap of how you enable persistent storage (since you already shared that code snippet):

if (navigator.storage && navigator.storage.persist) 
  navigator.storage.persist()
  .then(granted => { 
    if (granted) console.log("Storage will not be cleared except by explicit user action"); 
    else console.log("Storage may be cleared by the UA under storage pressure."); 
  });

To revoke that persistent storage permission programmatically, you can use the navigator.storage.unpersist() method — it's the direct built-in counterpart to persist(). Here's a working implementation:

if (navigator.storage && navigator.storage.unpersist)
  navigator.storage.unpersist()
  .then(revoked => {
    if (revoked) {
      console.log("Success! Persistent storage permission has been revoked. The browser can now clear this storage when under space pressure.");
    } else {
      console.log("Persistent storage wasn't active for this origin, so no changes were made.");
    }
  });

Key Details to Remember:

  • The unpersist() method returns a promise that resolves to a boolean: true means the permission was successfully revoked, false indicates persistent storage wasn't enabled in the first place.
  • This API only works in secure contexts (HTTPS websites, or localhost for local development) — just like the persist() method.
  • Revoking persistent storage does not delete any existing stored data; it simply removes the protection against automatic cleanup when the browser is low on storage space.

内容的提问来源于stack exchange,提问作者Lutz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:36:13