Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork207
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
License
playwright-community/playwright-go
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
🎭Playwright for
Looking for maintainers and seehere. Thanks!
API reference |Example recipes
Playwright is a Go library to automateChromium,Firefox andWebKit with a single API. Playwright is built to enable cross-browser web automation that isever-green,capable,reliable andfast.
| Linux | macOS | Windows | |
|---|---|---|---|
| Chromium 136.0.7103.25 | ✅ | ✅ | ✅ |
| WebKit 18.4 | ✅ | ✅ | ✅ |
| Firefox 137.0 | ✅ | ✅ | ✅ |
Headless execution is supported for all the browsers on all platforms.
go get -u github.com/playwright-community/playwright-go
Install the playwright driver and browsers (with OS dependencies if provide--with-deps).Note that you should replace the version number0.xxxx.x with the version used in your currentgo.mod. Each minor version upgrade requires a specific Playwright driver version.
go run github.com/playwright-community/playwright-go/cmd/playwright@v0.xxxx.x install --with-deps# Orgo install github.com/playwright-community/playwright-go/cmd/playwright@v0.xxxx.xplaywright install --with-depsAlternatively, 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()
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 page, 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
The following example crawls the current top voted items fromHacker News.
package mainimport ("fmt""log""github.com/playwright-community/playwright-go")funcmain() {pw,err:=playwright.Run()iferr!=nil {log.Fatalf("could not start playwright: %v",err)}browser,err:=pw.Chromium.Launch()iferr!=nil {log.Fatalf("could not launch browser: %v",err)}page,err:=browser.NewPage()iferr!=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()iferr!=nil {log.Fatalf("could not get entries: %v",err)}fori,entry:=rangeentries {title,err:=entry.Locator("td.title > span > a").TextContent()iferr!=nil {log.Fatalf("could not get text content: %v",err)}fmt.Printf("%d: %s\n",i+1,title)}iferr=browser.Close();err!=nil {log.Fatalf("could not close browser: %v",err)}iferr=pw.Stop();err!=nil {log.Fatalf("could not stop Playwright: %v",err)}}
Refer to theDockerfile.example to build your own docker image.
- Refer tohelper_test.go for End-To-End testing
- Downloading files
- End-To-End testing a website
- Executing JavaScript in the browser
- Emulate mobile and geolocation
- Parallel scraping using a WaitGroup
- Rendering a PDF of a website
- Scraping HackerNews
- Take a screenshot
- Record a video
- Monitor network activity
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 (seehere) 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.
We are ready for your feedback, but we are still covering Playwright Go with the tests.
About
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.