<script type="text/javascript">
  if (window.parent.postMessage) {
    // wait for message providing confirmation we are in a devhost
    window.addEventListener("message", function (event) {
      if (event.data.type === "devhost-init") {
        window.quartoDevhost = {
          openInputFile: function (line, column, highlight) {
            window.parent.postMessage({
              type: "openfile",
              file: "<%- inputFile %>",
              line: line,
              column: column,
              highlight: highlight
            }, event.origin);
          }
        };


      } else if (event.data.type === "goback") {
        window.history.back()
      } else if (event.data.type === "goforward") {
        window.history.forward()
      }
    }, true);

    // notify host of navigation (e.g. for 'pop out' command)
    window.parent.postMessage({
      type: "navigate",
      href: window.location.href,
      file: "<%- inputFile %>"
    }, "*");
  }
</script>