import "@johnlindquist/kit"
const { chromium }: typeof import("playwright") = await npm(
"playwright"
)
let urlFromUser = await arg("Enter the URL to screenshot");
if (!urlFromUser.match(/^https?:\/\//)) {
urlFromUser = `http://${urlFromUser}`;
}
const pathObj = path.parse(urlFromUser);
log(pathObj);
let timeout = 5_000;
const FOLDER = 'Downloads/screenshot-url';
const screenshotFolder = home(FOLDER);
const filename = `${pathObj.name}${pathObj.ext}.png`
const screenshotPath = home(FOLDER, filename);
const browser = await chromium.launch({ timeout, headless: false });
const context = await browser.newContext({ colorScheme: "dark" });
const page = await context.newPage();
await page.setViewportSize({
width: 800,
height: 600,
});
page.setDefaultTimeout(timeout);
try {
await page.goto(urlFromUser);
await page.screenshot({ path: screenshotPath })
await revealFile(screenshotFolder)
log(`Done`)
} catch (error) {
warn('error', error);
}
await browser.close();