Sub topic 13
Debugging transitions in DevTools
A cross-document view transition lasts a fraction of a second and spans two page loads. You can't inspect it in the usual way, because the pseudo-elements disappear before you can click them and the console clears when the page navigates. This chapter covers how to slow transitions down, keep your logs, and find out why a transition didn't run.
This chapter assumes you've read the earlier chapters on @view-transition, the pseudo-element tree, view-transition-name, and the pageswap and pagereveal events. The DevTools examples use Chrome or another Chromium browser, because it ships cross-document view transitions. Panel names and layout change between versions, so adjust to your build.
What makes these transitions hard to debug
Three properties get in the way:
- The pseudo-elements are temporary. The
::view-transitiontree exists only while the transition runs. When it finishes, the tree is removed. - Two documents are involved. The old page runs
pageswap. The new page runspagereveal. Each has its own console context. - Failure is silent. If the browser skips the transition, the navigation still succeeds. You see an ordinary page load with no error.
The approach is to make the transition longer, keep your logs across navigations, and find out which stage failed.
Keep the console across navigations
By default, Chrome clears the console on each navigation. Open the Console settings (the gear icon) and enable Preserve log. Messages from the old page's pageswap handler then stay visible next to messages from the new page's pagereveal handler.
Also open the Network panel and tick Disable cache while DevTools is open. A stale stylesheet missing the @view-transition rule is a common cause of "it worked a minute ago".
For logs that survive even without Preserve log, write them to sessionStorage. The script below records both lifecycle events and the outcome of the transition:
function log(label, extra = {}) {
const entry = { label, page: location.pathname, t: Math.round(performance.now()), ...extra };
console.log(entry);
const all = JSON.parse(sessionStorage.getItem('vt-log') ?? '[]');
all.push(entry);
sessionStorage.setItem('vt-log', JSON.stringify(all.slice(-50)));
}
window.addEventListener('pageswap', (event) => {
log('pageswap', {
hasTransition: Boolean(event.viewTransition),
to: event.activation?.entry.url ?? null,
});
});
window.addEventListener('pagereveal', (event) => {
log('pagereveal', {
hasTransition: Boolean(event.viewTransition),
from: window.navigation?.activation?.from?.url ?? null,
});
const transition = event.viewTransition;
if (!transition) return;
transition.ready.then(
() => log('ready'),
(reason) => log('skipped', { reason: String(reason) })
);
transition.finished.then(
() => log('finished'),
(reason) => log('finished-with-error', { reason: String(reason) })
);
});After a navigation, type console.table(JSON.parse(sessionStorage.getItem('vt-log'))) in the console to see the sequence.
Read the log like this:
- No
pageswapentry: the old page doesn't have this script, or the navigation never left the page. hasTransition: falseinpageswaporpagereveal: the browser decided not to start a transition. Check opt-in and eligibility.skipped: a transition was created but was abandoned before it could animate. The reason string is your clue.readythenfinished: the transition ran. If it looks wrong, the problem is in your CSS.
Slow the transition down
To inspect a 300 ms animation, you must stretch it. There are two ways.
Option 1: temporary CSS
This is the most dependable method. Add a debug rule to the stylesheet:
/* DEBUG ONLY: remove before shipping. */
::view-transition-group(*) {
animation-duration: 5s;
outline: 2px solid red;
}
::view-transition-old(*),
::view-transition-new(*) {
animation-duration: 5s;
}The (*) selector matches every named group, including root. The red outline shows each group's box, which makes size and position mismatches easy to spot. If you used animation: none in a reduced-motion rule, check that your OS setting isn't on, or this rule will be overridden.
Option 2: the Animations panel
Open the Animations panel from the DevTools drawer (the three-dot menu, then More tools). Use the playback speed buttons (100%, 25%, 10%) before you navigate, or use the pause control while the transition runs. While a transition is paused, its pseudo-elements stay in the DOM, so you can inspect them. Because the panel is attached to a page, you may need to reselect speed settings after a navigation. If the panel doesn't capture the animation, use the CSS method.
Inspect the pseudo-element tree
While the transition is slowed or paused, open the Elements panel. The tree appears under the <html> element, before <head>:
html
└─ ::view-transition
├─ ::view-transition-group(root)
│ └─ ::view-transition-image-pair(root)
│ ├─ ::view-transition-old(root)
│ └─ ::view-transition-new(root)
└─ ::view-transition-group(post-image)
└─ ::view-transition-image-pair(post-image)
├─ ::view-transition-old(post-image)
└─ ::view-transition-new(post-image)Here is what to check:
- Is there a group for each name you expect? A missing
post-imagegroup means the name wasn't applied on one or both pages at snapshot time. - Does a group have only
oldor onlynew? The element existed on only one page, so the browser fades it in or out instead of morphing it. - Do the styles you wrote appear in the Styles pane when you select a pseudo-element? If your
::view-transition-old(root)rule is crossed out or missing, the selector or the stylesheet is wrong.
The pseudo-elements sit above the page, so clicking the viewport won't select them. Select them in the Elements tree.
Work through the failure stages
Most problems fall at a specific stage. The diagram follows the order the browser checks things in.
Stage 1: opt-in
In the Elements panel, open the Styles pane on <html> and look for the @view-transition rule with navigation: auto. Check both pages. A common mistake is adding the rule to the list page's stylesheet only. Also confirm the stylesheet actually loaded: the Network panel shows its status, and a 404 means the rule never applied.
Stage 2: eligibility
Check that:
- The old and new URLs are same-origin. A link from
example.comtowww.example.comis cross-origin. - Redirects stay on the same origin. A redirect through another origin makes the navigation ineligible. The Network panel lists every hop.
- The navigation came from a link click, a form submission, or back/forward. Setting
location.hreffrom script, typing in the address bar, or reloading may not qualify. - The page isn't in a state the browser skips, such as a background tab. Transitions don't run when the page is hidden.
Stage 3: timing
If the log shows skipped, the new page may have taken too long to become renderable. Throttle the network in the Network panel (for example, Fast 4G) and test again. A slow server response or a heavy blocking script often explains skips that never happen on localhost. If you use rel="expect" with blocking="render", verify that the id in href exists in the HTML. A missing element means the page waits until the browser's timeout.
Stage 4: names
Duplicate view-transition-name values on one page cause the transition to be skipped. This is easy to trigger from lists: if every card thumbnail carries post-image in CSS, there are many matches. Run this in the console to count names:
const named = [...document.querySelectorAll('*')].filter(
(el) => getComputedStyle(el).viewTransitionName !== 'none'
);
console.table(
named.map((el) => ({
element: el.tagName.toLowerCase() + (el.id ? '#' + el.id : ''),
name: getComputedStyle(el).viewTransitionName,
}))
);Each name in the table should appear once. Run it on the page before navigating and, using the log, compare to the expected names on the destination page. Also check the timing of dynamic names: a name set in pageswap must be set before the old snapshot, and a name set in pagereveal must be set before the new frame is captured.
Common symptoms
| Symptom | Likely cause | What to check |
|---|---|---|
| Plain page load, no animation | Missing opt-in on one page | Styles pane on `<html>` for both pages |
| Works locally, not in production | Slow load, or a cross-origin redirect | Network throttling and redirect chain |
| Whole page fades but the image doesn't morph | Name set on only one page | Pseudo-tree shows only `old` or `new` |
| Transition skipped on the list page | Duplicate names | The name-count script above |
| Image morphs, but jumps in size | Different aspect ratio or `object-fit` | Group outline box on both ends |
| Custom animation ignored | Rule overridden or selector wrong | Styles pane on the pseudo-element |
| Animation runs for users who asked for reduced motion | Missing media query | Emulate `prefers-reduced-motion` in the Rendering panel |
To test reduced motion, open the Rendering panel and set Emulate CSS media feature prefers-reduced-motion to reduce. This avoids changing your operating system setting.
A repeatable routine
- Enable Preserve log and Disable cache, and add the logging script to both pages.
- Navigate and read
console.tableof the log. Decide which stage failed. - If a transition exists but looks wrong, add the slow-motion CSS and inspect the pseudo-tree.
- Throttle the network and repeat, to catch timing problems.
- Emulate reduced motion and confirm the movement stops.
- Remove the debug rules.
Exercise
Your list page logs pageswap with hasTransition: true, but the detail page logs pagereveal with hasTransition: false. Which stage is the most likely culprit, and what two things would you check?
Show answer
The opt-in stage, because the new page decides whether to take part. Check that the detail page's stylesheet actually contains @view-transition { navigation: auto; } and that it loaded (look for a 404 in the Network panel). Also check whether a redirect to a different origin happened, which would make the navigation ineligible.
Exercise
You slow the transition to 5 seconds and inspect the Elements panel. The tree contains ::view-transition-group(post-image) with only a ::view-transition-old(post-image) child. What does this tell you, and how do you fix it?
Show answer
The element had the name post-image on the old page but not on the new page at the time of the new snapshot, so the browser has nothing to morph into. Fix the destination page by applying view-transition-name: post-image to the hero image in CSS, or, if the name is set dynamically in pagereveal, make sure it is set before the first rendered frame and the selector finds the element.