Capture pages
Save a screenshot and PDF before releasing the browser.
Install the TypeScript SDK and Playwright from the Quickstart. Save as capture.mts and run node capture.mts.
import { chromium } from "playwright";
import { TabSail } from "tabsail";
const client = new TabSail();
await client.withSession({ timeoutSeconds: 300 }, async (session) => {
const grant = await client.sessions.connections.create(session.id, { type: "cdp" });
const browser = await chromium.connectOverCDP(grant.url);
try {
const context = browser.contexts()[0];
const page = context.pages()[0] ?? await context.newPage();
await page.goto("https://example.com", { waitUntil: "domcontentloaded" });
await page.getByRole("heading", { name: "Example Domain" }).waitFor();
await page.screenshot({ path: "page.png", fullPage: true });
await page.pdf({ path: "page.pdf", format: "A4", printBackground: true });
console.log("Saved page.png and page.pdf");
} finally {
await browser.close();
}
});Expected: page.png and page.pdf on your application's machine, followed by confirmed session release. For options, see Screenshots & PDF.