tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

idbfactory-origin-isolation-iframe.html (1442B)


      1 <!DOCTYPE html>
      2 <title>This iframe keeps a transaction on a database alive indefinitely to test</title>
      3 <script>
      4 
      5 // Keeps the passed transaction alive indefinitely (by making requests
      6 // against the named store). Returns a function that asserts that the
      7 // transaction has not already completed and then ends the request loop so that
      8 // the transaction may autocommit and complete.
      9 function keep_alive(tx, store_name) {
     10  let completed = false;
     11  tx.addEventListener('complete', () => { completed = true; });
     12 
     13  let keepSpinning = true;
     14 
     15  function spin() {
     16    if (!keepSpinning)
     17      return;
     18    tx.objectStore(store_name).get(0).onsuccess = spin;
     19  }
     20  spin();
     21 
     22  return () => {
     23    assert_false(completed, 'Transaction completed while kept alive');
     24    keepSpinning = false;
     25  };
     26 }
     27 
     28 async function run() {
     29  const dbs_to_delete = await indexedDB.databases();
     30  for (const db_info of dbs_to_delete) {
     31    let request = indexedDB.deleteDatabase(db_info.name);
     32    await new Promise((resolve, reject) => {
     33      request.onsuccess = resolve;
     34      request.onerror = reject;
     35    });
     36  }
     37 
     38  var openRequest = indexedDB.open('db-isolation-test');
     39  openRequest.onupgradeneeded = () => {
     40    openRequest.result.createObjectStore('s');
     41  };
     42  openRequest.onsuccess = () => {
     43    var tx = openRequest.result.transaction('s', 'readonly');
     44    keep_alive(tx, 's');
     45    window.parent.postMessage("keep_alive_started", "*");
     46  };
     47 }
     48 
     49 run();
     50 </script>