Puppeteer
Use Lightpanda with Puppeteer via the Chrome DevTools Protocol (CDP).
More examples in demo/puppeteer .
Connect Puppeteer
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 Puppeteer using browserWSEndpoint — the WebSocket URL Puppeteer uses to attach to an already-running browser instead of launching one itself:
'use strict'
import puppeteer from 'puppeteer-core'
const browser = await puppeteer.connect({
browserWSEndpoint: 'ws://127.0.0.1:9222',
})
const context = await browser.createBrowserContext()
const page = await context.newPage()
await page.goto('https://wikipedia.com/')
const title = await page.title()
console.log(title)
await page.close()
await context.close()
await browser.disconnect()Lightpanda commands
Lightpanda adds its own CDP commands, the LP domain. Puppeteer 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 example, after page.goto, add:
const client = await page.createCDPSession()
const { content } = await client.send('LP.dump', { format: 'markdown' })
console.log(content)