Skip to content

Commit

Permalink
chore: roll to Playwright v1.47.0 (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
canstand authored Sep 6, 2024
1 parent 9a40c60 commit a1b6055
Show file tree
Hide file tree
Showing 31 changed files with 1,310 additions and 431 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version: ^1.19.9
go-version: oldstable
id: go
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
Expand All @@ -27,16 +27,17 @@ jobs:
# https://github.com/microsoft/playwright/issues/30705 is fixed.
os: [ubuntu-latest, windows-latest, macos-13]
browser: [chromium, firefox, webkit]
go: ['stable', 'oldstable']
runs-on: ${{ matrix.os }}
name: ${{ matrix.browser }} on ${{ matrix.os }}
name: ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ^1.19.9
go-version: ${{ matrix.go }}
id: go
- name: Cache drivers
uses: actions/cache@v4
Expand All @@ -52,7 +53,7 @@ jobs:
~/Library/Caches/ms-playwright
~\AppData\Local\ms-playwright-go
~\AppData\Local\ms-playwright
key: ${{ runner.os }}-go-${{ matrix.browser }}-${{ hashFiles('**/run.go') }}
key: ${{ runner.os }}-go${{ matrix.go }}-${{ matrix.browser }}-${{ hashFiles('**/run.go') }}
- run: |
go install ./...
playwright install --with-deps ${{ matrix.browser }}
Expand Down Expand Up @@ -84,7 +85,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ^1.19.9
go-version: oldstable
id: go
- name: Install goveralls
run: go install github.com/mattn/goveralls@latest
Expand All @@ -99,7 +100,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version: ^1.19.9
go-version: oldstable
id: go
- run: |
go install ./...
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify_type_generation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ^1.19.9
go-version: oldstable
- name: Install gofumpt
run: go install mvdan.cc/gofumpt@latest
- name: Install Browsers
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
[![PkgGoDev](https://pkg.go.dev/badge/github.com/playwright-community/playwright-go)](https://pkg.go.dev/github.com/playwright-community/playwright-go)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](http://opensource.org/licenses/MIT)
[![Go Report Card](https://goreportcard.com/badge/github.com/playwright-community/playwright-go)](https://goreportcard.com/report/github.com/playwright-community/playwright-go) ![Build Status](https://github.com/playwright-community/playwright-go/workflows/Go/badge.svg)
[![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://aka.ms/playwright-slack) [![Coverage Status](https://coveralls.io/repos/github/playwright-community/playwright-go/badge.svg?branch=main)](https://coveralls.io/github/playwright-community/playwright-go?branch=main) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-127.0.6533.17-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-127.0-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> <!-- GEN:webkit-version-badge -->[![WebKit version](https://img.shields.io/badge/webkit-17.4-blue.svg?logo=safari)](https://webkit.org/)<!-- GEN:stop -->
[![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://aka.ms/playwright-slack) [![Coverage Status](https://coveralls.io/repos/github/playwright-community/playwright-go/badge.svg?branch=main)](https://coveralls.io/github/playwright-community/playwright-go?branch=main) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-129.0.6668.29-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-130.0-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> <!-- GEN:webkit-version-badge -->[![WebKit version](https://img.shields.io/badge/webkit-18.0-blue.svg?logo=safari)](https://webkit.org/)<!-- GEN:stop -->

[API reference](https://playwright.dev/docs/api/class-playwright) | [Example recipes](https://github.com/playwright-community/playwright-go/tree/main/examples)

Playwright is a Go library to automate [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) 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 <!-- GEN:chromium-version -->127.0.6533.17<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->127.0<!-- GEN:stop --> ||||
| Chromium <!-- GEN:chromium-version -->129.0.6668.29<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->18.0<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->130.0<!-- GEN:stop --> ||||

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

Expand Down
55 changes: 55 additions & 0 deletions browser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package playwright

import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -46,6 +47,14 @@ func (b *browserImpl) NewContext(options ...BrowserNewContextOptions) (BrowserCo
overrides["extraHTTPHeaders"] = serializeMapToNameAndValue(options[0].ExtraHttpHeaders)
options[0].ExtraHttpHeaders = nil
}
if option.ClientCertificates != nil {
certs, err := transformClientCertificate(option.ClientCertificates)
if err != nil {
return nil, err
}
overrides["clientCertificates"] = certs
options[0].ClientCertificates = nil
}
if option.StorageStatePath != nil {
var storageState *OptionalStorageState
storageString, err := os.ReadFile(*options[0].StorageStatePath)
Expand Down Expand Up @@ -217,3 +226,49 @@ func newBrowser(parent *channelOwner, objectType string, guid string, initialize
b.channel.On("close", b.onClose)
return b
}

func transformClientCertificate(clientCertificates []ClientCertificate) ([]map[string]interface{}, error) {
results := make([]map[string]interface{}, 0)

for _, cert := range clientCertificates {
data := map[string]interface{}{
"origin": cert.Origin,
"passphrase": cert.Passphrase,
}
if len(cert.Cert) > 0 {
data["cert"] = base64.StdEncoding.EncodeToString(cert.Cert)
} else if cert.CertPath != nil {
content, err := os.ReadFile(*cert.CertPath)
if err != nil {
return nil, err
}
data["cert"] = base64.StdEncoding.EncodeToString(content)
}

if len(cert.Key) > 0 {
data["key"] = base64.StdEncoding.EncodeToString(cert.Key)
} else if cert.KeyPath != nil {
content, err := os.ReadFile(*cert.KeyPath)
if err != nil {
return nil, err
}
data["key"] = base64.StdEncoding.EncodeToString(content)
}

if len(cert.Pfx) > 0 {
data["pfx"] = base64.StdEncoding.EncodeToString(cert.Pfx)
} else if cert.PfxPath != nil {
content, err := os.ReadFile(*cert.PfxPath)
if err != nil {
return nil, err
}
data["pfx"] = base64.StdEncoding.EncodeToString(content)
}

results = append(results, data)
}
if len(results) == 0 {
return nil, nil
}
return results, nil
}
8 changes: 8 additions & 0 deletions browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ func (b *browserTypeImpl) LaunchPersistentContext(userDataDir string, options ..
}
options[0].AcceptDownloads = nil
}
if options[0].ClientCertificates != nil {
certs, err := transformClientCertificate(options[0].ClientCertificates)
if err != nil {
return nil, err
}
overrides["clientCertificates"] = certs
options[0].ClientCertificates = nil
}
if options[0].ExtraHttpHeaders != nil {
overrides["extraHTTPHeaders"] = serializeMapToNameAndValue(options[0].ExtraHttpHeaders)
options[0].ExtraHttpHeaders = nil
Expand Down
11 changes: 11 additions & 0 deletions fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type apiRequestImpl struct {
func (r *apiRequestImpl) NewContext(options ...APIRequestNewContextOptions) (APIRequestContext, error) {
overrides := map[string]interface{}{}
if len(options) == 1 {
if options[0].ClientCertificates != nil {
certs, err := transformClientCertificate(options[0].ClientCertificates)
if err != nil {
return nil, err
}
overrides["clientCertificates"] = certs
options[0].ClientCertificates = nil
}
if options[0].ExtraHttpHeaders != nil {
overrides["extraHTTPHeaders"] = serializeMapToNameAndValue(options[0].ExtraHttpHeaders)
options[0].ExtraHttpHeaders = nil
Expand Down Expand Up @@ -105,6 +113,9 @@ func (r *apiRequestContextImpl) innerFetch(url string, request Request, options
if options[0].MaxRedirects != nil && *options[0].MaxRedirects < 0 {
return nil, errors.New("maxRedirects must be non-negative")
}
if options[0].MaxRetries != nil && *options[0].MaxRetries < 0 {
return nil, errors.New("maxRetries must be non-negative")
}
// only one of them can be specified
if countNonNil(options[0].Data, options[0].Form, options[0].Multipart) > 1 {
return nil, errors.New("only one of 'data', 'form' or 'multipart' can be specified")
Expand Down
Loading

0 comments on commit a1b6055

Please sign in to comment.