Skip to content

Commit 3d5c7c7

Browse files
authored
chore: roll to Playwright v1.45.1 (#472)
1 parent 3158371 commit 3d5c7c7

24 files changed

+1525
-163
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ covprofile
2929

3030
api.json
3131
_site/
32-
.jekyll-cache/
32+
.jekyll-cache/
33+
34+
.vscode/settings.json

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-125.0.6422.26-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-125.0.1-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-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 -->
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 -->125.0.6422.26<!-- GEN:stop --> ||||
16+
| Chromium <!-- GEN:chromium-version -->127.0.6533.17<!-- GEN:stop --> ||||
1717
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> ||||
18-
| Firefox <!-- GEN:firefox-version -->125.0.1<!-- GEN:stop --> ||||
18+
| Firefox <!-- GEN:firefox-version -->127.0<!-- GEN:stop --> ||||
1919

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

browser_context.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ type browserContextImpl struct {
3030
closed chan struct{}
3131
closeReason *string
3232
harRouters []*harRouter
33+
clock Clock
34+
}
35+
36+
func (b *browserContextImpl) Clock() Clock {
37+
return b.clock
3338
}
3439

3540
func (b *browserContextImpl) SetDefaultNavigationTimeout(timeout float64) {
@@ -408,6 +413,16 @@ func (b *browserContextImpl) Close(options ...BrowserContextCloseOptions) error
408413
b.closeReason = options[0].Reason
409414
}
410415
b.closeWasCalled = true
416+
417+
_, err := b.channel.connection.WrapAPICall(func() (interface{}, error) {
418+
return nil, b.request.Dispose(APIRequestContextDisposeOptions{
419+
Reason: b.closeReason,
420+
})
421+
}, true)
422+
if err != nil {
423+
return err
424+
}
425+
411426
innerClose := func() (interface{}, error) {
412427
for harId, harMetaData := range b.harRecorders {
413428
overrides := map[string]interface{}{}
@@ -442,7 +457,7 @@ func (b *browserContextImpl) Close(options ...BrowserContextCloseOptions) error
442457
return nil, nil
443458
}
444459

445-
_, err := b.channel.connection.WrapAPICall(innerClose, true)
460+
_, err = b.channel.connection.WrapAPICall(innerClose, true)
446461
if err != nil {
447462
return err
448463
}
@@ -737,6 +752,7 @@ func newBrowserContext(parent *channelOwner, objectType string, guid string, ini
737752
}
738753
bt.tracing = fromChannel(initializer["tracing"]).(*tracingImpl)
739754
bt.request = fromChannel(initializer["requestContext"]).(*apiRequestContextImpl)
755+
bt.clock = newClock(bt)
740756
bt.channel.On("bindingCall", func(params map[string]interface{}) {
741757
bt.onBinding(fromChannel(params["binding"]).(*bindingCallImpl))
742758
})

clock.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package playwright
2+
3+
import (
4+
"errors"
5+
"time"
6+
)
7+
8+
type clockImpl struct {
9+
browserCtx *browserContextImpl
10+
}
11+
12+
func newClock(bCtx *browserContextImpl) Clock {
13+
return &clockImpl{
14+
browserCtx: bCtx,
15+
}
16+
}
17+
18+
func (c *clockImpl) FastForward(ticks interface{}) error {
19+
params, err := parseTicks(ticks)
20+
if err != nil {
21+
return err
22+
}
23+
24+
_, err = c.browserCtx.channel.Send("clockFastForward", params)
25+
return err
26+
}
27+
28+
func (c *clockImpl) Install(options ...ClockInstallOptions) (err error) {
29+
params := map[string]any{}
30+
if len(options) == 1 {
31+
if options[0].Time != nil {
32+
params, err = parseTime(options[0].Time)
33+
if err != nil {
34+
return err
35+
}
36+
}
37+
}
38+
39+
_, err = c.browserCtx.channel.Send("clockInstall", params)
40+
41+
return err
42+
}
43+
44+
func (c *clockImpl) PauseAt(time interface{}) error {
45+
params, err := parseTime(time)
46+
if err != nil {
47+
return err
48+
}
49+
50+
_, err = c.browserCtx.channel.Send("clockPauseAt", params)
51+
return err
52+
}
53+
54+
func (c *clockImpl) Resume() error {
55+
_, err := c.browserCtx.channel.Send("clockResume")
56+
return err
57+
}
58+
59+
func (c *clockImpl) RunFor(ticks interface{}) error {
60+
params, err := parseTicks(ticks)
61+
if err != nil {
62+
return err
63+
}
64+
65+
_, err = c.browserCtx.channel.Send("clockRunFor", params)
66+
return err
67+
}
68+
69+
func (c *clockImpl) SetFixedTime(time interface{}) error {
70+
params, err := parseTime(time)
71+
if err != nil {
72+
return err
73+
}
74+
75+
_, err = c.browserCtx.channel.Send("clockSetFixedTime", params)
76+
return err
77+
}
78+
79+
func (c *clockImpl) SetSystemTime(time interface{}) error {
80+
params, err := parseTime(time)
81+
if err != nil {
82+
return err
83+
}
84+
85+
_, err = c.browserCtx.channel.Send("clockSetSystemTime", params)
86+
return err
87+
}
88+
89+
func parseTime(t interface{}) (map[string]any, error) {
90+
switch v := t.(type) {
91+
case int, int64:
92+
return map[string]any{"timeNumber": v}, nil
93+
case string:
94+
return map[string]any{"timeString": v}, nil
95+
case time.Time:
96+
return map[string]any{"timeNumber": v.UnixMilli()}, nil
97+
default:
98+
return nil, errors.New("time should be one of: int, int64, string, time.Time")
99+
}
100+
}
101+
102+
func parseTicks(ticks interface{}) (map[string]any, error) {
103+
switch v := ticks.(type) {
104+
case int, int64:
105+
return map[string]any{"ticksNumber": v}, nil
106+
case string:
107+
return map[string]any{"ticksString": v}, nil
108+
default:
109+
return nil, errors.New("ticks should be one of: int, int64, string")
110+
}
111+
}

fetch.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,20 @@ func newApiRequestImpl(pw *Playwright) *apiRequestImpl {
4848

4949
type apiRequestContextImpl struct {
5050
channelOwner
51-
tracing *tracingImpl
51+
tracing *tracingImpl
52+
closeReason *string
5253
}
5354

54-
func (r *apiRequestContextImpl) Dispose() error {
55-
_, err := r.channel.Send("dispose")
55+
func (r *apiRequestContextImpl) Dispose(options ...APIRequestContextDisposeOptions) error {
56+
if len(options) == 1 {
57+
r.closeReason = options[0].Reason
58+
}
59+
_, err := r.channel.Send("dispose", map[string]interface{}{
60+
"reason": r.closeReason,
61+
})
62+
if errors.Is(err, ErrTargetClosed) {
63+
return nil
64+
}
5665
return err
5766
}
5867

@@ -82,6 +91,9 @@ func (r *apiRequestContextImpl) Fetch(urlOrRequest interface{}, options ...APIRe
8291
}
8392

8493
func (r *apiRequestContextImpl) innerFetch(url string, request Request, options ...APIRequestContextFetchOptions) (APIResponse, error) {
94+
if r.closeReason != nil {
95+
return nil, fmt.Errorf("%w: %s", ErrTargetClosed, *r.closeReason)
96+
}
8597
overrides := map[string]interface{}{}
8698
if url != "" {
8799
overrides["url"] = url

generated-enums.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,15 @@ var (
377377
MediaPrint = getMedia("print")
378378
MediaNoOverride = getMedia("no-override")
379379
)
380+
381+
func getHttpCredentialsSend(in string) *HttpCredentialsSend {
382+
v := HttpCredentialsSend(in)
383+
return &v
384+
}
385+
386+
type HttpCredentialsSend string
387+
388+
var (
389+
HttpCredentialsSendUnauthorized *HttpCredentialsSend = getHttpCredentialsSend("unauthorized")
390+
HttpCredentialsSendAlways = getHttpCredentialsSend("always")
391+
)

0 commit comments

Comments
 (0)