import { existsSync } from "node:fs"; import { type BrowserType, chromium, firefox, type Page, } from "@playwright/test"; import { describe, expect, it } from "vitest"; const chromePath = "C:/Program Files/Google/Chrome/Application/chrome.exe"; describe("ui widget browser layout", () => { it("lets unsandboxed srcdoc widgets call parent window.pi in Chrome and Firefox", async () => { for (const browser of browsers()) { const result = await withBrowser(browser, async (page) => { await page.setContent(bridgeProbeHtml()); await page.waitForFunction(() => window.calls?.length === 1); return await page.evaluate(() => window.calls[0]); }); expect(result).toEqual({ from: "srcdoc", sameOrigin: true }); } }, 120_000); it("keeps over-wide iframe content bounded at phone width in Chrome and Firefox", async () => { for (const browser of browsers()) { const result = await withBrowser(browser, async (page) => { await page.setViewportSize({ width: 390, height: 760 }); await page.setContent(layoutProbeHtml()); await page.waitForFunction( () => document.querySelector("iframe")?.clientHeight === 600, ); return await page.evaluate(() => ({ viewport: document.documentElement.clientWidth, scrollWidth: document.documentElement.scrollWidth, iframeHeight: document .querySelector("iframe") ?.getBoundingClientRect().height, })); }); expect(result).toEqual({ viewport: 390, scrollWidth: 390, iframeHeight: 600, }); } }, 120_000); }); function browsers(): Array<{ name: string; type: BrowserType; executablePath?: string; }> { return [ ...(existsSync(chromePath) ? [{ name: "chrome", type: chromium, executablePath: chromePath }] : []), { name: "firefox", type: firefox }, ]; } async function withBrowser( browser: { name: string; type: BrowserType; executablePath?: string }, fn: (page: Page) => Promise, ): Promise { const instance = await browser.type.launch({ headless: true, executablePath: browser.executablePath, }); try { const page = await instance.newPage(); return await fn(page); } finally { await instance.close(); } } function bridgeProbeHtml(): string { const srcdoc = "", ``, ].join(""); } function layoutProbeHtml(): string { const srcdoc = [ "", "
x
y
", "", ].join(""); }