tor-browser

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

stash.js (753B)


      1 // Put test results into Stash
      2 function stashResultsThenClose(key, results) {
      3  fetch(`/scroll-to-text-fragment/stash.py?key=${key}`, {
      4    method: 'POST',
      5    body: JSON.stringify(results)
      6  }).then(() => {
      7    window.close();
      8  });
      9 }
     10 
     11 // Fetch test results from the Stash
     12 function fetchResults(key, resolve, reject) {
     13  fetch(`/scroll-to-text-fragment/stash.py?key=${key}`).then(response => {
     14    return response.text();
     15  }).then(text => {
     16    if (text) {
     17      try {
     18        const results = JSON.parse(text);
     19        resolve(results);
     20      } catch(e) {
     21        reject();
     22      }
     23    } else {
     24      // We keep trying to fetch results as the target page may not have stashed
     25      // them yet.
     26      fetchResults(key, resolve, reject);
     27    }
     28  });
     29 }