1import chalk from "chalk"; 2import { join } from "path"; 3import { readFileSync } from "fs"; 4 5let playwright; 6try { 7 // @ts-ignore-error 8 playwright = await import("playwright"); 9} 10catch (error) { 11 throw new Error("Playwright is expected to be installed manually before running this script"); 12} 13 14// Turning this on will leave the Chromium browser open, giving you the 15// chance to open up the web inspector. 16const debugging = false; 17 18/** @type {["chromium", "firefox"]} */ 19const browsers = ["chromium", "firefox"]; 20 21for (const browserType of browsers) { 22 const browser = await playwright[browserType].launch({ headless: !debugging }); 23 const context = await browser.newContext(); 24 const page = await context.newPage(); 25 26 /** @type {(err: Error) => void} */ 27 const errorCaught = err => { 28 console.error(chalk.red("There was an error running built/typescript.js in " + browserType)); 29 console.log(err.toString()); 30 process.exitCode = 1; 31 }; 32 33 // @ts-ignore-error 34 page.on("error", errorCaught); 35 page.on("pageerror", errorCaught); 36 37 await page.setContent(` 38 <html> 39 <script>${readFileSync(join("built", "local", "typescript.js"), "utf8")}</script> 40 </html> 41 `); 42 43 if (!debugging) { 44 await browser.close(); 45 } 46 else { 47 console.log("Not closing the browser, you'll need to exit the process in your terminal manually"); 48 } 49 console.log(`${browserType} :+1:`); 50} 51