Skip to main content
Glama
screenshot.ts1.33 kB
import { chromium } from "playwright"; interface ScreenshotParams { url: string; fullPage?: boolean; width?: number; height?: number; } interface ScreenshotResult { url: string; base64: string; width: number; height: number; timestamp: string; } export async function screenshot( params: ScreenshotParams ): Promise<ScreenshotResult> { const { url, fullPage = false, width = 1920, height = 1080 } = params; const browser = await chromium.launch({ headless: true }); const page = await browser.newPage({ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", }); try { await page.setViewportSize({ width, height }); await page.goto(url, { waitUntil: "networkidle", timeout: 30000 }); await page.waitForTimeout(1000); const screenshotBuffer = await page.screenshot({ fullPage, type: "png", }); const dimensions = await page.evaluate(() => ({ width: document.documentElement.scrollWidth, height: document.documentElement.scrollHeight, })); return { url, base64: screenshotBuffer.toString("base64"), width: fullPage ? dimensions.width : width, height: fullPage ? dimensions.height : height, timestamp: new Date().toISOString(), }; } finally { await browser.close(); } }

Implementation Reference

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/alucardeht/isis-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server