Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<html class="reftest-wait">
<title>View transitions: basic cross-document navigation to a prerender</title>
<link rel="author" href="mailto:bokan@chromium.org">
<link rel="match" href="transition-to-prerender-ref.html">
<script src="/common/utils.js"></script>
<script src="/common/reftest-wait.js"></script>
<script src="/speculation-rules/resources/utils.js"></script>
<script src="/speculation-rules/prerender/resources/utils.js"></script>
<style>
@view-transition {
navigation: auto;
}
html {
background-color: red;
}
html.outgoing {
background-color: cornflowerblue;
}
html.incoming {
background-color: hotpink;
}
::view-transition {
background-color: limegreen;
}
::view-transition-new(root) {
transform: translateY(55vh);
animation: none;
opacity: 1;
}
::view-transition-old(root) {
transform: translateY(-55vh);
animation: none;
opacity: 1;
}
::view-transition-group(root) {
animation-duration: 300s;
}
</style>
<script>
const params = new URLSearchParams(location.search);
const uid = params.has('uid') ? params.get('uid') : token();
const ready_channel = new PrerenderChannel('ready-to-activate', uid);
if (!implementsSpeculationRules()) {
onload = () => {
document.body.innerText = 'This test requires speculation rules.';
takeScreenshot();
}
} else {
if (!params.has('next')) {
onload = () => requestAnimationFrame(() => requestAnimationFrame(runTest));
} else {
onload = prerenderedPage;
}
}
async function runTest() {
document.documentElement.classList.add('outgoing');
const next_url =
new URL(`transition-to-prerender.html?next&uid=${uid}`, window.location).href;
const ready_to_activate = new Promise(resolve => {
ready_channel.addEventListener('message', resolve, {once: true});
});
startPrerendering(next_url);
await ready_to_activate;
window.location.replace(new URL(next_url, window.location));
}
function prerenderedPage() {
document.addEventListener('prerenderingchange', () => {
document.documentElement.classList.add('incoming');
requestAnimationFrame(takeScreenshot);
});
ready_channel.postMessage('readyToActivateMessage');
ready_channel.close();
}
function implementsSpeculationRules() {
return ('supports' in HTMLScriptElement) &&
HTMLScriptElement.supports('speculationrules');
}
</script>
</html>