Skip to content

Commit 24eab96

Browse files
authored
chore: roll to playwright v1.42.1 (#423)
1 parent 664e25d commit 24eab96

38 files changed

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

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

errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func (e *Error) Is(target error) bool {
4444
func parseError(err Error) error {
4545
if err.Name == "TimeoutError" {
4646
return fmt.Errorf("%w: %w: %w", ErrPlaywright, ErrTimeout, &err)
47+
} else if err.Name == "TargetClosedError" {
48+
return fmt.Errorf("%w: %w: %w", ErrPlaywright, ErrTargetClosed, &err)
4749
}
4850
return fmt.Errorf("%w: %w", ErrPlaywright, &err)
4951
}

generated-interfaces.go

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ type BrowserContext interface {
224224
// - The [Browser.Close] method was called.
225225
OnClose(fn func(BrowserContext))
226226

227-
// Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also
228-
// emitted if the page throws an error or a warning.
227+
// Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`.
229228
// The arguments passed into `console.log` and the page are available on the [ConsoleMessage] event handler argument.
230229
OnConsole(fn func(ConsoleMessage))
231230

@@ -905,8 +904,8 @@ type ElementHandle interface {
905904
// Holding down `Shift` will type the text that corresponds to the “key” in the upper case.
906905
// If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
907906
// texts.
908-
// Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
909-
// modifier, modifier is pressed and being held while the subsequent key is being pressed.
907+
// Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When
908+
// specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
910909
//
911910
// Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators].
912911
//
@@ -1597,8 +1596,8 @@ type Frame interface {
15971596
// Holding down `Shift` will type the text that corresponds to the “key” in the upper case.
15981597
// If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
15991598
// texts.
1600-
// Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
1601-
// modifier, modifier is pressed and being held while the subsequent key is being pressed.
1599+
// Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When
1600+
// specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
16021601
//
16031602
// Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators].
16041603
//
@@ -2031,8 +2030,8 @@ type Keyboard interface {
20312030
// Holding down `Shift` will type the text that corresponds to the “key” in the upper case.
20322031
// If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
20332032
// texts.
2034-
// Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
2035-
// modifier, modifier is pressed and being held while the subsequent key is being pressed.
2033+
// Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When
2034+
// specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
20362035
//
20372036
// key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
20382037
//
@@ -2536,8 +2535,8 @@ type Locator interface {
25362535
// Holding down `Shift` will type the text that corresponds to the “key” in the upper case.
25372536
// If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
25382537
// texts.
2539-
// Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
2540-
// modifier, modifier is pressed and being held while the subsequent key is being pressed.
2538+
// Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When
2539+
// specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
25412540
//
25422541
// key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
25432542
//
@@ -2870,8 +2869,7 @@ type Page interface {
28702869
// Emitted when the page closes.
28712870
OnClose(fn func(Page))
28722871

2873-
// Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also
2874-
// emitted if the page throws an error or a warning.
2872+
// Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`.
28752873
// The arguments passed into `console.log` are available on the [ConsoleMessage] event handler argument.
28762874
OnConsole(fn func(ConsoleMessage))
28772875

@@ -3489,8 +3487,8 @@ type Page interface {
34893487
// Holding down `Shift` will type the text that corresponds to the “key” in the upper case.
34903488
// If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
34913489
// texts.
3492-
// Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
3493-
// modifier, modifier is pressed and being held while the subsequent key is being pressed.
3490+
// Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When
3491+
// specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
34943492
//
34953493
// Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators].
34963494
//
@@ -3523,6 +3521,38 @@ type Page interface {
35233521
// [locators]: https://playwright.dev/docs/locators
35243522
QuerySelectorAll(selector string) ([]ElementHandle, error)
35253523

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.
3527+
// This method lets you set up a special function, called a handler, that activates when it detects that overlay is
3528+
// visible. The handler's job is to remove the overlay, allowing your test to continue as if the overlay wasn't there.
3529+
// Things to keep in mind:
3530+
// - When an overlay is shown predictably, we recommend explicitly waiting for it in your test and dismissing it as
3531+
// a part of your normal test flow, instead of using [Page.AddLocatorHandler].
3532+
// - Playwright checks for the overlay every time before executing or retrying an action that requires an
3533+
// [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.
3535+
// - The execution time of the handler counts towards the timeout of the action/assertion that executed the handler.
3536+
// If your handler takes too long, it might cause timeouts.
3537+
// - You can register multiple handlers. However, only a single handler will be running at a time. Make sure the
3538+
// actions within a handler don't depend on another handler.
3539+
// **NOTE** Running the handler will alter your page state mid-test. For example it will change the currently focused
3540+
// element and move the mouse. Make sure that actions that run after the handler are self-contained and do not rely on
3541+
// the focus and mouse state being unchanged. <br /> <br /> For example, consider a test that calls [Locator.Focus]
3542+
// followed by [Keyboard.Press]. If your handler clicks a button between these two actions, the focused element most
3543+
// likely will be wrong, and key press will happen on the unexpected element. Use [Locator.Press] instead to avoid
3544+
// this problem. <br /> <br /> Another example is a series of mouse actions, where [Mouse.Move] is followed by
3545+
// [Mouse.Down]. Again, when the handler runs between these two actions, the mouse position will be wrong during the
3546+
// mouse down. Prefer self-contained actions like [Locator.Click] that do not rely on the state being unchanged by a
3547+
// handler.
3548+
//
3549+
// 1. locator: Locator that triggers the handler.
3550+
// 2. handler: Function that should be run once “locator” appears. This function should get rid of the element that blocks actions
3551+
// like click.
3552+
//
3553+
// [actionability check]: https://playwright.dev/docs/actionability
3554+
AddLocatorHandler(locator Locator, handler func()) error
3555+
35263556
// This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the
35273557
// main resource response. In case of multiple redirects, the navigation will resolve with the response of the last
35283558
// redirect.

generated-structs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,6 +3165,8 @@ type PagePdfOptions struct {
31653165
Landscape *bool `json:"landscape"`
31663166
// Paper margins, defaults to none.
31673167
Margin *Margin `json:"margin"`
3168+
// Whether or not to embed the document outline into the PDF. Defaults to `false`.
3169+
Outline *bool `json:"outline"`
31683170
// Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
31693171
PageRanges *string `json:"pageRanges"`
31703172
// The file path to save the PDF to. If “path” is a relative path, then it is resolved relative to the current working
@@ -3177,6 +3179,8 @@ type PagePdfOptions struct {
31773179
PrintBackground *bool `json:"printBackground"`
31783180
// Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.
31793181
Scale *float64 `json:"scale"`
3182+
// Whether or not to generate tagged (accessible) PDF. Defaults to `false`.
3183+
Tagged *bool `json:"tagged"`
31803184
// Paper width, accepts values labeled with units.
31813185
Width *string `json:"width"`
31823186
}

page.go

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,47 @@ type pageImpl struct {
3232
closeReason *string
3333
closeWasCalled bool
3434
harRouters []*harRouter
35+
locatorHandlers map[float64]func()
36+
}
37+
38+
func (p *pageImpl) AddLocatorHandler(locator Locator, handler func()) error {
39+
if locator == nil || handler == nil {
40+
return errors.New("locator or handler must not be nil")
41+
}
42+
if locator.Err() != nil {
43+
return locator.Err()
44+
}
45+
loc := locator.(*locatorImpl)
46+
if loc.frame != p.mainFrame {
47+
return errors.New("locator must belong to the main frame of this page")
48+
}
49+
uid, err := p.channel.Send("registerLocatorHandler", map[string]any{
50+
"selector": loc.selector,
51+
})
52+
if err != nil {
53+
return err
54+
}
55+
p.locatorHandlers[uid.(float64)] = handler
56+
return nil
57+
}
58+
59+
func (p *pageImpl) onLocatorHandlerTriggered(uid float64) {
60+
handler, ok := p.locatorHandlers[uid]
61+
if !ok {
62+
return
63+
}
64+
go func() {
65+
defer func() {
66+
_, _ = p.connection.WrapAPICall(func() (interface{}, error) {
67+
p.channel.SendNoReply("resolveLocatorHandlerNoReply", map[string]any{
68+
"uid": uid,
69+
})
70+
return nil, nil
71+
}, true)
72+
}()
73+
74+
handler()
75+
}()
3576
}
3677

3778
func (p *pageImpl) Context() BrowserContext {
@@ -740,11 +781,12 @@ func newPage(parent *channelOwner, objectType string, guid string, initializer m
740781
viewportSize.Width = int(initializer["viewportSize"].(map[string]interface{})["width"].(float64))
741782
}
742783
bt := &pageImpl{
743-
workers: make([]Worker, 0),
744-
routes: make([]*routeHandlerEntry, 0),
745-
bindings: make(map[string]BindingCallFunction),
746-
viewportSize: viewportSize,
747-
harRouters: make([]*harRouter, 0),
784+
workers: make([]Worker, 0),
785+
routes: make([]*routeHandlerEntry, 0),
786+
bindings: make(map[string]BindingCallFunction),
787+
viewportSize: viewportSize,
788+
harRouters: make([]*harRouter, 0),
789+
locatorHandlers: make(map[float64]func(), 0),
748790
}
749791
bt.createChannelOwner(bt, parent, objectType, guid, initializer)
750792
bt.browserContext = fromChannel(parent.channel).(*browserContextImpl)
@@ -775,6 +817,9 @@ func newPage(parent *channelOwner, objectType string, guid string, initializer m
775817
bt.channel.On("frameDetached", func(ev map[string]interface{}) {
776818
bt.onFrameDetached(fromChannel(ev["frame"]).(*frameImpl))
777819
})
820+
bt.channel.On("locatorHandlerTriggered", func(ev map[string]interface{}) {
821+
bt.onLocatorHandlerTriggered(ev["uid"].(float64))
822+
})
778823
bt.channel.On(
779824
"load", func(ev map[string]interface{}) {
780825
bt.Emit("load", bt)

0 commit comments

Comments
 (0)