Skip to content

Commit 6b672db

Browse files
canstandmxschmitt
andauthored
chore: require go v1.22 (#489)
* chore: require go v1.22 * chore: improve comments Co-authored-by: Max Schmitt <[email protected]> --------- Co-authored-by: Max Schmitt <[email protected]>
1 parent 25b224d commit 6b672db

15 files changed

+28
-76
lines changed

browser_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"fmt"
77
"os"
88
"regexp"
9+
"slices"
910
"strings"
1011
"sync"
1112

1213
"github.com/playwright-community/playwright-go/internal/safe"
13-
"golang.org/x/exp/slices"
1414
)
1515

1616
type browserContextImpl struct {

channel.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package playwright
22

3+
import "encoding/json"
4+
35
type channel struct {
46
eventEmitter
57
guid string
@@ -8,6 +10,12 @@ type channel struct {
810
object interface{} // retain type info (for fromChannel needed)
911
}
1012

13+
func (c *channel) MarshalJSON() ([]byte, error) {
14+
return json.Marshal(map[string]string{
15+
"guid": c.guid,
16+
})
17+
}
18+
1119
func (c *channel) Send(method string, options ...interface{}) (interface{}, error) {
1220
return c.connection.WrapAPICall(func() (interface{}, error) {
1321
return c.innerSend(method, false, options...)

connection.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -164,33 +164,6 @@ func (c *connection) WrapAPICall(cb func() (interface{}, error), isInternal bool
164164
return cb()
165165
}
166166

167-
func (c *connection) replaceChannelsWithGuids(payload interface{}) interface{} {
168-
if payload == nil {
169-
return nil
170-
}
171-
if channel, isChannel := payload.(*channel); isChannel {
172-
return map[string]string{
173-
"guid": channel.guid,
174-
}
175-
}
176-
v := reflect.ValueOf(payload)
177-
if v.Kind() == reflect.Slice {
178-
listV := make([]interface{}, 0)
179-
for i := 0; i < v.Len(); i++ {
180-
listV = append(listV, c.replaceChannelsWithGuids(v.Index(i).Interface()))
181-
}
182-
return listV
183-
}
184-
if v.Kind() == reflect.Map {
185-
mapV := make(map[string]interface{})
186-
for _, key := range v.MapKeys() {
187-
mapV[key.String()] = c.replaceChannelsWithGuids(v.MapIndex(key).Interface())
188-
}
189-
return mapV
190-
}
191-
return payload
192-
}
193-
194167
func (c *connection) replaceGuidsWithChannels(payload interface{}) interface{} {
195168
if payload == nil {
196169
return nil
@@ -244,7 +217,7 @@ func (c *connection) sendMessageToServer(object *channelOwner, method string, pa
244217
"id": id,
245218
"guid": object.guid,
246219
"method": method,
247-
"params": c.replaceChannelsWithGuids(params),
220+
"params": params, // channel.MarshalJSON will replace channel with guid
248221
"metadata": metadata,
249222
}
250223
if c.tracingCount.Load() > 0 && len(stack) > 0 && object.guid != "localUtils" {

event_emitter.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package playwright
33
import (
44
"math"
55
"reflect"
6+
"slices"
67
"sync"
7-
8-
"golang.org/x/exp/slices"
98
)
109

1110
type EventEmitter interface {
@@ -119,10 +118,10 @@ func (er *eventRegister) count() int {
119118
return len(er.listeners)
120119
}
121120

122-
func (e *eventRegister) removeHandler(handler interface{}) {
121+
func (er *eventRegister) removeHandler(handler interface{}) {
123122
handlerPtr := reflect.ValueOf(handler).Pointer()
124123

125-
e.listeners = slices.DeleteFunc(e.listeners, func(l listener) bool {
124+
er.listeners = slices.DeleteFunc(er.listeners, func(l listener) bool {
126125
return reflect.ValueOf(l.handler).Pointer() == handlerPtr
127126
})
128127
}

frame_locator.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package playwright
22

33
import (
4+
"errors"
45
"fmt"
56
"strconv"
6-
7-
"github.com/playwright-community/playwright-go/internal/multierror"
87
)
98

109
type frameLocatorImpl struct {
@@ -102,7 +101,7 @@ func (fl *frameLocatorImpl) Locator(selectorOrLocator interface{}, options ...Fr
102101
locator, ok := selectorOrLocator.(*locatorImpl)
103102
if ok {
104103
if fl.frame != locator.frame {
105-
locator.err = multierror.Join(locator.err, ErrLocatorNotSameFrame)
104+
locator.err = errors.Join(locator.err, ErrLocatorNotSameFrame)
106105
return locator
107106
}
108107
return newLocator(locator.frame,

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/playwright-community/playwright-go
22

3-
go 1.19
3+
go 1.22
44

55
require (
66
github.com/deckarep/golang-set/v2 v2.6.0
@@ -12,8 +12,6 @@ require (
1212
github.com/orisano/pixelmatch v0.0.0-20230914042517-fa304d1dc785
1313
github.com/stretchr/testify v1.8.4
1414
github.com/tidwall/gjson v1.17.0
15-
go.uber.org/multierr v1.11.0
16-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
1715
)
1816

1917
require (

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@ github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhso
4242
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
4343
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
4444
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
45-
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
46-
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
4745
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4846
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
4947
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
50-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
51-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
5248
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
5349
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
5450
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=

internal/multierror/multierror_g0120.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

internal/multierror/multierror_go119.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

internal/safe/map.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package safe
22

33
import (
4+
"maps"
45
"sync"
5-
6-
"golang.org/x/exp/maps"
76
)
87

98
// SyncMap is a thread-safe map
@@ -64,7 +63,7 @@ func (m *SyncMap[K, V]) Delete(k K) {
6463
func (m *SyncMap[K, V]) Clear() {
6564
m.Lock()
6665
defer m.Unlock()
67-
maps.Clear(m.m)
66+
clear(m.m)
6867
}
6968

7069
func (m *SyncMap[K, V]) Len() int {

0 commit comments

Comments
 (0)