Skip to content

Commit

Permalink
deploy: 6b672db
Browse files Browse the repository at this point in the history
  • Loading branch information
canstand committed Sep 23, 2024
1 parent a193c90 commit 6999a89
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 80 deletions.
8 changes: 4 additions & 4 deletions assets/css/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"fmt"
"os"
"regexp"
"slices"
"strings"
"sync"

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

type browserContextImpl struct {
Expand Down
8 changes: 8 additions & 0 deletions channel.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package playwright

import "encoding/json"

type channel struct {
eventEmitter
guid string
Expand All @@ -8,6 +10,12 @@ type channel struct {
object interface{} // retain type info (for fromChannel needed)
}

func (c *channel) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]string{
"guid": c.guid,
})
}

func (c *channel) Send(method string, options ...interface{}) (interface{}, error) {
return c.connection.WrapAPICall(func() (interface{}, error) {
return c.innerSend(method, false, options...)
Expand Down
29 changes: 1 addition & 28 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,33 +164,6 @@ func (c *connection) WrapAPICall(cb func() (interface{}, error), isInternal bool
return cb()
}

func (c *connection) replaceChannelsWithGuids(payload interface{}) interface{} {
if payload == nil {
return nil
}
if channel, isChannel := payload.(*channel); isChannel {
return map[string]string{
"guid": channel.guid,
}
}
v := reflect.ValueOf(payload)
if v.Kind() == reflect.Slice {
listV := make([]interface{}, 0)
for i := 0; i < v.Len(); i++ {
listV = append(listV, c.replaceChannelsWithGuids(v.Index(i).Interface()))
}
return listV
}
if v.Kind() == reflect.Map {
mapV := make(map[string]interface{})
for _, key := range v.MapKeys() {
mapV[key.String()] = c.replaceChannelsWithGuids(v.MapIndex(key).Interface())
}
return mapV
}
return payload
}

func (c *connection) replaceGuidsWithChannels(payload interface{}) interface{} {
if payload == nil {
return nil
Expand Down Expand Up @@ -244,7 +217,7 @@ func (c *connection) sendMessageToServer(object *channelOwner, method string, pa
"id": id,
"guid": object.guid,
"method": method,
"params": c.replaceChannelsWithGuids(params),
"params": params, // channel.MarshalJSON will replace channel with guid
"metadata": metadata,
}
if c.tracingCount.Load() > 0 && len(stack) > 0 && object.guid != "localUtils" {
Expand Down
7 changes: 3 additions & 4 deletions event_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package playwright
import (
"math"
"reflect"
"slices"
"sync"

"golang.org/x/exp/slices"
)

type EventEmitter interface {
Expand Down Expand Up @@ -119,10 +118,10 @@ func (er *eventRegister) count() int {
return len(er.listeners)
}

func (e *eventRegister) removeHandler(handler interface{}) {
func (er *eventRegister) removeHandler(handler interface{}) {
handlerPtr := reflect.ValueOf(handler).Pointer()

e.listeners = slices.DeleteFunc(e.listeners, func(l listener) bool {
er.listeners = slices.DeleteFunc(er.listeners, func(l listener) bool {
return reflect.ValueOf(l.handler).Pointer() == handlerPtr
})
}
Expand Down
5 changes: 2 additions & 3 deletions frame_locator.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package playwright

import (
"errors"
"fmt"
"strconv"

"github.com/playwright-community/playwright-go/internal/multierror"
)

type frameLocatorImpl struct {
Expand Down Expand Up @@ -102,7 +101,7 @@ func (fl *frameLocatorImpl) Locator(selectorOrLocator interface{}, options ...Fr
locator, ok := selectorOrLocator.(*locatorImpl)
if ok {
if fl.frame != locator.frame {
locator.err = multierror.Join(locator.err, ErrLocatorNotSameFrame)
locator.err = errors.Join(locator.err, ErrLocatorNotSameFrame)
return locator
}
return newLocator(locator.frame,
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/playwright-community/playwright-go

go 1.19
go 1.22

require (
github.com/deckarep/golang-set/v2 v2.6.0
Expand All @@ -12,8 +12,6 @@ require (
github.com/orisano/pixelmatch v0.0.0-20230914042517-fa304d1dc785
github.com/stretchr/testify v1.8.4
github.com/tidwall/gjson v1.17.0
go.uber.org/multierr v1.11.0
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
)

require (
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhso
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
8 changes: 0 additions & 8 deletions internal/multierror/multierror_g0120.go

This file was deleted.

8 changes: 0 additions & 8 deletions internal/multierror/multierror_go119.go

This file was deleted.

5 changes: 2 additions & 3 deletions internal/safe/map.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package safe

import (
"maps"
"sync"

"golang.org/x/exp/maps"
)

// SyncMap is a thread-safe map
Expand Down Expand Up @@ -64,7 +63,7 @@ func (m *SyncMap[K, V]) Delete(k K) {
func (m *SyncMap[K, V]) Clear() {
m.Lock()
defer m.Unlock()
maps.Clear(m.m)
clear(m.m)
}

func (m *SyncMap[K, V]) Len() int {
Expand Down
10 changes: 4 additions & 6 deletions locator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"errors"
"fmt"
"strconv"

"github.com/playwright-community/playwright-go/internal/multierror"
)

var (
Expand Down Expand Up @@ -35,15 +33,15 @@ func newLocator(frame *frameImpl, selector string, options ...LocatorLocatorOpti
if option.Has != nil {
has := option.Has.(*locatorImpl)
if frame != has.frame {
locator.err = multierror.Join(locator.err, ErrLocatorNotSameFrame)
locator.err = errors.Join(locator.err, ErrLocatorNotSameFrame)
} else {
selector += fmt.Sprintf(` >> internal:has=%s`, escapeText(has.selector))
}
}
if option.HasNot != nil {
hasNot := option.HasNot.(*locatorImpl)
if frame != hasNot.frame {
locator.err = multierror.Join(locator.err, ErrLocatorNotSameFrame)
locator.err = errors.Join(locator.err, ErrLocatorNotSameFrame)
} else {
selector += fmt.Sprintf(` >> internal:has-not=%s`, escapeText(hasNot.selector))
}
Expand Down Expand Up @@ -598,15 +596,15 @@ func (l *locatorImpl) Locator(selectorOrLocator interface{}, options ...LocatorL
locator, ok := selectorOrLocator.(*locatorImpl)
if ok {
if l.frame != locator.frame {
l.err = multierror.Join(l.err, ErrLocatorNotSameFrame)
l.err = errors.Join(l.err, ErrLocatorNotSameFrame)
return l
}
return newLocator(l.frame,
l.selector+" >> internal:chain="+escapeText(locator.selector),
options...,
)
}
l.err = multierror.Join(l.err, fmt.Errorf("invalid locator parameter: %v", selectorOrLocator))
l.err = errors.Join(l.err, fmt.Errorf("invalid locator parameter: %v", selectorOrLocator))
return l
}

Expand Down
2 changes: 1 addition & 1 deletion page.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"errors"
"fmt"
"os"
"slices"
"sync"

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

type pageImpl struct {
Expand Down
8 changes: 3 additions & 5 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"path/filepath"
"runtime"
"strings"

"github.com/playwright-community/playwright-go/internal/multierror"
)

const (
Expand Down Expand Up @@ -372,17 +370,17 @@ func downloadDriver(driverURLs []string) (body []byte, e error) {
for _, driverURL := range driverURLs {
resp, err := http.Get(driverURL)
if err != nil {
e = multierror.Join(e, fmt.Errorf("could not download driver from %s: %w", driverURL, err))
e = errors.Join(e, fmt.Errorf("could not download driver from %s: %w", driverURL, err))
continue
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
e = multierror.Join(e, fmt.Errorf("error: got non 200 status code: %d (%s) from %s", resp.StatusCode, resp.Status, driverURL))
e = errors.Join(e, fmt.Errorf("error: got non 200 status code: %d (%s) from %s", resp.StatusCode, resp.Status, driverURL))
continue
}
body, err = io.ReadAll(resp.Body)
if err != nil {
e = multierror.Join(e, fmt.Errorf("could not read response body: %w", err))
e = errors.Join(e, fmt.Errorf("could not read response body: %w", err))
continue
}
return body, nil
Expand Down
2 changes: 1 addition & 1 deletion tests/browser_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"math"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"time"

"github.com/playwright-community/playwright-go"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

func TestBrowserTypeBrowserName(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"time"

"github.com/playwright-community/playwright-go"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

func TestMouseMove(t *testing.T) {
Expand Down

0 comments on commit 6999a89

Please sign in to comment.