Skip to Content
UsageCDPPlaywright

Playwright

Use Lightpanda with Playwright  via the Chrome DevTools Protocol  (CDP), in JavaScript or Python.

More examples in demo/playwright  (JavaScript).

Connect Playwright

Start Lightpanda as a local CDP server (find all options in the serve command reference):

lightpanda serve --host 127.0.0.1 --port 9222

Connect Playwright:

import { chromium } from 'playwright-core'; const browser = await chromium.connectOverCDP('ws://127.0.0.1:9222'); const context = await browser.newContext({}); const page = await context.newPage(); await page.goto('https://wikipedia.com/'); const title = await page.locator('h1').textContent(); console.log(title); await page.close(); await context.close(); await browser.close();

Lightpanda commands

Lightpanda adds its own CDP commands, the LP domain. Playwright sends them through a CDP session: open one on the page and send the command by name.

A selection of commands, by task:

TaskCommand
Get the page as Markdown, HTML, PNG or PDF, after your clicks and form fillsLP.dump
Get a compact outline of the page, with node IDsLP.getSemanticTree
Click or fill a node by its IDLP.clickNode, LP.fillNode
Tell a blocked or broken page from an empty oneLP.getPageStatus
Skip images, iframes or other sub-resources for this connectionLP.configureLoading

Find every command, with its parameters and result, in the LP domain reference.

In the local JavaScript example, after page.goto, add:

const client = await context.newCDPSession(page); const { content } = await client.send('LP.dump', { format: 'markdown' }); console.log(content);