Skip to content

armgit / moli

Public Imported from GitHub
0

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

1.9 KB
Raw Blame
<!doctype html>
<meta charset="utf-8">
<script src="/wpt/resources/testharness.js"></script>
<script src="/wpt/resources/testharnessreport.js"></script>
<script src="/wpt/resources/moli-wpt-adapter.js"></script>
<script>
function query_param(name) {
  return new URL(location.href).searchParams.get(name);
}

const STORAGE_PREFIX = "__lm_wpt_location_replace_basic__";
const stage = query_param("stage");

if (stage !== "final") {
  sessionStorage.setItem(STORAGE_PREFIX + "initialHref", location.href);
  sessionStorage.setItem(STORAGE_PREFIX + "initialLength", String(history.length));
  location.replace(location.pathname + "?stage=final&marker=replace");
} else {
  test(function () {
    const initialHref = sessionStorage.getItem(STORAGE_PREFIX + "initialHref");
    const initialLength = Number(sessionStorage.getItem(STORAGE_PREFIX + "initialLength"));

    assert_true(initialHref !== null, "source stage should store the initial href");
    assert_true(initialHref !== location.href, "replace should commit a new destination URL");
    assert_equals(query_param("marker"), "replace", "final URL should include the replace marker");
    assert_true(
      location.href.indexOf("stage=final") !== -1,
      "replace should reach the final-stage destination",
    );
    assert_equals(
      history.length,
      initialLength,
      "replace should reuse the current session history entry",
    );
    assert_true(document.location === window.location, "document.location should alias window.location");
    assert_equals(typeof location.assign, "function", "location.assign should stay callable");
    assert_equals(typeof location.replace, "function", "location.replace should stay callable");
    assert_equals(typeof location.reload, "function", "location.reload should stay callable");
  }, "location.replace navigates to the destination without extending session history");
}
</script>