onpageshow_message.html (1316B)
1 <html> 2 <head> 3 <meta charset="utf-8"> 4 <script> 5 addEventListener("pageshow", function() { 6 var bc = new BroadcastChannel("browser_browsingContext"); 7 function frameData() { 8 var win = SpecialPowers.wrap(frames[0]); 9 bc.postMessage( 10 { framesLength: frames.length, 11 browsingContextId: win.docShell.browsingContext.id, 12 outerWindowId: win.docShell.outerWindowID 13 }); 14 } 15 16 bc.onmessage = function(event) { 17 if (event.data == "createiframe") { 18 let frame = document.createElement("iframe"); 19 frame.src = "dummy_page.html"; 20 document.body.appendChild(frame); 21 frame.onload = frameData; 22 } else if (event.data == "nextpage") { 23 bc.close(); 24 location.href = "onload_message.html"; 25 } else if (event.data == "queryframes") { 26 frameData(); 27 } else if (event.data == "close") { 28 bc.postMessage("closed"); 29 bc.close(); 30 window.close(); 31 } 32 } 33 bc.postMessage("pageshow"); 34 }); 35 </script> 36 </head> 37 <body> 38 This file posts a message containing "pageshow" to a BroadcastChannel and 39 keep the channel open for commands. 40 </body> 41 </html>