popup.html (432B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 Popup <input id="input"> 4 <script> 5 window.onload = async () => { 6 try { 7 if (!document.hasFocus()) { 8 const input = document.getElementById("input"); 9 input.focus(); 10 await new Promise(r => input.onfocus = r); 11 } 12 opener.postMessage(`focus = ${document.hasFocus()}`, "*"); 13 } catch(e) { 14 opener.postMessage(`${e.name}: $(e.message)`, "*"); 15 } 16 }; 17 </script> 18 </html>