Skip to content

chore: roll to Playwright v1.51.1 #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-133.0.6943.16-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-134.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.2-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-134.0.6998.35-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-135.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.4-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 -->133.0.6943.16<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->18.2<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->134.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->134.0.6998.35<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->18.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->135.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |

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

Expand Down
11 changes: 11 additions & 0 deletions browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ func (b *browserTypeImpl) LaunchPersistentContext(userDataDir string, options ..
func (b *browserTypeImpl) Connect(wsEndpoint string, options ...BrowserTypeConnectOptions) (Browser, error) {
overrides := map[string]interface{}{
"wsEndpoint": wsEndpoint,
"headers": map[string]string{
"x-playwright-browser": b.Name(),
},
}
if len(options) == 1 {
if options[0].Headers != nil {
for k, v := range options[0].Headers {
overrides["headers"].(map[string]string)[k] = v
}
options[0].Headers = nil
}
}
localUtils := b.connection.LocalUtils()
pipe, err := localUtils.channel.SendReturnAsDict("connect", options, overrides)
Expand Down
9 changes: 7 additions & 2 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,14 @@ func (f *frameImpl) SetChecked(selector string, checked bool, options ...FrameSe
}

func (f *frameImpl) Locator(selector string, options ...FrameLocatorOptions) Locator {
var option LocatorLocatorOptions
var option LocatorOptions
if len(options) == 1 {
option = LocatorLocatorOptions(options[0])
option = LocatorOptions{
Has: options[0].Has,
HasNot: options[0].HasNot,
HasText: options[0].HasText,
HasNotText: options[0].HasNotText,
}
}
return newLocator(f, selector, option)
}
Expand Down
9 changes: 7 additions & 2 deletions frame_locator.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ func (fl *frameLocatorImpl) Last() FrameLocator {
}

func (fl *frameLocatorImpl) Locator(selectorOrLocator interface{}, options ...FrameLocatorLocatorOptions) Locator {
var option LocatorLocatorOptions
var option LocatorOptions
if len(options) == 1 {
option = LocatorLocatorOptions(options[0])
option = LocatorOptions{
Has: options[0].Has,
HasNot: options[0].HasNot,
HasText: options[0].HasText,
HasNotText: options[0].HasNotText,
}
}

selector, ok := selectorOrLocator.(string)
Expand Down
13 changes: 13 additions & 0 deletions generated-enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,19 @@ var (
LoadStateNetworkidle = getLoadState("networkidle")
)

func getContrast(in string) *Contrast {
v := Contrast(in)
return &v
}

type Contrast string

var (
ContrastNoPreference *Contrast = getContrast("no-preference")
ContrastMore = getContrast("more")
ContrastNoOverride = getContrast("no-override")
)

func getMedia(in string) *Media {
v := Media(in)
return &v
Expand Down
15 changes: 12 additions & 3 deletions generated-interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ type BrowserContext interface {
// offline: Whether to emulate network being offline for the browser context.
SetOffline(offline bool) error

// Returns storage state for this browser context, contains current cookies and local storage snapshot.
// Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB
// snapshot.
StorageState(path ...string) (*StorageState, error)

Tracing() Tracing
Expand Down Expand Up @@ -2789,7 +2790,8 @@ type Locator interface {
// [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control
SetInputFiles(files interface{}, options ...LocatorSetInputFilesOptions) error

// Perform a tap gesture on the element matching the locator.
// Perform a tap gesture on the element matching the locator. For examples of emulating other gestures by manually
// dispatching touch events, see the [emulating legacy touch events] page.
//
// # Details
//
Expand All @@ -2802,6 +2804,7 @@ type Locator interface {
// [TimeoutError]. Passing zero timeout disables this.
// **NOTE** `element.tap()` requires that the `hasTouch` option of the browser context be set to true.
//
// [emulating legacy touch events]: https://playwright.dev/docs/touch-events
// [actionability]: https://playwright.dev/docs/actionability
Tap(options ...LocatorTapOptions) error

Expand Down Expand Up @@ -4416,6 +4419,10 @@ type Selectors interface {

// The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on
// the touchscreen can only be used in browser contexts that have been initialized with `hasTouch` set to true.
// This class is limited to emulating tap gestures. For examples of other gestures simulated by manually dispatching
// touch events, see the [emulating legacy touch events] page.
//
// [emulating legacy touch events]: https://playwright.dev/docs/touch-events
type Touchscreen interface {
// Dispatches a `touchstart` and `touchend` event with a single touch at the position
// (“[object Object]”,“[object Object]”).
Expand Down Expand Up @@ -4482,7 +4489,9 @@ type WebError interface {
Error() error
}

// The [WebSocket] class represents websocket connections in the page.
// The [WebSocket] class represents WebSocket connections within a page. It provides the ability to inspect and
// manipulate the data being transmitted and received.
// If you want to intercept or modify WebSocket frames, consider using [WebSocketRoute].
type WebSocket interface {
// Fired when the websocket closes.
OnClose(fn func(WebSocket))
Expand Down
32 changes: 27 additions & 5 deletions generated-structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type APIRequestNewContextOptions struct {
ClientCertificates []ClientCertificate `json:"clientCertificates"`
// An object containing additional HTTP headers to be sent with every request. Defaults to none.
ExtraHttpHeaders map[string]string `json:"extraHTTPHeaders"`
// Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status
// codes.
FailOnStatusCode *bool `json:"failOnStatusCode"`
// Credentials for [HTTP authentication]. If no
// origin is specified, the username and password are sent to any servers upon unauthorized responses.
//
Expand Down Expand Up @@ -1261,7 +1264,11 @@ type ElementHandleScreenshotOptions struct {
// changed. Defaults to `"hide"`.
Caret *ScreenshotCaret `json:"caret"`
// Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink
// box `#FF00FF` (customized by “[object Object]”) that completely covers its bounding box.
// box `#FF00FF` (customized by “[object Object]”) that completely covers its bounding box. The mask is also applied
// to invisible elements, see [Matching only visible elements] to
// disable that.
//
// [Matching only visible elements]: https://playwright.dev/docs/locators#matching-only-visible-elements
Mask []Locator `json:"mask"`
// Specify the color of the overlay box for masked elements, in
// [CSS color format]. Default color is pink `#FF00FF`.
Expand Down Expand Up @@ -2451,6 +2458,8 @@ type LocatorFilterOptions struct {
// passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches
// `<article><div>Playwright</div></article>`.
HasText interface{} `json:"hasText"`
// Only matches visible or invisible elements.
Visible *bool `json:"visible"`
}

type LocatorFocusOptions struct {
Expand Down Expand Up @@ -2688,7 +2697,11 @@ type LocatorScreenshotOptions struct {
// changed. Defaults to `"hide"`.
Caret *ScreenshotCaret `json:"caret"`
// Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink
// box `#FF00FF` (customized by “[object Object]”) that completely covers its bounding box.
// box `#FF00FF` (customized by “[object Object]”) that completely covers its bounding box. The mask is also applied
// to invisible elements, see [Matching only visible elements] to
// disable that.
//
// [Matching only visible elements]: https://playwright.dev/docs/locators#matching-only-visible-elements
Mask []Locator `json:"mask"`
// Specify the color of the overlay box for masked elements, in
// [CSS color format]. Default color is pink `#FF00FF`.
Expand Down Expand Up @@ -3236,7 +3249,12 @@ type PageEmulateMediaOptions struct {
// emulation. `no-preference` is deprecated.
//
// [prefers-colors-scheme]: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
ColorScheme *ColorScheme `json:"colorScheme"`
ColorScheme *ColorScheme `json:"colorScheme"`
// Emulates `prefers-contrast` media feature, supported values are `no-preference`, `more`. Passing
// `no-override` disables contrast emulation.
Contrast *Contrast `json:"contrast"`
// Emulates `forced-colors` media feature, supported values are `active` and `none`. Passing `no-override`
// disables forced colors emulation.
ForcedColors *ForcedColors `json:"forcedColors"`
// Changes the CSS media type of the page. The only allowed values are `screen`, `print` and `no-override`.
// Passing `no-override` disables CSS media emulation.
Expand Down Expand Up @@ -3683,7 +3701,11 @@ type PageScreenshotOptions struct {
// `false`.
FullPage *bool `json:"fullPage"`
// Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink
// box `#FF00FF` (customized by “[object Object]”) that completely covers its bounding box.
// box `#FF00FF` (customized by “[object Object]”) that completely covers its bounding box. The mask is also applied
// to invisible elements, see [Matching only visible elements] to
// disable that.
//
// [Matching only visible elements]: https://playwright.dev/docs/locators#matching-only-visible-elements
Mask []Locator `json:"mask"`
// Specify the color of the overlay box for masked elements, in
// [CSS color format]. Default color is pink `#FF00FF`.
Expand Down Expand Up @@ -4048,7 +4070,7 @@ type PageAssertionsToHaveTitleOptions struct {

type PageAssertionsToHaveURLOptions struct {
// Whether to perform case-insensitive match. “[object Object]” option takes precedence over the corresponding regular
// expression flag if specified.
// expression parameter if specified. A provided predicate ignores this flag.
IgnoreCase *bool `json:"ignoreCase"`
// Time to retry the assertion for in milliseconds. Defaults to `5000`.
Timeout *float64 `json:"timeout"`
Expand Down
28 changes: 22 additions & 6 deletions locator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ var (
type locatorImpl struct {
frame *frameImpl
selector string
options *LocatorLocatorOptions
options *LocatorOptions
err error
}

func newLocator(frame *frameImpl, selector string, options ...LocatorLocatorOptions) *locatorImpl {
option := &LocatorLocatorOptions{}
type LocatorOptions LocatorFilterOptions

func newLocator(frame *frameImpl, selector string, options ...LocatorOptions) *locatorImpl {
option := &LocatorOptions{}
if len(options) == 1 {
option = &options[0]
}
Expand All @@ -46,6 +48,10 @@ func newLocator(frame *frameImpl, selector string, options ...LocatorLocatorOpti
selector += fmt.Sprintf(` >> internal:has-not=%s`, escapeText(hasNot.selector))
}
}
if option.Visible != nil {
selector += fmt.Sprintf(` >> visible=%s`, strconv.FormatBool(*option.Visible))
}

locator.selector = selector

return locator
Expand Down Expand Up @@ -339,7 +345,7 @@ func (l *locatorImpl) Fill(value string, options ...LocatorFillOptions) error {

func (l *locatorImpl) Filter(options ...LocatorFilterOptions) Locator {
if len(options) == 1 {
return newLocator(l.frame, l.selector, LocatorLocatorOptions(options[0]))
return newLocator(l.frame, l.selector, LocatorOptions(options[0]))
}
return newLocator(l.frame, l.selector)
}
Expand Down Expand Up @@ -602,9 +608,19 @@ func (l *locatorImpl) Last() Locator {
}

func (l *locatorImpl) Locator(selectorOrLocator interface{}, options ...LocatorLocatorOptions) Locator {
var option LocatorOptions
if len(options) == 1 {
option = LocatorOptions{
Has: options[0].Has,
HasNot: options[0].HasNot,
HasText: options[0].HasText,
HasNotText: options[0].HasNotText,
}
}

selector, ok := selectorOrLocator.(string)
if ok {
return newLocator(l.frame, l.selector+" >> "+selector, options...)
return newLocator(l.frame, l.selector+" >> "+selector, option)
}
locator, ok := selectorOrLocator.(*locatorImpl)
if ok {
Expand All @@ -614,7 +630,7 @@ func (l *locatorImpl) Locator(selectorOrLocator interface{}, options ...LocatorL
}
return newLocator(l.frame,
l.selector+" >> internal:chain="+escapeText(locator.selector),
options...,
option,
)
}
l.err = errors.Join(l.err, fmt.Errorf("invalid locator parameter: %v", selectorOrLocator))
Expand Down
Loading