request-picture-in-picture.html (998B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/speculation-rules/prerender/resources/utils.js"></script> 5 <video id="target" 6 onloadstart="loadstart()" src="/media/test.webm"></video> 7 <script> 8 9 assert_true(document.prerendering); 10 11 const params = new URLSearchParams(location.search); 12 const uid = params.get('uid'); 13 14 async function requestPictureInPicture() { 15 const bc = new PrerenderChannel('prerender-channel', uid); 16 17 try { 18 await target.requestPictureInPicture(); 19 bc.postMessage('unexpected success'); 20 } catch (err) { 21 if (err.name == 'InvalidStateError') 22 bc.postMessage('Metadata for the video element are not loaded yet'); 23 else 24 bc.postMessage(err.message); 25 } finally { 26 bc.close(); 27 } 28 } 29 30 function loadstart() { 31 // Wait some time to give the test a chance to load the data and fail the test. 32 setTimeout(() => { requestPictureInPicture(); }, 100); 33 } 34 </script>