Truly independent web browser
<!DOCTYPE html>
<script src="include.js"></script>
<div id="scroller" tabindex="0" style="width: 100px; height: 100px; overflow: scroll">
<div style="height: 2000px"></div>
</div>
<div style="width: 200vw; height: 1000vh"></div>
<script>
promiseTest(async () => {
const scroller = document.getElementById("scroller");
const scrolled = scrollendEvent(document);
window.scrollTo(100, 0);
await scrolled;
// A key that jumps scrolls before the key press returns. A key that animates leaves the scroll offset alone
// until a later frame. This holds even when a busy page sees only the last frame of the animation.
const keyAnimatesUntilScrollend = async (target, key) => {
const scrollOffset = () => (target === document ? window.scrollY : target.scrollTop);
const scrollOffsetBeforeKey = scrollOffset();
const finished = scrollendEvent(target);
internals.sendKey(target === document ? document.body : target, key);
const keyAnimates = scrollOffset() === scrollOffsetBeforeKey;
await finished;
return keyAnimates;
};
const viewportEndAnimates = await keyAnimatesUntilScrollend(document, "End");
const viewportEnd = document.documentElement.scrollHeight - window.innerHeight;
println(`End animated the viewport to its end: ${viewportEndAnimates && window.scrollY === viewportEnd}`);
const viewportHomeAnimates = await keyAnimatesUntilScrollend(document, "Home");
println(`Home animated the viewport to its start: ${viewportHomeAnimates && window.scrollY === 0}`);
println(`Home kept the viewport's horizontal offset: ${window.scrollX === 100}`);
const scrollerEndAnimates = await keyAnimatesUntilScrollend(scroller, "End");
const scrollerEnd = scroller.scrollHeight - scroller.clientHeight;
println(`End animated the scroll container to its end: ${scrollerEndAnimates && scroller.scrollTop === scrollerEnd}`);
});
</script>