MCPcopy
hub / github.com/mxschmitt/playwright-go

github.com/mxschmitt/playwright-go @v0.6100.0 sqlite

repository ↗ · DeepWiki ↗ · release v0.6100.0 ↗
2,848 symbols 11,628 edges 160 files 778 documented · 27%
README

🎭 Playwright for

PkgGoDev License Go Report Card Build Status Tests Join Discord Coverage Status Chromium version Firefox version WebKit version

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 149.0.7827.55 :white_check_mark: :white_check_mark: :white_check_mark:
WebKit 26.5 :white_check_mark: :white_check_mark: :white_check_mark:
Firefox 151.0 :white_check_mark: :white_check_mark: :white_check_mark:

Headless 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 (with OS dependencies if provide --with-deps). 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/playwright@v0.xxxx.x install --with-deps
# Or
go install github.com/mxschmitt/playwright-go/cmd/playwright@v0.xxxx.x
playwright install --with-deps

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

err := playwright.Install()

Capabilities

Playwright is built to automate the broad and growing set of web browser capabilities used by Single Page Apps and Progressive Web Apps.

  • Scenarios that span multiple pages, domains and iframes
  • Auto-wait for elements to be ready before executing actions (like click, fill)
  • Intercept network activity for stubbing and mocking network requests
  • Emulate mobile devices, geolocation, permissions
  • Support for web components via shadow-piercing selectors
  • Native input events for mouse and keyboard
  • Upload and download files

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)
    }
}

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.

Is Playwright for Go ready?

We are ready for your feedback, but we are still covering Playwright Go with the tests.

Resources

Extension points exported contracts — how you extend this code

BindingCallFunction (FuncType)
BindingCallFunction represents the func signature of an exposed binding call func
binding_call.go
EventEmitter (Interface)
(no doc) [1 implementers]
event_emitter.go
BindingCall (Interface)
(no doc) [1 implementers]
binding_call.go

Core symbols most depended-on inside this repo

Send
called by 247
transport.go
Close
called by 149
transport.go
createElement
called by 113
tests/assets/modernizr.js
On
called by 102
event_emitter.go
fromChannel
called by 75
connection.go
Emit
called by 63
event_emitter.go
addTest
called by 52
tests/assets/modernizr.js
testAllProps
called by 41
tests/assets/modernizr.js

Shape

Method 1,483
Function 882
Struct 409
Interface 42
TypeAlias 31
FuncType 1

Languages

Go99%
TypeScript1%

Modules by API surface

generated-interfaces.go641 symbols
generated-structs.go301 symbols
page.go152 symbols
tests/page_test.go79 symbols
browser_context.go78 symbols
locator.go75 symbols
frame.go68 symbols
generated-enums.go60 symbols
tests/locator_test.go48 symbols
helpers.go43 symbols
tests/utils_test.go41 symbols
element_handle.go41 symbols

Dependencies from manifests, versioned

github.com/davecgh/go-spewv1.1.1 · 1×
github.com/deckarep/golang-set/v2v2.8.0 · 1×
github.com/go-jose/go-jose/v3v3.0.5 · 1×
github.com/go-stack/stackv1.8.1 · 1×
github.com/h2non/filetypev1.1.3 · 1×
github.com/kr/prettyv0.3.1 · 1×
github.com/orisano/pixelmatchv0.0.0-2023091404251 · 1×
github.com/pmezard/go-difflibv1.0.0 · 1×
github.com/rogpeppe/go-internalv1.11.0 · 1×

For agents

$ claude mcp add playwright-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact