<!doctype html>
<script type="module">
import {request_options_with_mediation_required} from './fedcm-helper.sub.js';

// Loading fedcm-iframe.html in the test will make a FedCM call on load, and
// trigger a postMessage upon completion.
//
// message {
//   string result: "Pass" | "Fail"
//   string token: token.token
//   string errorType: error.name
// }

window.onload = async () => {
  try {
    const cred = await navigator.credentials.get(request_options_with_mediation_required());
    window.top.postMessage({result: "Pass", token: cred.token}, '*');
  } catch (error) {
    window.top.postMessage({result: "Fail", errorType: error.name}, '*');
  }
};

</script>
