mardi 3 décembre 2019

Cancel/abort indexedDB.deleteDatabase if onblocked event is called

I have a weird use case where on webapp onLoad I want to delete indexedDB.

I am using following code

const req = indexedDB.deleteDatabase('abc');
    req.onsuccess = () => {
      console.log('Deleted database successfully');
    };
    req.onerror = () => {
      console.log('Could not delete database');
    };
    req.onblocked = (event: any) => {
      console.log('Could not delete database due to the operation being blocked');
    };

It is working fine on single tab but if there are multiple tabs opened, req.onblocked is called that blocks the indexedDB to open new connections.

Is there any way I can cancel/abort delete request inside req.onblocked event handler? Is there any option available to check already opened connections easily and reliably




Aucun commentaire:

Enregistrer un commentaire