puppeteer for Go
Puppeteer-style page automation for Go, standard library only.
A from-scratch, standard-library-only Go toolkit inspired by the Node.js Puppeteer API. It fetches pages over net/http, parses the HTML with its own tokenizer and DOM builder, and queries the document with a real CSS selector engine — no cgo, no third-party modules, not even golang.org/x/net. Because a dependency-free Go library cannot embed a browser, it deliberately runs NO JavaScript and does NO rendering: there is no script execution, no layout/geometry/screenshots, and no live DOM — the tree is a static snapshot of the bytes the server sent. In practice it behaves like an HTTP client married to an HTML parser and a selector engine, ideal for scraping and automating server-rendered pages, following links, submitting forms and managing cookies and headers. Launch returns a Browser (cookie jar, shared headers, user agent, per-navigation timeout); Browser.NewPage returns a Page whose Goto fetches and parses a URL, and from which you select nodes, enumerate resolved Links and discover, fill and submit Forms. The import path is github.com/malcolmston/puppeteer and the package is named puppeteer.
Install
$ go get github.com/malcolmston/puppeteerQuick start
import "github.com/malcolmston/puppeteer"
browser, _ := puppeteer.Launch(nil)
defer browser.Close()
page := browser.NewPage()
if _, err := page.Goto("https://example.com"); err != nil {
log.Fatal(err)
}
fmt.Println("title:", page.Title())
links, _ := page.QuerySelectorAll("a[href]")
for _, a := range links {
href, _ := a.Attr("href")
fmt.Println("link:", href, "->", a.TextContent())
}Features
LaunchaBrowserwith aLaunchOptionscookie jar, shared headers, user agent, per-navigation timeout and custom transportBrowser.NewPagereturns aPage;Page.Goto/GotoContextfetch overnet/http, follow redirects and update cookies- Own HTML tokenizer + DOM builder —
Parsenever fails, recovering malformed input the way browsers do into aNodetree - A real CSS selector engine —
QuerySelectorandQuerySelectorAllsupporting type/*,#id,.class, attribute and combinator selectors - Structural pseudo-classes including the
:nth-child()An+Bmicrosyntax (odd,even,2n+1,-n+3) Elementhandles —TextContent,InnerHTML,OuterHTML,Attr/Attributes,ClassList/HasClassand node-relative queries- DOM traversal —
Children,Parent,Next,Prev,ClosestandMatches - Resolved
Links— everya[href]turned into an absolute URL against the page's location - Form automation —
Forms,FormBySelector,FillForm, thenBuildRequestorSubmit(GET query or POST body) - Cookies & headers —
Cookies,SetCookies,SetUserAgent,SetExtraHTTPHeadersover anet/http/cookiejar - No JavaScript, no rendering — no script execution, no layout/geometry/screenshots, no live DOM; a static snapshot of server-sent bytes
- Zero dependencies — pure Go standard library, nothing to audit but the toolchain