tor-browser

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

cache-storage-reporting.js (1920B)


      1 function remote(path) {
      2  const REMOTE_ORIGIN = get_host_info().HTTPS_REMOTE_ORIGIN;
      3  return new URL(path, REMOTE_ORIGIN).href;
      4 }
      5 
      6 function local(path) {
      7  return new URL(path, location.origin).href;
      8 }
      9 
     10 function encode(url) {
     11  return encodeURI(url).replace(/\;/g, '%3B');
     12 }
     13 
     14 const resource_path = (new URL('./resources', location)).pathname;
     15 const header_coep = '|header(Cross-Origin-Embedder-Policy,require-corp)';
     16 const header_coep_report_only =
     17    '|header(Cross-Origin-Embedder-Policy-Report-Only,require-corp)';
     18 
     19 const iframe_path = resource_path + '/iframe.html?pipe=';
     20 const worker_path = resource_path + '/reporting-worker.js?pipe=';
     21 const image_url = remote('/images/blue.png');
     22 
     23 // This script attempt to load a COEP:require-corp CORP:undefined response from
     24 // the CacheStorage.
     25 //
     26 // Executed from different context:
     27 // - A Document
     28 // - A ServiceWorker
     29 // - A DedicatedWorker
     30 // - A SharedWorker
     31 //
     32 // The context has either COEP or COEP-Report-Only defined.
     33 const eval_script = `
     34  (async function() {
     35    try {
     36      const cache = await caches.open('v1');
     37      const request = new Request('${image_url}', { mode: 'no-cors' });
     38      const response = await cache.match(request);
     39    } catch(e) {
     40    }
     41  })()
     42 `;
     43 
     44 promise_setup(async (t) => {
     45  const cache = await caches.open('v1');
     46  const request = new Request(image_url, {mode: 'no-cors'});
     47  const response = await fetch(request);
     48  await cache.put(request, response);
     49 }, 'Setup: store a CORS:cross-origin COEP:none response into CacheStorage')
     50 
     51 async function makeIframe(test, iframe_url) {
     52  const iframe = document.createElement('iframe');
     53  test.add_cleanup(() => iframe.remove());
     54  iframe.src = iframe_url;
     55  const iframe_loaded = new Promise(resolve => iframe.onload = resolve);
     56  document.body.appendChild(iframe);
     57  await iframe_loaded;
     58  return iframe;
     59 }
     60 
     61 function wait(ms) {
     62  return new Promise(resolve => step_timeout(resolve, ms));
     63 }