middle-frame.html (1107B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="/common/get-host-info.sub.js"></script> 5 </head> 6 <body> 7 <script> 8 onmessage = e => parent.postMessage(e.data, "*"); 9 10 const path = "/fetch/api/resources/cors-top.txt"; 11 const http_url = get_host_info().HTTP_ORIGIN + path; 12 const https_url = get_host_info().HTTPS_ORIGIN + path; 13 14 const ifr = document.createElement("iframe"); 15 ifr.src = `data:text/html, 16 <!DOCTYPE html> 17 <script> 18 async function try_fetch(url) { 19 try { 20 const response = await fetch(url); 21 return response.ok; 22 } catch(e) { 23 return false; 24 } 25 } 26 async function try_fetch_and_report(url) { 27 parent.postMessage({ 28 protocol: new URL(url).protocol, 29 success: await try_fetch(url), 30 }, "*"); 31 } 32 try_fetch_and_report("${http_url}"); 33 try_fetch_and_report("${https_url}"); 34 <\/script> 35 `; 36 document.body.appendChild(ifr); 37 </script> 38 </body> 39 </html>