Extract data
Read a known page, validate structured values, and save output before releasing the browser.
Install the TypeScript SDK artifact and Playwright, and configure credentials using the Quickstart.
Save as extract.mjs and run node extract.mjs:
import assert from "node:assert/strict";
import { writeFile } from "node:fs/promises";
import { TabSail } from "tabsail";
import { chromium } from "playwright";
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" });
const result = {
title: await page.title(),
heading: await page.locator("h1").innerText(),
};
assert.equal(result.title, "Example Domain");
assert.equal(result.heading, "Example Domain");
await writeFile("result.json", JSON.stringify(result, null, 2));
await page.screenshot({ path: "result.png" });
console.log(session.id, result.title);
} finally {
await browser.close();
}
});Expected results: a validated title, result.json, result.png, and a released session after the owned scope finishes. The JSON and screenshot are saved on the machine running this script.
For a real extraction task, define and validate the output schema before saving results. Keep page content and screenshots out of logs when they contain sensitive information. Website downloads use the separate session file service.