puppeteer for Go

github.com/malcolmston/puppeteer

Puppeteer-style page automation for Go, standard library only.

 GitHubports puppeteer/puppeteer

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

shell
$ go get github.com/malcolmston/puppeteer

Quick start

main.go
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

  • Launch a Browser with a LaunchOptions cookie jar, shared headers, user agent, per-navigation timeout and custom transport
  • Browser.NewPage returns a Page; Page.Goto / GotoContext fetch over net/http, follow redirects and update cookies
  • Own HTML tokenizer + DOM builder — Parse never fails, recovering malformed input the way browsers do into a Node tree
  • A real CSS selector engine — QuerySelector and QuerySelectorAll supporting type/*, #id, .class, attribute and combinator selectors
  • Structural pseudo-classes including the :nth-child() An+B microsyntax (odd, even, 2n+1, -n+3)
  • Element handles — TextContent, InnerHTML, OuterHTML, Attr/Attributes, ClassList/HasClass and node-relative queries
  • DOM traversal — Children, Parent, Next, Prev, Closest and Matches
  • Resolved Links — every a[href] turned into an absolute URL against the page's location
  • Form automation — Forms, FormBySelector, FillForm, then BuildRequest or Submit (GET query or POST body)
  • Cookies & headers — Cookies, SetCookies, SetUserAgent, SetExtraHTTPHeaders over a net/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
puppeteer