<!DOCTYPE html>
<meta charset="utf8">
<script>
window.onload = async () => {
  parent.postMessage("ready", "*");
}

window.addEventListener("message", async function listener(event) {
  if (event.data[0] == "gimme") {
    var result = [];

    // Prepare for test of AudioContext.currentTime
    // eslint-disable-next-line
    let audioContext = new AudioContext();

    // Known ways to generate time stamps, in milliseconds
    const timeStampCodes = [
      "performance.now()",
      "new Date().getTime()",
      "new Event(\"\").timeStamp",
      "new File([], \"\").lastModified",
    ];
    // These are measured in seconds, so we need to scale them up
    var timeStampCodesDOM = timeStampCodes.concat([
      "audioContext.currentTime * 1000",
    ]);

    for (let timeStampCode of timeStampCodesDOM) {
      // eslint-disable-next-line no-eval
      let timeStamp = eval(timeStampCode);

      result.push({
        'name': timeStampCode,
        'value': timeStamp
      });
    }

    let worker = new SharedWorker("file_reduceTimePrecision_iframe_worker.sjs");
    let worker_result = await new Promise(resolve => {
      worker.port.onmessage = function(e) {
        resolve(e.data);
      };
    });

    for (let item of worker_result) {
      result.push(item);
    }

    parent.postMessage(result, "*")
  }
});
</script>
