Skip to Content
UsageCDPChromedp

Chromedp

Use Lightpanda with Chromedp , a Go client for the Chrome DevTools Protocol  (CDP).

The examples on this page use the API of Chromedp v0.23.0  and later, which requires Go 1.25.

More examples in demo/chromedp .

Connect chromedp

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 Chromedp using remote.NewAllocator:

package main import ( "context" "log" "github.com/chromedp/chromedp" "github.com/chromedp/chromedp/remote" ) func main() { ctx, cancel := remote.NewAllocator(context.Background(), "ws://127.0.0.1:9222", remote.NoModifyURL, ) defer cancel() ctx, cancel = chromedp.NewContext(ctx) defer cancel() if err := chromedp.Do(ctx, chromedp.Navigate("https://wikipedia.com/")); err != nil { log.Fatalf("Failed loading the page: %v", err) } title, err := chromedp.Run(ctx, chromedp.Title()) if err != nil { log.Fatalf("Failed getting page's title: %v", err) } log.Println("Got title of:", title) }

Lightpanda commands

Lightpanda adds its own CDP commands, the LP domain. Chromedp sends them by name with the target’s Call method, inside a chromedp.Func.

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 example, replace the chromedp.Do and chromedp.Run calls with:

var res struct { Content string `json:"content"` } if err := chromedp.Do(ctx, chromedp.Navigate("https://wikipedia.com/"), chromedp.Func(func(ctx context.Context, t *chromedp.Target) error { return t.Call(ctx, "LP.dump", map[string]any{"format": "markdown"}, &res) }), ); err != nil { log.Fatalf("Failed dumping the page: %v", err) } log.Println(res.Content)