tor-browser

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

delegate-request-subframe.sub.html (1282B)


      1 <!DOCTYPE html>
      2 <title>Payment request delegation test: subframe</title>
      3 
      4 <script>
      5  function reportResult(msg) {
      6      window.top.postMessage({"type": "result", "result": msg}, "*");
      7  }
      8 
      9  async function requestPayment(e) {
     10      const supportedMethods = [{
     11          supportedMethods: "https://{{hosts[][nonexistent]}}/payment-request"
     12      }];
     13      const details = {
     14          total: { label: "Test", amount: { currency: "CAD", value: "1.00" } }
     15      };
     16      const request = new PaymentRequest(supportedMethods, details);
     17 
     18      request.show().catch(e => {
     19          if (e.name == "SecurityError") {
     20              reportResult("failure");
     21          } else if (e.name == "NotSupportedError") {
     22              // Because we used a non-existent url in supportedMethod aboves, this error message
     23              // means all checks required for this test (i.e. user activation check and payment
     24              // delegation check) have passed successfully.
     25              reportResult("success");
     26          } else {
     27              reportResult("unexpected");
     28          }
     29      });
     30  }
     31 
     32  window.addEventListener("message", e => {
     33      if (e.data.type == "make-payment-request")
     34          requestPayment();
     35  });
     36 
     37  window.top.postMessage({"type": "subframe-loaded"}, "*");
     38 </script>