Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

2.3 KB
Raw Blame
<!doctype html>
<meta charset="utf-8">
<script>
const STORAGE_PREFIX = "__lm_wpt_navigation_cross_document_result_promises_basic__";

for (const key of [
  "resultOrder",
  "sourceLog",
  "committedType",
  "committedUrl",
  "finishedType",
  "finishedUrl",
]) {
  sessionStorage.removeItem(STORAGE_PREFIX + key);
}

let committedSettled = false;
let finishedSettled = false;
const sourceLog = [];

navigation.addEventListener("currententrychange", function (event) {
  sourceLog.push(
    "listener:" + String(event.navigationType) + ":" + (event.from ? event.from.url : "null"),
  );
  sessionStorage.setItem(STORAGE_PREFIX + "sourceLog", sourceLog.join("|"));
});

navigation.oncurrententrychange = function (event) {
  sourceLog.push(
    "prop:" + String(event.navigationType) + ":" + (event.from ? event.from.url : "null"),
  );
  sessionStorage.setItem(STORAGE_PREFIX + "sourceLog", sourceLog.join("|"));
};

sessionStorage.setItem(STORAGE_PREFIX + "sourceLog", "before");

const result = navigation.navigate("resources/navigation-cross-document-result-promises-destination.html");
sessionStorage.setItem(
  STORAGE_PREFIX + "resultOrder",
  [
    "surface:" +
      String(
        !!result &&
          typeof result.committed?.then === "function" &&
          typeof result.finished?.then === "function",
      ),
    "sync:" + String(committedSettled) + "," + String(finishedSettled),
  ].join("|"),
);

result.committed.then(function (entry) {
  committedSettled = true;
  sessionStorage.setItem(
    STORAGE_PREFIX + "resultOrder",
    sessionStorage.getItem(STORAGE_PREFIX + "resultOrder") + "|committed",
  );
  sessionStorage.setItem(STORAGE_PREFIX + "committedType", Object.prototype.toString.call(entry));
  sessionStorage.setItem(STORAGE_PREFIX + "committedUrl", String(entry ? entry.url : ""));
});

result.finished.then(function (entry) {
  finishedSettled = true;
  sessionStorage.setItem(
    STORAGE_PREFIX + "resultOrder",
    sessionStorage.getItem(STORAGE_PREFIX + "resultOrder") + "|finished",
  );
  sessionStorage.setItem(STORAGE_PREFIX + "finishedType", Object.prototype.toString.call(entry));
  sessionStorage.setItem(STORAGE_PREFIX + "finishedUrl", String(entry ? entry.url : ""));
});

sessionStorage.setItem(
  STORAGE_PREFIX + "sourceLog",
  sessionStorage.getItem(STORAGE_PREFIX + "sourceLog") + "|after-call",
);
</script>