Skip to content

Commit f764444

Browse files
authored
chore: roll to Playwright v1.43.0 (#449)
1 parent 872a873 commit f764444

18 files changed

+488
-147
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
[![PkgGoDev](https://pkg.go.dev/badge/github.com/playwright-community/playwright-go)](https://pkg.go.dev/github.com/playwright-community/playwright-go)
66
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](http://opensource.org/licenses/MIT)
77
[![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)
8-
[![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-123.0.6312.4-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-123.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 -->
8+
[![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-124.0.6367.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-124.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 -->
99

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

1212
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**.
1313

1414
| | Linux | macOS | Windows |
1515
| :--- | :---: | :---: | :---: |
16-
| Chromium <!-- GEN:chromium-version -->123.0.6312.4<!-- GEN:stop --> ||||
16+
| Chromium <!-- GEN:chromium-version -->124.0.6367.29<!-- GEN:stop --> ||||
1717
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> ||||
18-
| Firefox <!-- GEN:firefox-version -->123.0<!-- GEN:stop --> ||||
18+
| Firefox <!-- GEN:firefox-version -->124.0<!-- GEN:stop --> ||||
1919

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

browser_context.go

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"os"
8+
"regexp"
89
"strings"
910
"sync"
1011

@@ -43,10 +44,7 @@ func (b *browserContextImpl) setDefaultNavigationTimeoutImpl(timeout *float64) {
4344
}
4445

4546
func (b *browserContextImpl) SetDefaultTimeout(timeout float64) {
46-
b.timeoutSettings.SetDefaultTimeout(&timeout)
47-
b.channel.SendNoReply("setDefaultTimeoutNoReply", map[string]interface{}{
48-
"timeout": timeout,
49-
})
47+
b.setDefaultTimeoutImpl(&timeout)
5048
}
5149

5250
func (b *browserContextImpl) setDefaultTimeoutImpl(timeout *float64) {
@@ -125,8 +123,53 @@ func (b *browserContextImpl) AddCookies(cookies []OptionalCookie) error {
125123
return err
126124
}
127125

128-
func (b *browserContextImpl) ClearCookies() error {
129-
_, err := b.channel.Send("clearCookies")
126+
func (b *browserContextImpl) ClearCookies(options ...BrowserContextClearCookiesOptions) error {
127+
params := map[string]interface{}{}
128+
if len(options) == 1 {
129+
if options[0].Domain != nil {
130+
switch t := options[0].Domain.(type) {
131+
case string:
132+
params["domain"] = t
133+
case *string:
134+
params["domain"] = t
135+
case *regexp.Regexp:
136+
pattern, flag := convertRegexp(t)
137+
params["domainRegexSource"] = pattern
138+
params["domainRegexFlags"] = flag
139+
default:
140+
return errors.New("invalid type for domain, expected string or *regexp.Regexp")
141+
}
142+
}
143+
if options[0].Name != nil {
144+
switch t := options[0].Name.(type) {
145+
case string:
146+
params["name"] = t
147+
case *string:
148+
params["name"] = t
149+
case *regexp.Regexp:
150+
pattern, flag := convertRegexp(t)
151+
params["nameRegexSource"] = pattern
152+
params["nameRegexFlags"] = flag
153+
default:
154+
return errors.New("invalid type for name, expected string or *regexp.Regexp")
155+
}
156+
}
157+
if options[0].Path != nil {
158+
switch t := options[0].Path.(type) {
159+
case string:
160+
params["path"] = t
161+
case *string:
162+
params["path"] = t
163+
case *regexp.Regexp:
164+
pattern, flag := convertRegexp(t)
165+
params["pathRegexSource"] = pattern
166+
params["pathRegexFlags"] = flag
167+
default:
168+
return errors.New("invalid type for path, expected string or *regexp.Regexp")
169+
}
170+
}
171+
}
172+
_, err := b.channel.Send("clearCookies", params)
130173
return err
131174
}
132175

cmd/playwright/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"log"
55
"os"
6-
"os/exec"
76

87
"github.com/playwright-community/playwright-go"
98
)
@@ -16,7 +15,7 @@ func main() {
1615
if err = driver.DownloadDriver(); err != nil {
1716
log.Fatalf("could not download driver: %v", err)
1817
}
19-
cmd := exec.Command(driver.DriverBinaryLocation, os.Args[1:]...)
18+
cmd := driver.Command(os.Args[1:]...)
2019
cmd.Stdout = os.Stdout
2120
cmd.Stderr = os.Stderr
2221
if err := cmd.Run(); err != nil {

frame_locator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@ func (fl *frameLocatorImpl) Locator(selectorOrLocator interface{}, options ...Fr
120120
func (fl *frameLocatorImpl) Nth(index int) FrameLocator {
121121
return newFrameLocator(fl.frame, fl.frameSelector+" >> nth="+strconv.Itoa(index))
122122
}
123+
124+
func (fl *frameLocatorImpl) Owner() Locator {
125+
return newLocator(fl.frame, fl.frameSelector)
126+
}

generated-interfaces.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ type BrowserContext interface {
295295
// Returns the browser instance of the context. If it was launched as a persistent context null gets returned.
296296
Browser() Browser
297297

298-
// Clears context cookies.
299-
ClearCookies() error
298+
// Removes cookies from context. Accepts optional filter.
299+
ClearCookies(options ...BrowserContextClearCookiesOptions) error
300300

301301
// Clears all permission overrides for the browser context.
302302
ClearPermissions() error
@@ -1831,9 +1831,10 @@ type Frame interface {
18311831
// matches a given selector.
18321832
// **Converting Locator to FrameLocator**
18331833
// If you have a [Locator] object pointing to an `iframe` it can be converted to [FrameLocator] using
1834-
// [`:scope`] CSS selector:
1835-
//
1836-
// [`:scope`]: https://developer.mozilla.org/en-US/docs/Web/CSS/:scope
1834+
// [Locator.ContentFrame].
1835+
// **Converting FrameLocator to Locator**
1836+
// If you have a [FrameLocator] object it can be converted to [Locator] pointing to the same `iframe` using
1837+
// [FrameLocator.Owner].
18371838
type FrameLocator interface {
18381839
// Returns locator to the first matching frame.
18391840
First() FrameLocator
@@ -1925,6 +1926,12 @@ type FrameLocator interface {
19251926

19261927
// Returns locator to the n-th matching frame. It's zero based, `nth(0)` selects the first frame.
19271928
Nth(index int) FrameLocator
1929+
1930+
// Returns a [Locator] object pointing to the same `iframe` as this frame locator.
1931+
// Useful when you have a [FrameLocator] object obtained somewhere, and later on would like to interact with the
1932+
// `iframe` element.
1933+
// For a reverse operation, use [Locator.ContentFrame].
1934+
Owner() Locator
19281935
}
19291936

19301937
// JSHandle represents an in-page JavaScript object. JSHandles can be created with the [Page.EvaluateHandle] method.
@@ -2243,6 +2250,12 @@ type Locator interface {
22432250
// Deprecated: Always prefer using [Locator]s and web assertions over [ElementHandle]s because latter are inherently racy.
22442251
ElementHandles() ([]ElementHandle, error)
22452252

2253+
// Returns a [FrameLocator] object pointing to the same `iframe` as this locator.
2254+
// Useful when you have a [Locator] object obtained somewhere, and later on would like to interact with the content
2255+
// inside the frame.
2256+
// For a reverse operation, use [FrameLocator.Owner].
2257+
ContentFrame() FrameLocator
2258+
22462259
// Execute JavaScript code in the page, taking the matching element as an argument.
22472260
//
22482261
// # Details
@@ -3521,17 +3534,20 @@ type Page interface {
35213534
// [locators]: https://playwright.dev/docs/locators
35223535
QuerySelectorAll(selector string) ([]ElementHandle, error)
35233536

3524-
// When testing a web page, sometimes unexpected overlays like a coookie consent dialog appear and block actions you
3525-
// want to automate, e.g. clicking a button. These overlays don't always show up in the same way or at the same time,
3526-
// making them tricky to handle in automated tests.
3537+
// **NOTE** This method is experimental and its behavior may change in the upcoming releases.
3538+
// When testing a web page, sometimes unexpected overlays like a "Sign up" dialog appear and block actions you want to
3539+
// automate, e.g. clicking a button. These overlays don't always show up in the same way or at the same time, making
3540+
// them tricky to handle in automated tests.
35273541
// This method lets you set up a special function, called a handler, that activates when it detects that overlay is
35283542
// visible. The handler's job is to remove the overlay, allowing your test to continue as if the overlay wasn't there.
35293543
// Things to keep in mind:
35303544
// - When an overlay is shown predictably, we recommend explicitly waiting for it in your test and dismissing it as
35313545
// a part of your normal test flow, instead of using [Page.AddLocatorHandler].
35323546
// - Playwright checks for the overlay every time before executing or retrying an action that requires an
35333547
// [actionability check], or before performing an auto-waiting assertion check. When overlay
3534-
// is visible, Playwright calls the handler first, and then proceeds with the action/assertion.
3548+
// is visible, Playwright calls the handler first, and then proceeds with the action/assertion. Note that the
3549+
// handler is only called when you perform an action/assertion - if the overlay becomes visible but you don't
3550+
// perform any actions, the handler will not be triggered.
35353551
// - The execution time of the handler counts towards the timeout of the action/assertion that executed the handler.
35363552
// If your handler takes too long, it might cause timeouts.
35373553
// - You can register multiple handlers. However, only a single handler will be running at a time. Make sure the

generated-structs.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,14 @@ type Script struct {
585585
// Raw script content. Optional.
586586
Content *string `json:"content"`
587587
}
588+
type BrowserContextClearCookiesOptions struct {
589+
// Only removes cookies with the given domain.
590+
Domain interface{} `json:"domain"`
591+
// Only removes cookies with the given name.
592+
Name interface{} `json:"name"`
593+
// Only removes cookies with the given path.
594+
Path interface{} `json:"path"`
595+
}
588596
type BrowserContextCloseOptions struct {
589597
// The reason to be reported to the operations interrupted by the context closure.
590598
Reason *string `json:"reason"`
@@ -716,6 +724,10 @@ type BrowserTypeLaunchOptions struct {
716724
ChromiumSandbox *bool `json:"chromiumSandbox"`
717725
// **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the
718726
// “headless” option will be set `false`.
727+
//
728+
// Deprecated: Use [debugging tools] instead.
729+
//
730+
// [debugging tools]: https://playwright.dev/docs/debug
719731
Devtools *bool `json:"devtools"`
720732
// If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and
721733
// is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were
@@ -804,6 +816,10 @@ type BrowserTypeLaunchPersistentContextOptions struct {
804816
DeviceScaleFactor *float64 `json:"deviceScaleFactor"`
805817
// **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the
806818
// “headless” option will be set `false`.
819+
//
820+
// Deprecated: Use [debugging tools] instead.
821+
//
822+
// [debugging tools]: https://playwright.dev/docs/debug
807823
Devtools *bool `json:"devtools"`
808824
// If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and
809825
// is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were

js_handle.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ func (j *jsHandleImpl) AsElement() ElementHandle {
8080

8181
func (j *jsHandleImpl) Dispose() error {
8282
_, err := j.channel.Send("dispose")
83+
if errors.Is(err, ErrTargetClosed) {
84+
return nil
85+
}
8386
return err
8487
}
8588

locator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ func (l *locatorImpl) Click(options ...LocatorClickOptions) error {
190190
return l.frame.Click(l.selector, opt)
191191
}
192192

193+
func (l *locatorImpl) ContentFrame() FrameLocator {
194+
return newFrameLocator(l.frame, l.selector)
195+
}
196+
193197
func (l *locatorImpl) Count() (int, error) {
194198
if l.err != nil {
195199
return 0, l.err

0 commit comments

Comments
 (0)