playwright-go

mxschmittMIT活跃维护

Playwright 的 Go 语言绑定,用一套 API 同时驱动 Chromium、Firefox 和 WebKit,方便 Go 开发者写浏览器自动化脚本和端到端测试。

Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.

v0.6401.0发布于 2026-11-05 00:06 UTC3,542star +3 / 7 天250fork同步于 2026-11-10 11:40 UTC

怎么上手

由 README 提炼,执行前请确认
go get -u github.com/mxschmitt/playwright-go
go run github.com/mxschmitt/playwright-go/cmd/[email protected] install --with-deps
硬件要求按 README 说明

README 未说明显存或 GPU 要求;支持 Linux、macOS、Windows 上的 Chromium、Firefox、WebKit,均支持无头与有头模式。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用一套 Go API 控制 Chromium、Firefox 和 WebKit 的浏览器自动化库

Playwright 的 Go 语言绑定,用一套 API 同时驱动 Chromium、Firefox 和 WebKit,方便 Go 开发者写浏览器自动化脚本和端到端测试。

核心能力

  • 用 GetByRole、GetByText 等语义定位器替代脆弱的 CSS 路径
  • Click、Fill 等操作自动等待元素可交互,断言自动重试
  • 每个 BrowserContext 相当于全新浏览器配置,可保存并复用登录态
  • 用 context.Tracing() 录制 trace,再用 show-trace 查看 DOM 快照与网络
  • 用 page.Route() 拦截和 mock 网络请求,并支持移动端、地理位置等模拟

容易踩的坑

安装命令里的 v0.xxxx.x 要换成 go.mod 中实际使用的版本,每个小版本升级都对应特定的 Playwright driver 版本;除 go get 外还必须单独安装 Playwright driver 和浏览器,否则无法启动;缺少系统依赖时需加 --with-deps 或手动安装,而从代码调用 playwright.Install() 不会自动装系统依赖。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.6401.0
  1. v0.6401.0最新正式版2026-11-05 · 2026-11-05 00:06 UTC

    Roll to v1.64.1

    This release rolls the bundled Playwright driver from v1.62.1 to v1.64.1 (Chromium 156.0.8078.4, Firefox 157.0, WebKit 27.2) and ports the v1.63 and v1.64 client APIs. The Chromium update includes the fix for CVE-2026-79219.

    [!IMPORTANT] This release pins a new driver version. After upgrading, reinstall the driver:

    go run github.com/mxschmitt/playwright-go/cmd/[email protected] install --with-deps
    

    New APIs

    v1.63:

    • Page.FrameLocator() and Frame.FrameLocator() without a selector search every frame.
    • Locator.Visible().
    • Page.OnDialogClosed and BrowserContext.OnDialogClosed ("dialogclosed" event).
    • HttpCredentialsList context option (Browser, BrowserType and APIRequest) for different credentials per origin.
    • Opfs option on BrowserContext.StorageState and APIRequestContext.StorageState (Origin.Opfs []OPFSEntry).
    • AriaSnapshots and ScreenSnapshots options on Tracing.Start.

    v1.64:

    • APIRequestContext.AddCookies, Cookies and ClearCookies.
    • Locator.Within, Page.GetByRef.
    • IncludeShadow option on Page.Content and Frame.Content.
    • Page.WebMCP() and Frame.WebMCP() with WebMCP.Tools and WebMCP.CallTool.
    • RecordVideo.Fps, ScreencastStartOptions.Fps, and Style (ScreencastActionStyle) for screencast and video actions.
    • SignCount on VirtualCredential and CredentialsCreateOptions.

    Behavior changes

    • Protocol call ids are now strings (<prefix>@<n>), as required by the v1.63+ driver.
    • httpCredentials is always sent to the driver as a list.
    • Locators derived from a locator that carries an error (First, Last, Nth, Filter, Visible, And, Or, …) keep that error, including the existing errors for unsupported GetBy* arguments.
    • The bundled Node.js runtime moves to 24.21.0.

    Fixes

    • Locator assertion errors include the driver's custom error message (e.g. frameLocator() matched elements in multiple frames).
    • StorageStatePath sends the file's JSON as is, so IndexedDB and OPFS entries reach the driver.
    • Screencast.Start with Path now saves the video on Stop.
    • The traces dir and tracing stack counter also apply to BrowserContext.Request().Tracing().
    • WaitForLoadState and WaitForURL no longer miss a state recorded between the initial check and subscribing (#641).
    • Unknown guids in CDP event payloads pass through instead of failing (#642).
    • Fixed a deadlock between Unroute and in-flight route interception (#643).

    What's Changed

    New Contributors

    Full Changelog: https://github.com/mxschmitt/playwright-go/compare/v0.6201.1...v0.6401.0

  2. v0.6201.12026-08-17 · 2026-08-17 07:07 UTC
    查看更新说明

    Go-only patch release on top of the v1.62.1 driver. The bundled driver version is unchanged, so no reinstall is needed when upgrading from v0.6201.0.

    Four any-typed parameters accepted argument types the generated docs promised but the code did not handle, and each failed by panicking rather than reporting an error. All four now behave as documented.

    Fixes

    • Page.ExpectRequest / Page.ExpectResponse accept func(Request) bool / func(Response) bool predicates again, so waits can filter on Method(), Status(), headers or post data instead of the URL alone (#627).
    • ToHaveText, ToContainText and ToHaveClass accept mixed lists of strings and regexps ([]any{"alpha", regexp.MustCompile("bet.")}), matching upstream's Array<string|RegExp>. Homogeneous []string / []*regexp.Regexp are unaffected.
    • ExpectEvent / WaitForEvent reject the wait with a descriptive error when the predicate is unusable — not a function, wrong argument type, wrong return type, or panicking — instead of crashing the process from the library's own dispatch goroutine. A typed-nil predicate now means "no predicate".
    • The GetBy* family on Page, Frame, Locator and FrameLocator, GetByRole's Name/Description options, and the HasText/HasNotText locator options report an invalid argument type through Locator.Err() instead of panicking.

    Internal

    • Driver protocol messages are decoded with encoding/json rather than the vendored Go 1.6 JSON fork in go-jose/v3 — about 20% faster on large frames at the same allocation count. github.com/go-jose/go-jose/v3 and golang.org/x/crypto leave the module graph (investigated for #631).

    What's Changed

    Full Changelog: https://github.com/mxschmitt/playwright-go/compare/v0.6201.0...v0.6201.1

  3. v0.6201.02026-08-12 · 2026-08-12 21:41 UTC
    查看更新说明

    Roll to v1.62.1

    This release rolls the bundled Playwright driver to v1.62.1 (Chromium 151.0.7922.34, Firefox 153.0, WebKit 26.5).

    [!IMPORTANT] This release pins a new driver version. After upgrading, reinstall the driver:

    go run github.com/mxschmitt/playwright-go/cmd/[email protected] install --with-deps
    

    New APIs

    • ScrollMode (auto / none) on the affected action options.
    • WebP screenshots, including path-based format inference.
    • Virtual WebAuthn credentials in BrowserContext storage state.
    • APIResponse.Timing().ResponseEnd.
    • Locator.WaitForFunction.

    Behavior changes

    • Per-call timeouts are now sent through protocol metadata, as required by the v1.62 protocol.
    • Screencast frames are acknowledged only after their callback completes, preserving driver backpressure.
    • responseEndTiming is preserved in API responses.

    Fixes

    • A pending protocol callback is now removed when its transport send fails (previously leaked).
    • PLAYWRIGHT_CLI_PATH is compatible with more external driver layouts.
    • Fixed a data race on Page's frame list (#626).

    What's Changed

    New Contributors

    Full Changelog: https://github.com/mxschmitt/playwright-go/compare/v0.6100.0...v0.6201.0

  4. v0.6100.02026-06-26 · 2026-06-26 20:18 UTC
    查看更新说明

    Roll to v1.61.1

    This release rolls the bundled Playwright driver to v1.61.1 (Chromium 149.0.7827.55, Firefox 151.0, WebKit 26.5).

    [!IMPORTANT] This release pins a new driver version. After upgrading, reinstall the driver:

    go run github.com/mxschmitt/playwright-go/cmd/[email protected] install --with-deps
    

    [!NOTE] The module path has moved from github.com/playwright-community/playwright-go to github.com/mxschmitt/playwright-go. Update your imports accordingly.

    What's Changed

    Full Changelog: https://github.com/mxschmitt/playwright-go/compare/v0.6000.0...v0.6100.0

  5. v0.6000.02026-06-26 · 2026-06-26 01:33 UTC
    查看更新说明

    Roll to Playwright v1.60.0

    This release rolls the driver from Playwright v1.57.0 → v1.60.0 and brings the Go client in line with the upstream TypeScript client. Browser versions: Chromium 148.0.7778.96, Firefox 150.0.2, WebKit 26.4.

    [!IMPORTANT] Driver upgrade required. Reinstall the driver/browsers to match this version:

    go run github.com/playwright-community/playwright-go/cmd/[email protected] install --with-deps
    

    Features

    Bug fixes — deadlocks & data races

    Bug fixes — other

    CI, chores & tests

    Full Changelog: https://github.com/playwright-community/playwright-go/compare/v0.5700.1...v0.6000.0

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    🎭 Playwright for

    PkgGoDev License Go Tests Coverage Status Join DiscordChromium version Firefox version WebKit version

    Website | API reference | Example recipes

    Playwright is a Go library to automate Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.

    LinuxmacOSWindows
    Chromium 156.0.8078.4:white_check_mark::white_check_mark::white_check_mark:
    WebKit 27.2:white_check_mark::white_check_mark::white_check_mark:
    Firefox 157.0:white_check_mark::white_check_mark::white_check_mark:

    Headless and headed execution is supported for all the browsers on all platforms.

    Installation

    go get -u github.com/mxschmitt/playwright-go
    

    Install the Playwright driver and browsers (add --with-deps to also install the OS dependencies). Note that you should replace the version number 0.xxxx.x with the version used in your current go.mod. Each minor version upgrade requires a specific Playwright driver version.

    go run github.com/mxschmitt/playwright-go/cmd/[email protected] install --with-deps
    # Or
    go install github.com/mxschmitt/playwright-go/cmd/[email protected]
    playwright install --with-deps
    

    Alternatively, you can download the driver and browsers from your code. If your operating system lacks the browser dependencies you still need to install them manually, because installing system dependencies requires privileges.

    err := playwright.Install()
    

    Documentation

    https://playwright.dev/docs/intro

    The guides, concepts and API semantics are shared across all Playwright languages — only the code samples on that site are written in JavaScript.

    API Reference

    https://pkg.go.dev/github.com/mxschmitt/playwright-go

    Example

    The following example crawls the current top voted items from Hacker News.

    package main
    
    import (
    	"fmt"
    	"log"
    
    	"github.com/mxschmitt/playwright-go"
    )
    
    func main() {
    	pw, err := playwright.Run()
    	if err != nil {
    		log.Fatalf("could not start playwright: %v", err)
    	}
    	browser, err := pw.Chromium.Launch()
    	if err != nil {
    		log.Fatalf("could not launch browser: %v", err)
    	}
    	page, err := browser.NewPage()
    	if err != nil {
    		log.Fatalf("could not create page: %v", err)
    	}
    	if _, err = page.Goto("https://news.ycombinator.com"); err != nil {
    		log.Fatalf("could not goto: %v", err)
    	}
    	entries, err := page.Locator(".athing").All()
    	if err != nil {
    		log.Fatalf("could not get entries: %v", err)
    	}
    	for i, entry := range entries {
    		title, err := entry.Locator("td.title > span > a").TextContent()
    		if err != nil {
    			log.Fatalf("could not get text content: %v", err)
    		}
    		fmt.Printf("%d: %s\n", i+1, title)
    	}
    	if err = browser.Close(); err != nil {
    		log.Fatalf("could not close browser: %v", err)
    	}
    	if err = pw.Stop(); err != nil {
    		log.Fatalf("could not stop Playwright: %v", err)
    	}
    }
    

    Capabilities

    • Resilient locators — find elements the way a user sees the page with GetByRole, GetByLabel, GetByPlaceholder, GetByText and GetByTestId instead of brittle CSS paths.
    • Auto-wait — actions such as Click and Fill wait for the element to be actionable, and web-first assertions created via playwright.NewPlaywrightAssertions() retry until the condition is met. No arbitrary sleeps.
    • Full isolation — every BrowserContext is the equivalent of a brand new browser profile at near-zero overhead. Save the authentication state once with context.StorageState() and reuse it everywhere.
    • Trace Viewer — record a trace via context.Tracing() and inspect DOM snapshots, network traffic and console logs afterwards with playwright show-trace.
    • Network interception — stub and mock requests with page.Route(), or monitor all traffic of a page.
    • Emulation — mobile devices, geolocation, permissions, color scheme, locale and timezone.
    • Beyond the DOM — scenarios that span multiple pages, domains and iframes, shadow-piercing selectors, native mouse and keyboard input, file uploads and downloads.

    Docker

    Refer to the Dockerfile.example to build your own Docker image.

    More examples

    How does it work?

    Playwright is a Node.js library which uses:

    • Chrome DevTools Protocol to communicate with Chromium
    • Patched Firefox to communicate with Firefox
    • Patched WebKit to communicate with WebKit

    These patches are based on the original sources of the browsers and don't modify the browser behaviour, so the browsers are basically the same (see here) as you see them in the wild. The support for different programming languages is based on exposing a RPC server in the Node.js land which can be used to allow other languages to use Playwright without implementing all the custom logic.

    The bridge between Node.js and the other languages is basically a Node.js runtime combined with Playwright which gets shipped for each of these languages (around 50MB) and then communicates over stdio to send the relevant commands. This will also download the pre-compiled browsers.

    Other languages

    More comfortable in another programming language? Playwright is also available in