All payments made in the preview are in test mode. Read more
▲ crawlflux

Guide

Run Playwright on Lambda — without shipping a browser

Bundling Chromium into a serverless function means fighting package size limits, missing system libraries and slow cold starts. Laptops have the opposite problem: they sleep, change networks and run out of RAM at 20 tabs.

The fix is the same for both: keep your agent code where it is, and run the browser somewhere else.

The pattern

  1. Install playwright-core (client only, no browser download).
  2. Connect to a remote browser over CDP with your token in a header.
  3. Always close the browser in finally so the session ends with the invocation.

Lambda handler

shell
npm i playwright-core
handler.mjs
// handler.mjs — Lambda, Node 20 runtime
import { chromium } from "playwright-core";

export const handler = async (event) => {
  const browser = await chromium.connectOverCDP("wss://connect.crawlflux.dev", {
    headers: { Authorization: `Bearer ${process.env.CRAWLFLUX_TOKEN}` },
  });
  try {
    const ctx = browser.contexts()[0] ?? (await browser.newContext());
    const page = await ctx.newPage();
    await page.goto(event.url ?? "https://example.com", { waitUntil: "domcontentloaded" });
    return { statusCode: 200, body: JSON.stringify({ title: await page.title() }) };
  } finally {
    await browser.close();
  }
};

Set CRAWLFLUX_TOKEN as an environment variable (or pull it from Secrets Manager). Give the function a timeout longer than your slowest page load; memory can stay at the minimum because no browser runs locally.

Other runtimes

Common failures

See the full CDP quickstart or get a token.