v0.3.3

Getting Started

Last updated


From go get to a first Markdown result: prerequisites, install, one Fetch call, and shutting browsers down.

Prerequisites


ItemRequirementWhy
Go1.25.0 or newerThe version declared in go.mod
OSmacOS or LinuxChrome path lookup and cookie decryption are implemented for these two platforms; elsewhere Fetch still runs headless with go-rod's own browser lookup, without SameSession or headed retry
Chrome / ChromiumInstalledmacOS looks for /Applications/Google Chrome.app or Chromium.app; Linux tries google-chrome, google-chrome-stable, chromium, chromium-browser in order
sqlite3Only for SameSessionReads the Chrome cookie database
security (macOS)Built inRetrieves the Chrome Safe Storage password, only for SameSession
secret-tool (Linux)libsecret-toolsSame purpose, only for SameSession

When no Chrome binary is found, go-rod falls back to a browser it downloads itself. SameSession still needs a local Chrome profile, because that is where the cookies come from.

Install


  1. go get github.com/pardnchiu/go-browser/core

The package lives in the core subdirectory and its package name is browser:
  1. import browser "github.com/pardnchiu/go-browser/core"

First call


  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. browser "github.com/pardnchiu/go-browser/core"
  7. )
  8. func main() {
  9. defer browser.Close()
  10. result, err := browser.Fetch(context.Background(), "https://example.com", 30*time.Second, nil)
  11. if err != nil {
  12. panic(err)
  13. }
  14. fmt.Println(result.Title)
  15. fmt.Println(result.Content)
  16. }

Passing nil for opt takes every default: headless first, up to three scroll passes, Markdown output, a two second idle wait. The URL needs a scheme and a dotted hostname, so http://localhost:8080 is rejected with invalid url.

Call Close before exit


Browser instances are cached and reused, and a background evictor reclaims them after five idle minutes. Calling browser.Close() before exit shuts all cached instances down immediately; skipping it leaves Chrome processes running until the evictor or the process exit cleans them up.

Next


中文