opaque-origin-sandbox.html (750B)
1 <!DOCTYPE html> 2 <script> 3 'use strict' 4 5 // Sends a message containing the result of navigator.storage.getDirectory() 6 // to its creator. 7 8 function post_message(data) { 9 if (window.parent !== null) { 10 window.parent.postMessage(data, { targetOrigin: '*' }); 11 } 12 if (window.opener !== null) { 13 window.opener.postMessage(data, { targetOrigin: '*' }); 14 } 15 } 16 17 try { 18 navigator.storage.getDirectory() 19 .then(() => { 20 post_message('navigator.storage.getDirectory(): FULFILLED'); 21 }).catch(error => { 22 post_message(`navigator.storage.getDirectory(): REJECTED: ${error.name}`); 23 }); 24 } catch (error) { 25 post_message(`navigator.storage.getDirectory(): EXCEPTION: ${error.name}`); 26 } 27 </script>