cross-origin-helper-frame.html (1043B)
1 <!doctype html> 2 <meta charset="utf8"> 3 <title>Performs IndexedDB tasks in response to postMessage</title> 4 <script> 5 'use strict'; 6 7 self.addEventListener('message', async event => { 8 const action = event.data.action; 9 let response = null; 10 switch(action) { 11 case 'get-database-names': { 12 const dbInfos = await self.indexedDB.databases(); 13 response = dbInfos.map(dbInfo => dbInfo.name); 14 break; 15 } 16 17 case 'delete-database': { 18 const dbName = event.data.name; 19 await new Promise((resolve, reject) => { 20 const request = indexedDB.deleteDatabase(dbName); 21 request.onsuccess = resolve; 22 request.onerror = reject; 23 }); 24 response = true; 25 break; 26 } 27 } 28 event.source.postMessage({ action, response }, event.origin); 29 window.close(); 30 }); 31 32 // Make up for the fact that the opener of a cross-origin window has no way of 33 // knowing when the window finishes loading. 34 if (window.opener !== null) { 35 window.opener.postMessage({ action: null, response: 'ready' }, '*'); 36 } 37 </script>