Page navigations drawn by a shader that starts at the clicked link
A four-page site inside one canvas. Tap a card or a link: the address changes, and a shader spreads the new page from the element you tapped. Back and Forward do the same. Both pages are live DOM while the shader runs.
Show the code the Navigation API driving a transition shader
- The first view, inside
<live-transition>. Ordinary links and a GET form. The other views are files in /nav-shader/views/. - Intercept every navigation.
precommitHandlerfetches the new view while the old URL is still in the address bar. After the commit, the shader runs.sourceElementis the link or button that was used. - A view becomes a new child of the element. Each child is a state with its own texture.
- The shader.
originis the centre of the clicked element. GLSL and WGSL. - Without the Navigation API. A click listener and
history.pushState(). - Inside the element: each state is uploaded as a texture when it repaints.
- The whole file.
How it works
<live-transition> draws its children in one canvas and blends two of them with a fragment
shader, with WebGPU when it works and WebGL otherwise. This page adds the navigation. One navigate listener intercepts links, the
GET form, Back and Forward. Its precommitHandler fetches the new view's HTML and appends it as a child, which defers the URL
change until the view is ready. Its post-commit handler calls show() with the centre of event.sourceElement as the
origin, and the navigation is finished when the shader has finished.
Views are kept after they are first loaded, so text typed into one is there on the way back. Reloading at
?view=knots starts on that view.
Live checks
| Result | Experiment | Detail |
|---|
Findings
- Measured, headless Chromium 157, 21 November 2026.
precommitHandler,controller.addHandler()andNavigateEvent.sourceElementare all present. The first two were listed for Chrome 141 and 146. - The new view can be a live child of the canvas before the address changes. The precommit handler fetched and appended the view in 84 ms and the query string was still the old one when it resolved. The post-commit handler then started the shader.
sourceElementgives the shader its origin. For a link it is the<a>, for the GET form it is the submit button.getBoundingClientRect()on it, minus the element's own rect, was within 2 px of the card centre. Back and Forward have no source element, so they start from the centre.- Both views run while the shader blends them. At 41% of a 4 s transition the old view's clock had counted on and a text field in the new view took a value. A tap part way through goes to whichever view the shader shows at that point (the
pickfunction of the effect). - Back and Forward are intercepted the same way. A traversal was drawn by the shader. A view is kept as a child after its first load, so its precommit step took 0 ms and its form state was still there.
- A snapshot outlives its element. An
ElementImagetaken withcaptureElementImage()still drew after the element was removed. This page doesn't need it, because the old view stays in the DOM, but a site that discards the old view could keep its picture this way. - The hidden copy that runs the navigating checks shares this tab's history.
history.lengthwent from 2 to 4 while the checks ran. After the copy was removed, one Back from a view returned to the first view, so the copy's entries weren't visited. When the same checks ran during a visitor's own navigation, the copy'shistory.back()undid the visitor's navigation, which is why the checks on this page wait for a tap. - Not verified. WebGPU on screen (no adapter here: the WGSL of the ink shader hasn't been compared with the GLSL), the phone's Back gesture and its preview animation, a cross-document navigation, and what a screen reader says when the view changes. The WebGPU check above compares the two pictures on a device that has an adapter.