cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <button onclick="checkAPI();">Check if navigator.storage API's can run on your browser</button>

<button onclick="showEstimate();">Estimate Available Space</button>

<button onclick="queryForPermission();">Query For User Permission</button>

<button onclick="revokePermission();">Revoke User Permission</button>

<p class="message hasAPI">
  <span>navigator.storage.persist</span> and <span>navigator.storage.estimate</span> work fine.
</p>

<p class="message estimate"></p>

<p class="message permission"></p>

<p class="message error noAPI">
  You browser does not support <span>navigator.storage</span>
</p>

<p class="message error incompleteAPI">
  You browser has incomplete implementation of <span>navigator.storage</span>. Things like <span>navigator.storage.persist</span> and <span>navigator.storage.estimate</span> are used in this demo.
</p>
            
          
!
            
              

.message {
  padding: 20px;
  line-height: 2;
  border: 1px solid #f2f2f2;
  display: none;
  
  &.error {
    border: 1px solid #e60000;
    background: #ffb3b3;
    color: #e60000;
  }
  
  a {
    text-decoration: none;
    color: white;
    font-weight: bold;
  }
  
  span {
    border: 1px solid white;
    border-radius: 5px;
    padding: 5px;
    background: #f2f2f2;
  }
}

.show {
  display: block;
}

button {
  display: block;
  width: 50%;
  height: 50px;
  margin: 20px auto;
  background:  #99ff99;
  border: 1px solid #00e600;
  color: #008000;
  cursor: pointer;
}
            
          
!
            
              function checkAPI() {
  // this checks whether navigator.storage.persist and navigator.storage.estimate apis
  // can run or not
  if (!navigator.storage) {
    showMessage('.noAPI');
    return;
  }
  
  if(!navigator.storage.persist || !navigator.storage.estimate) {
    showMessage('.incompleteAPI');
    return;
  }
  
  showMessage('.hasAPI');
}

function showEstimate() {
  checkAPI();
  
  navigator.storage.estimate()
    .then(info => {
      document.querySelector('.estimate').innerHTML = `
            <span>Quota</span>: ${info.quota} Units and
            <span>Usage</span>: ${info.usage} Units
         `;
      showMessage('.estimate');
    })
}

function queryForPermission() {
  checkAPI();
  
  navigator.permissions.query({
    name: 'persistent-storage'
  })
  .then((info) => {
    console.log('info', info)
    if(info.state == 'prompt') {
      // start the prompt
      navigator.storage.persist()
      .then((data) => {
        document.querySelector('.permission').innerHTML = `
            <span>navigator.storage.persist()</span> 
            is asking for permissions. Please click on the 
            <span>Allow</span> button.
         `;
        showMessage('.permission');
      })
    }
    
    if(info.state == 'granted') {
      
      // you dont need permissions
      // for already enabled 
      navigator.storage.persist()
      .then((data) => {
        document.querySelector('.permission').innerHTML = `
            <span>navigator.storage.persist()</span> 
            has the permission set to 
            <span>granted</span>
         `;
        showMessage('.permission');
      })
    }
  })
  .catch((e) => {
    console.log(e)
  })
}

function revokePermission() {
  
  // dom.permissions.revoke.enable 
  // needs to be set to true
  navigator.permissions.revoke({
    name: 'persistent-storage'
  })
  .then((info) => {
    if(info.state == 'granted') {
      
      document.querySelector('.permission').innerHTML = `
          You permissions for 
          <span>navigator.storage.persist()</span> 
          has been <span>revoked</span>.
       `;
      showMessage('.permission');
      
    }
  })
  .catch((e) => {
    document.querySelector('.permission').innerHTML = `
        Nothing to revoke.
     `;
    showMessage('.permission');
  })
}

function showMessage(classname) {
  document.querySelector(classname).classList.add('show');
}
            
          
!
999px
Loading ..................

Console