/** * The page half of the lite-youtube smoke (see lite-youtube.html). Imports * the shipped dist bundle, checks the 16:9 box and the 44px play badge and * that no request went to YouTube, then activates the link and checks the * player that took its place. The iframe's own load is not awaited: the * smoke needs no network. */ export {}; // a module: the page awaits at its top level await import("../dist/lite-youtube.js"); await new Promise(resolve => setTimeout(resolve, 50)); const host = document.querySelector("pebble-lite-youtube") as HTMLElement; const ratio = (el: Element) => el.getBoundingClientRect().width / el.getBoundingClientRect().height; // by host: the page's own bundle is named after the package const fromYouTube = () => performance.getEntriesByType("resource").filter(e => /(youtube|ytimg|googlevideo|ggpht)\./.test(new URL(e.name).hostname)).length; const posterRatio = ratio(host); const badge = host.querySelector(".play")!.getBoundingClientRect(); const requestsBefore = fromYouTube(); host.querySelector("a")!.click(); const iframe = host.querySelector("iframe"); const verdict = { checks: { registered: customElements.get("pebble-lite-youtube") !== undefined, "the poster box is 16:9": Math.abs(posterRatio - 16 / 9) < 0.02, "the play badge is at least 44px": badge.width >= 44 && badge.height >= 44, "nothing came from YouTube before the click": requestsBefore === 0, "the click put the nocookie player in": iframe?.src === "https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?autoplay=1&playsinline=1", "the player is named": iframe?.title === "Bande-annonce : Maman, j’ai raté l’avion", "the player may autoplay and go fullscreen": iframe?.allow === "autoplay; encrypted-media; picture-in-picture" && iframe.allowFullscreen, "the player fills the 16:9 box": iframe !== null && Math.abs(ratio(iframe) - 16 / 9) < 0.02 && Math.abs(ratio(host) - 16 / 9) < 0.02, "focus moved into the player": document.activeElement === iframe, }, observed: { posterRatio, badge: [badge.width, badge.height], requestsBefore, src: iframe?.src }, }; document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`;