安装命令里的 v0.xxxx.x 要换成 go.mod 中实际使用的版本,每个小版本升级都对应特定的 Playwright driver 版本;除 go get 外还必须单独安装 Playwright driver 和浏览器,否则无法启动;缺少系统依赖时需加 --with-deps 或手动安装,而从代码调用 playwright.Install() 不会自动装系统依赖。
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.
go get -u github.com/mxschmitt/playwright-go
go run github.com/mxschmitt/playwright-go/cmd/[email protected] install --with-depsREADME 未说明显存或 GPU 要求;支持 Linux、macOS、Windows 上的 Chromium、Firefox、WebKit,均支持无头与有头模式。
用一套 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.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-depsNew APIs
v1.63:
Page.FrameLocator()andFrame.FrameLocator()without a selector search every frame.Locator.Visible().Page.OnDialogClosedandBrowserContext.OnDialogClosed("dialogclosed"event).HttpCredentialsListcontext option (Browser, BrowserType and APIRequest) for different credentials per origin.Opfsoption onBrowserContext.StorageStateandAPIRequestContext.StorageState(Origin.Opfs []OPFSEntry).AriaSnapshotsandScreenSnapshotsoptions onTracing.Start.
v1.64:
APIRequestContext.AddCookies,CookiesandClearCookies.Locator.Within,Page.GetByRef.IncludeShadowoption onPage.ContentandFrame.Content.Page.WebMCP()andFrame.WebMCP()withWebMCP.ToolsandWebMCP.CallTool.RecordVideo.Fps,ScreencastStartOptions.Fps, andStyle(ScreencastActionStyle) for screencast and video actions.SignCountonVirtualCredentialandCredentialsCreateOptions.
Behavior changes
- Protocol call ids are now strings (
<prefix>@<n>), as required by the v1.63+ driver. httpCredentialsis 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 unsupportedGetBy*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). StorageStatePathsends the file's JSON as is, so IndexedDB and OPFS entries reach the driver.Screencast.StartwithPathnow saves the video onStop.- The traces dir and tracing stack counter also apply to
BrowserContext.Request().Tracing(). WaitForLoadStateandWaitForURLno 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
Unrouteand in-flight route interception (#643).
What's Changed
- fix: flaky navigation timeouts caused by a lost wakeup in WaitForLoadState and WaitForURL by @myrjola in https://github.com/mxschmitt/playwright-go/pull/641
- fix: leave unbound guids in event payloads untouched instead of closing the connection by @pcockrill in https://github.com/mxschmitt/playwright-go/pull/642
- test: live CDP download guid coverage and unroute interception deadlock fix by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/643
- chore: roll to Playwright v1.64.1 by @zacker150 in https://github.com/mxschmitt/playwright-go/pull/645
New Contributors
- @myrjola made their first contribution in https://github.com/mxschmitt/playwright-go/pull/641
- @pcockrill made their first contribution in https://github.com/mxschmitt/playwright-go/pull/642
- @zacker150 made their first contribution in https://github.com/mxschmitt/playwright-go/pull/645
Full Changelog: https://github.com/mxschmitt/playwright-go/compare/v0.6201.1...v0.6401.0
- 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.ExpectResponseacceptfunc(Request) bool/func(Response) boolpredicates again, so waits can filter onMethod(),Status(), headers or post data instead of the URL alone (#627).ToHaveText,ToContainTextandToHaveClassaccept mixed lists of strings and regexps ([]any{"alpha", regexp.MustCompile("bet.")}), matching upstream'sArray<string|RegExp>. Homogeneous[]string/[]*regexp.Regexpare unaffected.ExpectEvent/WaitForEventreject 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 onPage,Frame,LocatorandFrameLocator,GetByRole'sName/Descriptionoptions, and theHasText/HasNotTextlocator options report an invalid argument type throughLocator.Err()instead of panicking.
Internal
- Driver protocol messages are decoded with
encoding/jsonrather than the vendored Go 1.6 JSON fork ingo-jose/v3— about 20% faster on large frames at the same allocation count.github.com/go-jose/go-jose/v3andgolang.org/x/cryptoleave the module graph (investigated for #631).
What's Changed
- feat: add release-playwright skill and CLAUDE.md by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/630
- test: stop TestShouldUploadAFolderRemote from eating the package timeout by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/632
- fix: accept Request/Response predicates in Page.ExpectRequest/ExpectResponse by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/633
- fix: accept mixed string/regexp lists in ToHaveText, ToContainText, ToHaveClass by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/634
- chore: decode driver protocol messages with encoding/json by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/636
- ci: stop commits to main from serializing into one concurrency queue by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/638
- chore: modernize the docs site and refresh the README by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/639
- docs: fix the coverage badge and link the CI badge by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/640
- fix: report invalid GetBy*/HasText argument types instead of panicking by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/637
- fix: reject unusable event predicates instead of panicking in the dispatch goroutine by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/635
Full Changelog: https://github.com/mxschmitt/playwright-go/compare/v0.6201.0...v0.6201.1
- 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-depsNew APIs
ScrollMode(auto/none) on the affected action options.- WebP screenshots, including path-based format inference.
- Virtual WebAuthn credentials in
BrowserContextstorage 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.
responseEndTimingis preserved in API responses.
Fixes
- A pending protocol callback is now removed when its transport send fails (previously leaked).
PLAYWRIGHT_CLI_PATHis compatible with more external driver layouts.- Fixed a data race on
Page's frame list (#626).
What's Changed
- ci: re-run flaky tests via gotestsum while surfacing them on flakiness.io by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/621
- [codex] fix page frames data race by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/626
- docs(skill): require roll PRs to note they were skill-generated by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/629
- chore: roll to Playwright v1.62.1 by @lucastsudaka in https://github.com/mxschmitt/playwright-go/pull/628
New Contributors
- @lucastsudaka made their first contribution in https://github.com/mxschmitt/playwright-go/pull/628
Full Changelog: https://github.com/mxschmitt/playwright-go/compare/v0.6100.0...v0.6201.0
- 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-gotogithub.com/mxschmitt/playwright-go. Update your imports accordingly.What's Changed
- docs: fix broken links and tidy README/CONTRIBUTING by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/613
- ci: only cancel in-progress runs for pull requests by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/614
- test: add reusable withRetry helper for flaky WebKit folder upload by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/616
- feat: assemble driver from npm + nodejs.org instead of deprecated CDN by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/615
- chore: roll to Playwright v1.61.1 by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/617
- feat: allow PLAYWRIGHT_CLI_PATH to point directly at cli.js by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/618
- chore: migrate from playwright-community org to mxschmitt by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/619
- docs: fix coveralls badge not rendering in README by @mxschmitt in https://github.com/mxschmitt/playwright-go/pull/620
Full Changelog: https://github.com/mxschmitt/playwright-go/compare/v0.6000.0...v0.6100.0
- 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-depsFeatures
- Roll to Playwright v1.60.0 in https://github.com/playwright-community/playwright-go/pull/592
- Align Go client with upstream Playwright TypeScript client (v1.60.0) in https://github.com/playwright-community/playwright-go/pull/612
- Add
--no-shelloption to the driver runner in https://github.com/playwright-community/playwright-go/pull/571 - Add
WithDepsoption to install system dependencies in https://github.com/playwright-community/playwright-go/pull/572
Bug fixes — deadlocks & data races
- Prevent deadlock when reading request headers in a route handler (#519) in https://github.com/playwright-community/playwright-go/pull/608
- Prevent deadlock when calling blocking methods inside event handlers in https://github.com/playwright-community/playwright-go/pull/603
- Prevent jsonPipe deadlock that hung remote connections in https://github.com/playwright-community/playwright-go/pull/602
- Do not hold the eventRegister lock while running event handlers in https://github.com/playwright-community/playwright-go/pull/604
- Identify event listeners by closure, not shared code pointer (#323) in https://github.com/playwright-community/playwright-go/pull/606
- Fix data race between routing and closing context in https://github.com/playwright-community/playwright-go/pull/567
Bug fixes — other
- Resolve
Locator.Evaluatewith attached state to match upstream in https://github.com/playwright-community/playwright-go/pull/605 - Resolve relative
recordVideo.dirto an absolute path in https://github.com/playwright-community/playwright-go/pull/607 - Handle missing timing fields in the CDP response in https://github.com/playwright-community/playwright-go/pull/581
- Handle null response metadata in https://github.com/playwright-community/playwright-go/pull/586
- Handle typed request header maps in https://github.com/playwright-community/playwright-go/pull/587
- Respect default timeout in
SetInputFiles; fix flakyTestPageCloseRacein https://github.com/playwright-community/playwright-go/pull/595 - Prevent panic in
EvaluateHandlewhen it returns anElementHandlein https://github.com/playwright-community/playwright-go/pull/597
CI, chores & tests
- Update
go-jose/go-jose/v3to v3.0.5 in https://github.com/playwright-community/playwright-go/pull/588 - Update GitHub Actions to latest versions in https://github.com/playwright-community/playwright-go/pull/598
- Add flakiness.io reporter to the test job in https://github.com/playwright-community/playwright-go/pull/596
- CI test stabilization in https://github.com/playwright-community/playwright-go/pull/609, https://github.com/playwright-community/playwright-go/pull/610, https://github.com/playwright-community/playwright-go/pull/611
- Add
.claude/to.gitignorein https://github.com/playwright-community/playwright-go/pull/594
Full Changelog: https://github.com/playwright-community/playwright-go/compare/v0.5700.1...v0.6000.0
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
🎭 Playwright for
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.
| Linux | macOS | Windows | |
|---|---|---|---|
| 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,GetByTextandGetByTestIdinstead of brittle CSS paths. - Auto-wait — actions such as
ClickandFillwait for the element to be actionable, and web-first assertions created viaplaywright.NewPlaywrightAssertions()retry until the condition is met. No arbitrary sleeps. - Full isolation — every
BrowserContextis the equivalent of a brand new browser profile at near-zero overhead. Save the authentication state once withcontext.StorageState()and reuse it everywhere. - Trace Viewer — record a trace via
context.Tracing()and inspect DOM snapshots, network traffic and console logs afterwards withplaywright 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
- Refer to helper_test.go for End-To-End testing
- Downloading files
- End-To-End testing a website
- Executing JavaScript in the browser
- Emulate mobile and geolocation
- Monitor network activity
- Parallel scraping using a WaitGroup
- Rendering a PDF of a website
- Scraping HackerNews
- Take a screenshot
- Using a locally installed Chrome
- Record a video
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