prerender-removed-during-navigation.html (2574B)
1 <!DOCTYPE html> 2 <html class="reftest-wait"> 3 <title>View transitions: cross-document navigation to a prerender cancelled before commit</title> 4 <link rel="help" href="https://drafts.csswg.org/css-view-transitions-2/"> 5 <link rel="author" href="mailto:bokan@chromium.org"> 6 <link rel="match" href="prerender-removed-during-navigation-ref.html"> 7 <script src="/common/utils.js"></script> 8 <script src="/common/reftest-wait.js"></script> 9 <script src="/speculation-rules/resources/utils.js"></script> 10 <script src="/speculation-rules/prerender/resources/utils.js"></script> 11 <style> 12 @view-transition { 13 navigation: auto; 14 } 15 html { 16 background-color: red; 17 } 18 html.outgoing { 19 background-color: cornflowerblue; 20 } 21 html.incoming { 22 background-color: hotpink; 23 } 24 ::view-transition { 25 background-color: limegreen; 26 } 27 ::view-transition-new(root) { 28 transform: translateY(55vh); 29 animation: none; 30 opacity: 1; 31 } 32 ::view-transition-old(root) { 33 transform: translateY(-55vh); 34 animation: none; 35 opacity: 1; 36 } 37 ::view-transition-group(root) { 38 animation-duration: 300s; 39 } 40 </style> 41 <script> 42 const params = new URLSearchParams(location.search); 43 const uid = params.has('uid') ? params.get('uid') : token(); 44 const ready_channel = new PrerenderChannel('ready-to-activate', uid); 45 46 if (!implementsSpeculationRules()) { 47 onload = () => { 48 document.body.innerText = 'This test requires speculation rules.'; 49 takeScreenshot(); 50 } 51 } else { 52 if (!params.has('next')) { 53 onload = () => requestAnimationFrame(() => requestAnimationFrame(runTest)); 54 } else if (document.prerendering) { 55 onload = prerenderedPage; 56 } else { 57 onload = incomingPage; 58 } 59 } 60 61 async function runTest() { 62 document.documentElement.classList.add('outgoing'); 63 const next_url = 64 new URL(`prerender-removed-during-navigation.html?next&uid=${uid}`, window.location).href; 65 66 const ready_to_activate = new Promise(resolve => { 67 ready_channel.addEventListener('message', resolve, {once: true}); 68 }); 69 70 let prerender_script = startPrerendering(next_url); 71 72 await ready_to_activate; 73 74 onpageswap = () => { 75 prerender_script.remove(); 76 } 77 78 window.location.replace(new URL(next_url, window.location)); 79 } 80 81 function prerenderedPage() { 82 ready_channel.postMessage('readyToActivateMessage'); 83 ready_channel.close(); 84 } 85 86 function incomingPage() { 87 document.documentElement.classList.add('incoming'); 88 requestAnimationFrame(takeScreenshot); 89 } 90 91 function implementsSpeculationRules() { 92 return ('supports' in HTMLScriptElement) && 93 HTMLScriptElement.supports('speculationrules'); 94 } 95 </script> 96 </html>