workflow() factory is the entry point for every Libretto automation. You wrap your Playwright logic in a typed handler, export the result, and the CLI (or your own runner) takes care of launching a browser, wiring up context, and invoking your handler.
workflow()
Creates a LibrettoWorkflow from a handler function.
LibrettoWorkflowContext and typed input, and must return a Promise<Output>.
LibrettoWorkflowContext<S>
The session identifier for this workflow run. Use it to correlate logs and state files.
A Playwright
Page instance ready for navigation and interaction.An optional generic services object. Defaults to
{}. Pass domain services (API clients, repositories, etc.) through here so your handler stays testable.Full example
Running with the CLI
Pass the file path and the exported name tolibretto run:
tsx, launches a Chromium browser, and calls your handler with the session context it constructs.
launchBrowser()
Launches a Playwright Chromium browser and returns a ready-to-use BrowserSession. Use this when you want to run workflows programmatically — outside the CLI — or when you need direct access to the Browser or BrowserContext objects.
LaunchBrowserArgs
A unique identifier for this browser session. Used to name the session state file written under
.libretto/sessions/.Whether to run Chromium in headless mode. Defaults to
false (visible window).The browser viewport size. Defaults to
{ width: 1366, height: 768 }.Path to a Playwright storage state JSON file (cookies, localStorage). Useful for resuming authenticated sessions.
BrowserSession return value
The underlying Playwright
Browser instance.The Playwright
BrowserContext created for this session.The initial
Page opened in the context. Pass this to your workflow handler.The remote debugging port Chromium is listening on.
Absolute path to the session state JSON file written by
launchBrowser.Closes the browser and releases all resources.
Programmatic usage
pause()
Pauses a running workflow so you can inspect browser state interactively, then resume from the CLI.
The session identifier. Must match the session name used when the workflow was started.
pause() is a no-op when NODE_ENV === "production". It is safe to leave pause() calls in your code without worrying about them blocking production runs.pause() writes a .paused signal file and polls for a .resume signal. Use the Libretto CLI to send the resume signal: