Truly independent web browser
<!DOCTYPE html>
<style>
body {
margin: 0;
overflow: scroll;
}
.spacer {
height: 3000px;
background: linear-gradient(to bottom, red, blue);
}
</style>
<div class="spacer"></div>
<script src="include.js"></script>
<script>
asyncTest(done => {
const vv = window.visualViewport;
const scrollDelta = 100;
println(`Initial: pageTop=${vv.pageTop}, scale=${vv.scale}`);
// First, zoom in
vv.addEventListener("resize", async function onResize() {
vv.removeEventListener("resize", onResize);
println(`After zoom: pageTop=${vv.pageTop}, scale=${vv.scale}, offsetTop=${vv.offsetTop}`);
const pageTopBefore = vv.pageTop;
// Scroll down
internals.wheel(100, 100, 0, scrollDelta);
await scrollOffsetStopsChanging(() => vv.pageTop);
const pageTopAfter = vv.pageTop;
const scrolled = pageTopAfter - pageTopBefore;
println(`pageTop changed by: ${scrolled}`);
// The delta is in screen pixels, which pan the zoomed visual viewport by the delta divided by the scale.
// Allow small tolerance for floating point
const expectedScroll = scrollDelta / vv.scale;
if (Math.abs(scrolled - expectedScroll) < 1) {
println("PASS");
} else {
println(`FAIL: Expected scroll of ${expectedScroll}, got ${scrolled}`);
}
done();
});
requestAnimationFrame(() => {
// Zoom in (scale increases with positive delta)
internals.pinch(100, 100, 0.5);
});
});
</script>