Playwright
Use Lightpanda with Playwright via the Chrome DevTools Protocol (CDP), in JavaScript or Python.
More examples in demo/playwright (JavaScript).
Connect Playwright
Local
Start Lightpanda as a local CDP server (find all options in the serve command reference):
lightpanda serve --host 127.0.0.1 --port 9222Connect Playwright:
JavaScript
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:
| Task | Command |
|---|---|
| Get the page as Markdown, HTML, PNG or PDF, after your clicks and form fills | LP.dump |
| Get a compact outline of the page, with node IDs | LP.getSemanticTree |
| Click or fill a node by its ID | LP.clickNode, LP.fillNode |
| Tell a blocked or broken page from an empty one | LP.getPageStatus |
| Skip images, iframes or other sub-resources for this connection | LP.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);