diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-31 16:09:12 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-31 16:09:12 -0600 |
| commit | 238b61113456ebad8bad880913dc315cd892a296 (patch) | |
| tree | f38db8e10c4b55aef21c96c30fc71278c6e3d5c6 | |
| parent | ebb003ef2beaeee61104d6b88a342c5c9fa73b51 (diff) | |
| parent | 311603d0c0b04d451e9fb8e5e8335dca8425e2c4 (diff) | |
Merge branch 'sparkle-visibility' into 'main'
Connect to postgresql
See merge request gitlab-org/software-supply-chain-security/authorization/sparkled!21
136 files changed, 7850 insertions, 23996 deletions
@@ -1,9 +1,11 @@ APP_ENV=development # AUTHZD_HOST=0.0.0.0:20000 +DATABASE_URL=postgresql:///sparkle_development?host=/tmp HMAC_SESSION_SECRET=session_secret LOG_LEVEL=warn OAUTH_CLIENT_ID=client_id OAUTH_CLIENT_SECRET=client_secret OIDC_ISSUER=https://gitlab.com +RUNWAY_PG_USER_POSTGRES_PASSWORD_SPARKLE= ZED_ENDPOINT=localhost:50051 ZED_TOKEN=secret @@ -4,3 +4,7 @@ /tmp /log .claude/ + +# Generated Procfiles (use Procfile.template as source) +Procfile +Procfile.dev @@ -14,11 +14,12 @@ FROM authzed/spicedb:latest AS spicedb-binary # Build stage for sparkle FROM golang:1.24-alpine AS build ENV CGO_ENABLED=0 -RUN go install github.com/xlgmokha/minit@latest WORKDIR /app COPY . ./ RUN go build -o /bin/sparkled ./cmd/sparkled/main.go RUN go build -o /bin/authzd ./cmd/authzd/main.go +WORKDIR /app/vendor/github.com/xlgmokha/minit +RUN go build -o /bin/minit main.go # Final stage FROM gcr.io/distroless/base-debian12:debug-nonroot @@ -36,8 +37,8 @@ COPY --from=build /app/etc/envoy /etc/envoy COPY --from=build /app/etc/authzd /etc/authzd COPY --from=build /app/public /public COPY --from=build /bin/authzd /bin/authzd +COPY --from=build /bin/minit /bin/minit COPY --from=build /bin/sparkled /bin/sparkled -COPY --from=build /go/bin/minit /bin/minit ENTRYPOINT ["/bin/dumb-init", "--"] -CMD ["/bin/minit"] +CMD ["/bin/minit", "-f", "/Procfile"] @@ -3,9 +3,10 @@ GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed 's/\//_/g') IMAGE_TAG := $(PROJECT_NAME):$(GIT_BRANCH) AUTHZD_BIN := bin/authzd SPARKLED_BIN := bin/sparkled +TOOL := bin/tool ZED := bin/zed -.PHONY: clean setup build test run db-setup +.PHONY: clean setup build test run db-setup db-create db-stop db-reset $(AUTHZD_BIN): $(shell find . -name "*.go" 2>/dev/null) go.sum @go build -o $(AUTHZD_BIN) ./cmd/authzd/main.go @@ -13,13 +14,15 @@ $(AUTHZD_BIN): $(shell find . -name "*.go" 2>/dev/null) go.sum $(SPARKLED_BIN): $(shell find . -name "*.go" 2>/dev/null) go.sum @go build -o $(SPARKLED_BIN) ./cmd/sparkled/main.go -clean: +db-clean: + @rm -rf tmp/postgres tmp/postgres.log + +clean: db-clean @rm -f $(AUTHZD_BIN) $(SPARKLED_BIN) @go clean -testcache setup: @mise install - @mise exec go -- go install github.com/xlgmokha/minit@latest @mise exec go -- go mod tidy @mise exec go -- go mod vendor @mise exec go -- go tool @@ -28,6 +31,12 @@ setup: fi @mise exec python -- pip install dumb-init +Procfile: Procfile.template + @grep -v "# DEV_ONLY:" Procfile.template > Procfile + +Procfile.dev: Procfile.template + @sed 's/# DEV_ONLY: //' Procfile.template > Procfile.dev + build: $(AUTHZD_BIN) $(SPARKLED_BIN) test-schema: @@ -44,24 +53,25 @@ test-integration: build-image test: clean test-unit test-schema test-integration -build-image: +build-image: Procfile @docker build --network=host --no-cache --tag $(IMAGE_TAG) . -run: clean build - @go tool godotenv -f .env.local,.env minit +run: clean build Procfile.dev db-init + @$(TOOL) godotenv -f .env.local,.env $(TOOL) minit -f Procfile.dev run-image: clean build-image - @docker run --rm --network host --env-file .env.local -p 10000:10000 -p 9901:9901 -p 8080:8080 -it $(IMAGE_TAG) + @docker run --rm --network host --env-file .env.local -p 10000:10000 -it $(IMAGE_TAG) lint: - @go tool yamlfmt -lint -exclude vendor . + @$(TOOL) yamlfmt -lint -exclude vendor . @$(ZED) validate etc/authzd/* tidy: @go get -u ./... + @go tool | grep github | awk '{print $1}' | xargs -I {} go get -tool {}@latest @go mod tidy @go mod vendor - @go tool yamlfmt -exclude vendor . + @$(TOOL) yamlfmt -exclude vendor . db-schema-load: @$(ZED) schema write etc/authzd/schema.zed @@ -69,4 +79,15 @@ db-schema-load: db-seed: @$(ZED) import etc/authzd/relationships.yaml +db-stop: + @mise exec postgres -- pg_ctl -D tmp/postgres stop || true + +db-reset: db-stop db-clean db-create + +db-init: + @[ ! -d tmp/postgres ] && mise exec postgres -- initdb -D tmp/postgres || true + +db-create: db-init + @mise exec postgres -- createdb -h /tmp sparkle_development || true + db-setup: db-schema-load db-seed diff --git a/Procfile.template b/Procfile.template new file mode 100644 index 0000000..3f20a32 --- /dev/null +++ b/Procfile.template @@ -0,0 +1,5 @@ +# DEV_ONLY: postgres: ./bin/postgres -D tmp/postgres -c config_file=etc/postgres/postgresql.conf +spicedb: ./bin/spicedb serve --grpc-preshared-key $ZED_TOKEN --http-addr :8081 --grpc-addr :50051 --datastore-engine memory --log-level $LOG_LEVEL --log-format json --telemetry-endpoint "" --skip-release-check +authzd: ./bin/authzd +envoy: ./bin/envoy-shim +sparkled: ./bin/sparkled @@ -9,6 +9,7 @@ import ( "github.com/xlgmokha/x/pkg/log" "github.com/xlgmokha/x/pkg/x" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/dashboard" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/health" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/sparkles" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/middleware" ) @@ -22,6 +23,7 @@ func New(rootDir string) http.Handler { mountable := []Mountable{ ioc.MustResolve[*dashboard.Controller](ioc.Default), + ioc.MustResolve[*health.Controller](ioc.Default), ioc.MustResolve[*sparkles.Controller](ioc.Default), } for _, m := range mountable { diff --git a/app/controllers/health/controller.go b/app/controllers/health/controller.go new file mode 100644 index 0000000..99ff4cd --- /dev/null +++ b/app/controllers/health/controller.go @@ -0,0 +1,43 @@ +package health + +import ( + "context" + "net/http" + "time" + + "github.com/xlgmokha/x/pkg/serde" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/db" +) + +type Controller struct { + dbConnection *db.Connection +} + +func New(dbConnection *db.Connection) *Controller { + return &Controller{ + dbConnection: dbConnection, + } +} + +func (c *Controller) MountTo(mux *http.ServeMux) { + mux.Handle("GET /-/health", http.HandlerFunc(c.Health)) + mux.Handle("GET /-/health/database", http.HandlerFunc(c.Database)) +} + +func (c *Controller) Health(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + serde.ToHTTP(w, r, map[string]string{"status": "ok"}) +} + +func (c *Controller) Database(w http.ResponseWriter, r *http.Request) { + ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) + defer cancel() + + if c.dbConnection.IsHealthy(ctx) { + w.WriteHeader(http.StatusOK) + serde.ToHTTP(w, r, map[string]string{"database": "ok"}) + } else { + w.WriteHeader(http.StatusServiceUnavailable) + serde.ToHTTP(w, r, map[string]string{"database": "unavailable"}) + } +} diff --git a/app/controllers/sparkles/controller.go b/app/controllers/sparkles/controller.go index 90767b2..86610e1 100644 --- a/app/controllers/sparkles/controller.go +++ b/app/controllers/sparkles/controller.go @@ -3,7 +3,6 @@ package sparkles import ( "net/http" - "github.com/xlgmokha/x/pkg/log" "github.com/xlgmokha/x/pkg/mapper" "github.com/xlgmokha/x/pkg/serde" "github.com/xlgmokha/x/pkg/x" @@ -32,9 +31,6 @@ func (c *Controller) MountTo(mux *http.ServeMux) { middleware.RequireUser(), // middleware.RequirePermission("create", c.check), )) - - // This is a temporary endpoint to restore a backup - mux.HandleFunc("POST /sparkles/restore", c.Restore) } func (c *Controller) Index(w http.ResponseWriter, r *http.Request) { @@ -64,16 +60,3 @@ func (c *Controller) Create(w http.ResponseWriter, r *http.Request) { return } } - -// This is a temporary endpoint to restore a backup -// of sparkles and can be deleted once we have an actual database -func (c *Controller) Restore(w http.ResponseWriter, r *http.Request) { - sparkles, _ := serde.FromHTTP[[]*domain.Sparkle](r) - log.WithFields(r.Context(), log.Fields{"sparkles": sparkles}) - - x.Each(sparkles, func(sparkle *domain.Sparkle) { - if err := c.db.Save(r.Context(), sparkle); err != nil { - pls.LogError(r.Context(), err) - } - }) -} diff --git a/app/db/connection.go b/app/db/connection.go new file mode 100644 index 0000000..d494f6c --- /dev/null +++ b/app/db/connection.go @@ -0,0 +1,54 @@ +package db + +import ( + "context" + "database/sql" + "fmt" + + _ "github.com/lib/pq" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls" +) + +type Connection struct { + db *sql.DB +} + +func NewConnection(databaseURL string) (*Connection, error) { + db, err := sql.Open("postgres", databaseURL) + if err != nil { + return nil, fmt.Errorf("failed to open database connection: %w", err) + } + + return &Connection{ + db: db, + }, nil +} + +func (c *Connection) Ping(ctx context.Context) error { + if c.db == nil { + return fmt.Errorf("database connection not available") + } + + return c.db.PingContext(ctx) +} + +func (c *Connection) IsHealthy(ctx context.Context) bool { + if c.db == nil { + return false + } + + err := c.Ping(ctx) + if err != nil { + pls.LogError(ctx, err) + return false + } + + return true +} + +func (c *Connection) Close() error { + if c.db == nil { + return nil + } + return c.db.Close() +} diff --git a/app/db/url.go b/app/db/url.go new file mode 100644 index 0000000..b17c651 --- /dev/null +++ b/app/db/url.go @@ -0,0 +1,19 @@ +package db + +import ( + "fmt" + + "github.com/xlgmokha/x/pkg/env" +) + +func URL() string { + if url := env.Fetch("DATABASE_URL", ""); url != "" { + return url + } + + return fmt.Sprintf( + "postgresql://postgres:%s@localhost:5000/%s?sslmode=disable", + env.Fetch("RUNWAY_PG_USER_POSTGRES_PASSWORD_SPARKLE", ""), + env.Fetch("DATABASE_NAME", "sparkle"), + ) +} diff --git a/app/init.go b/app/init.go index 8e5e0e5..ab1d6f8 100644 --- a/app/init.go +++ b/app/init.go @@ -14,6 +14,7 @@ import ( "github.com/xlgmokha/x/pkg/mapper" "github.com/xlgmokha/x/pkg/x" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/dashboard" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/health" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/controllers/sparkles" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/db" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" @@ -29,6 +30,13 @@ func init() { ioc.RegisterSingleton[*zerolog.Logger](c, func() *zerolog.Logger { return log.New(os.Stdout, log.Fields{"app": "sparkled"}) }) + ioc.RegisterSingleton[*db.Connection](c, func() *db.Connection { + conn, err := db.NewConnection(db.URL()) + if err != nil { + pls.LogErrorNow(context.Background(), err) + } + return conn + }) ioc.RegisterSingleton[*authzed.Client](c, func() *authzed.Client { return authz.NewSpiceDBClient( context.Background(), @@ -62,6 +70,9 @@ func init() { ioc.Register[*dashboard.Controller](c, func() *dashboard.Controller { return dashboard.New() }) + ioc.Register[*health.Controller](c, func() *health.Controller { + return health.New(ioc.MustResolve[*db.Connection](c)) + }) ioc.Register[*sparkles.Controller](c, func() *sparkles.Controller { return sparkles.New( ioc.MustResolve[domain.Repository[*domain.Sparkle]](c), diff --git a/bin/postgres b/bin/postgres new file mode 100755 index 0000000..66c0ab0 --- /dev/null +++ b/bin/postgres @@ -0,0 +1,8 @@ +#!/bin/sh + +if ! command -v postgres >/dev/null 2>&1; then + echo "Install postgres via mise: mise install postgres" + exit 1 +fi + +exec postgres $@ diff --git a/bin/tool b/bin/tool new file mode 100755 index 0000000..7b46bce --- /dev/null +++ b/bin/tool @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +tool_bin=$(go tool -n "$1") + +shift + +exec "$tool_bin" "$@" diff --git a/etc/postgres/postgresql.conf b/etc/postgres/postgresql.conf new file mode 100644 index 0000000..4d7f703 --- /dev/null +++ b/etc/postgres/postgresql.conf @@ -0,0 +1,25 @@ +# Connection settings +listen_addresses = '' +unix_socket_directories = '/tmp' + +# Logging settings +logging_collector = off +log_destination = 'stderr' +log_statement = 'ddl' +log_line_prefix = '' +log_min_duration_statement = 1000 +log_checkpoints = on + +# Performance and Development +shared_preload_libraries = '' # No additional libraries needed +max_connections = 100 # Default connection limit +shared_buffers = 128MB # Default buffer size + +# Development-friendly settings +fsync = off # Faster writes (safe for development only) +synchronous_commit = off # Faster commits (safe for development only) +full_page_writes = off # Reduce I/O (safe for development only) + +# Timezone +timezone = 'UTC' # Use UTC for consistency +log_timezone = 'UTC' # Log timestamps in UTC @@ -8,6 +8,8 @@ require ( github.com/coreos/go-oidc/v3 v3.15.0 github.com/docker/docker v28.3.3+incompatible github.com/envoyproxy/go-control-plane/envoy v1.32.4 + github.com/golobby/container/v3 v3.3.2 + github.com/lib/pq v1.10.9 github.com/oauth2-proxy/mockoidc v0.0.0-20240214162133-caebfff84d25 github.com/oklog/ulid v1.3.1 github.com/rs/zerolog v1.34.0 @@ -77,7 +79,6 @@ require ( github.com/dalzilio/rudd v1.1.1-0.20230806153452-9e08a6ea8170 // indirect github.com/danieljoos/wincred v1.2.1 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/deckarep/golang-set/v2 v2.8.0 // indirect github.com/distribution/reference v0.6.0 // indirect github.com/docker/go-connections v0.5.0 // indirect github.com/docker/go-units v0.5.0 // indirect @@ -98,13 +99,11 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-logr/zerologr v1.2.3 // indirect github.com/go-ole/go-ole v1.3.0 // indirect - github.com/go-stack/stack v1.8.1 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v5 v5.3.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v1.0.0 // indirect - github.com/golobby/container/v3 v3.3.2 // indirect github.com/google/go-cmp v0.7.0 // indirect github.com/google/go-github/v43 v43.0.0 // indirect github.com/google/go-querystring v1.1.0 // indirect @@ -159,7 +158,6 @@ require ( github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/planetscale/vtprotobuf v0.6.1-0.20250313105119-ba97887b0a25 // indirect - github.com/playwright-community/playwright-go v0.5200.0 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/prometheus/client_golang v1.21.1 // indirect @@ -189,7 +187,7 @@ require ( github.com/tklauser/go-sysconf v0.3.15 // indirect github.com/tklauser/numcpus v0.10.0 // indirect github.com/xlab/treeprint v1.2.0 // indirect - github.com/xlgmokha/minit v0.0.0-20250725204255-8e0834741617 // indirect + github.com/xlgmokha/minit v0.0.0-20250731211218-d06d0bc4c199 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect github.com/zeebo/errs v1.4.0 // indirect @@ -223,6 +221,5 @@ tool ( github.com/fullstorydev/grpcurl/cmd/grpcurl github.com/google/yamlfmt/cmd/yamlfmt github.com/joho/godotenv/cmd/godotenv - github.com/playwright-community/playwright-go/cmd/playwright github.com/xlgmokha/minit ) @@ -171,8 +171,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set/v2 v2.8.0 h1:swm0rlPCmdWn9mESxKOjWk8hXSqoxOp+ZlfuyaAdFlQ= -github.com/deckarep/golang-set/v2 v2.8.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/dlmiddlecote/sqlstats v1.0.2 h1:gSU11YN23D/iY50A2zVYwgXgy072khatTsIW6UPjUtI= @@ -258,8 +256,6 @@ github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ github.com/go-sql-driver/mysql v1.9.1 h1:FrjNGn/BsJQjVRuSa8CBrM5BWA9BWoXXat3KrtSb/iI= github.com/go-sql-driver/mysql v1.9.1/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= -github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= @@ -390,6 +386,8 @@ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o= github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk= github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4= github.com/lthibault/jitterbug v2.0.0+incompatible h1:qouq51IKzlMx25+15jbxhC/d79YyTj0q6XFoptNqaUw= @@ -418,8 +416,6 @@ github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2Em github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= -github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= @@ -482,8 +478,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/planetscale/vtprotobuf v0.6.1-0.20250313105119-ba97887b0a25 h1:S1hI5JiKP7883xBzZAr1ydcxrKNSVNm7+3+JwjxZEsg= github.com/planetscale/vtprotobuf v0.6.1-0.20250313105119-ba97887b0a25/go.mod h1:ZQntvDG8TkPgljxtA0R9frDoND4QORU1VXz015N5Ks4= -github.com/playwright-community/playwright-go v0.5200.0 h1:z/5LGuX2tBrg3ug1HupMXLjIG93f1d2MWdDsNhkMQ9c= -github.com/playwright-community/playwright-go v0.5200.0/go.mod h1:UnnyQZaqUOO5ywAZu60+N4EiWReUqX1MQBBA3Oofvf8= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -587,8 +581,8 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ= github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0= -github.com/xlgmokha/minit v0.0.0-20250725204255-8e0834741617 h1:MM4yskiyvXBz8ufTTp3PWgpAZMY4BEGIIbuS3arc0Ws= -github.com/xlgmokha/minit v0.0.0-20250725204255-8e0834741617/go.mod h1:2Kojbsk+Nuj/Rcf+kHkJOKnf+VstT/r1ZRS4pPqtVXY= +github.com/xlgmokha/minit v0.0.0-20250731211218-d06d0bc4c199 h1:uCej+MMWWjvQwCdo6NQm4aDGVs3CsC8mLvwAoVJZy0A= +github.com/xlgmokha/minit v0.0.0-20250731211218-d06d0bc4c199/go.mod h1:2Kojbsk+Nuj/Rcf+kHkJOKnf+VstT/r1ZRS4pPqtVXY= github.com/xlgmokha/x v0.0.0-20250730165105-1a2af5f242cf h1:XXOAL/L880uxlbwOMAr6WMKCQzYyZfaYg4ovehJniY0= github.com/xlgmokha/x v0.0.0-20250730165105-1a2af5f242cf/go.mod h1:zhU3cB9VYGt4IlTIaLVw3wsXIS5UzXiYmCB+q+DjfHs= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= @@ -1,3 +1,4 @@ [tools] go = "1.24.5" +postgres = "17" python = "3.13.4" diff --git a/vendor/github.com/deckarep/golang-set/v2/.gitignore b/vendor/github.com/deckarep/golang-set/v2/.gitignore deleted file mode 100644 index 4eb156d..0000000 --- a/vendor/github.com/deckarep/golang-set/v2/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -.idea
\ No newline at end of file diff --git a/vendor/github.com/deckarep/golang-set/v2/LICENSE b/vendor/github.com/deckarep/golang-set/v2/LICENSE deleted file mode 100644 index efd4827..0000000 --- a/vendor/github.com/deckarep/golang-set/v2/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Open Source Initiative OSI - The MIT License (MIT):Licensing - -The MIT License (MIT) -Copyright (c) 2013 - 2022 Ralph Caraveo (deckarep@gmail.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE.
\ No newline at end of file diff --git a/vendor/github.com/deckarep/golang-set/v2/README.md b/vendor/github.com/deckarep/golang-set/v2/README.md deleted file mode 100644 index e471368..0000000 --- a/vendor/github.com/deckarep/golang-set/v2/README.md +++ /dev/null @@ -1,195 +0,0 @@ - -[](https://goreportcard.com/report/github.com/deckarep/golang-set/v2) -[](http://godoc.org/github.com/deckarep/golang-set/v2) - -# golang-set - -The missing `generic` set collection for the Go language. Until Go has sets built-in...use this. - -## Psst -* Hi there, 👋! Do you use or have interest in the [Zig programming language](https://ziglang.org/) created by Andrew Kelley? If so, the golang-set project has a new sibling project: [ziglang-set](https://github.com/deckarep/ziglang-set)! Come check it out! - -## Update 3/14/2025 -* Packaged version: `2.8.0` introduces support for true iterators for Go 1.23+. Please see [issue #141](https://github.com/deckarep/golang-set/issues/141) -for further details on the implications of how iterations work between older Go versions vs newer Go versions. Additionally, this -release has a minor unit-test spelling fix. - -## Update 12/3/2024 -* Packaged version: `2.7.0` fixes a long-standing bug with *JSON Unmarshaling*. A large refactor in the interest of performance -introduced this bug and there was no way around it but to revert the code back to how it was previously. The performance -difference was likely negligible to begin with. JSON Marshaling and Unmarshaling is now properly supported again without -needing to do workarounds. - -## Update 3/5/2023 -* Packaged version: `2.2.0` release includes a refactor to minimize pointer indirection, better method documentation standards and a few constructor convenience methods to increase ergonomics when appending items `Append` or creating a new set from an exist `Map`. -* supports `new generic` syntax -* Go `1.18.0` or higher -* Workflow tested on Go `1.20` - - - -Coming from Python one of the things I miss is the superbly wonderful set collection. This is my attempt to mimic the primary features of the set collection from Python. -You can of course argue that there is no need for a set in Go, otherwise the creators would have added one to the standard library. To those I say simply ignore this repository and carry-on and to the rest that find this useful please contribute in helping me make it better by contributing with suggestions or PRs. - -## Install - -Use `go get` to install this package. - -```shell -go get github.com/deckarep/golang-set/v2 -``` - -## Features - -* *NEW* [Generics](https://go.dev/doc/tutorial/generics) based implementation (requires [Go 1.18](https://go.dev/blog/go1.18beta1) or higher) -* One common *interface* to both implementations - * a **non threadsafe** implementation favoring *performance* - * a **threadsafe** implementation favoring *concurrent* use -* Feature complete set implementation modeled after [Python's set implementation](https://docs.python.org/3/library/stdtypes.html#set). -* Exhaustive unit-test and benchmark suite - -## Trusted by - -This package is trusted by many companies and thousands of open-source packages. Here are just a few sample users of this package. - -* Notable projects/companies using this package - * Ethereum - * Docker - * 1Password - * Hashicorp - -## Star History - -[](https://star-history.com/#deckarep/golang-set&Date) - - -## Usage - -The code below demonstrates how a Set collection can better manage data and actually minimize boilerplate and needless loops in code. This package now fully supports *generic* syntax so you are now able to instantiate a collection for any [comparable](https://flaviocopes.com/golang-comparing-values/) type object. - -What is considered comparable in Go? -* `Booleans`, `integers`, `strings`, `floats` or basically primitive types. -* `Pointers` -* `Arrays` -* `Structs` if *all of their fields* are also comparable independently - -Using this library is as simple as creating either a threadsafe or non-threadsafe set and providing a `comparable` type for instantiation of the collection. - -```go -// Syntax example, doesn't compile. -mySet := mapset.NewSet[T]() // where T is some concrete comparable type. - -// Therefore this code creates an int set -mySet := mapset.NewSet[int]() - -// Or perhaps you want a string set -mySet := mapset.NewSet[string]() - -type myStruct struct { - name string - age uint8 -} - -// Alternatively a set of structs -mySet := mapset.NewSet[myStruct]() - -// Lastly a set that can hold anything using the any or empty interface keyword: interface{}. This is effectively removes type safety. -mySet := mapset.NewSet[any]() -``` - -## Comprehensive Example - -```go -package main - -import ( - "fmt" - mapset "github.com/deckarep/golang-set/v2" -) - -func main() { - // Create a string-based set of required classes. - required := mapset.NewSet[string]() - required.Add("cooking") - required.Add("english") - required.Add("math") - required.Add("biology") - - // Create a string-based set of science classes. - sciences := mapset.NewSet[string]() - sciences.Add("biology") - sciences.Add("chemistry") - - // Create a string-based set of electives. - electives := mapset.NewSet[string]() - electives.Add("welding") - electives.Add("music") - electives.Add("automotive") - - // Create a string-based set of bonus programming classes. - bonus := mapset.NewSet[string]() - bonus.Add("beginner go") - bonus.Add("python for dummies") -} -``` - -Create a set of all unique classes. -Sets will *automatically* deduplicate the same data. - -```go - all := required - .Union(sciences) - .Union(electives) - .Union(bonus) - - fmt.Println(all) -``` - -Output: -```sh -Set{cooking, english, math, chemistry, welding, biology, music, automotive, beginner go, python for dummies} -``` - -Is cooking considered a science class? -```go -result := sciences.Contains("cooking") -fmt.Println(result) -``` - -Output: -```false -false -``` - -Show me all classes that are not science classes, since I don't enjoy science. -```go -notScience := all.Difference(sciences) -fmt.Println(notScience) -``` - -```sh -Set{ music, automotive, beginner go, python for dummies, cooking, english, math, welding } -``` - -Which science classes are also required classes? -```go -reqScience := sciences.Intersect(required) -``` - -Output: -```sh -Set{biology} -``` - -How many bonus classes do you offer? -```go -fmt.Println(bonus.Cardinality()) -``` -Output: -```sh -2 -``` - -Thanks for visiting! - --deckarep diff --git a/vendor/github.com/deckarep/golang-set/v2/iterator.go b/vendor/github.com/deckarep/golang-set/v2/iterator.go deleted file mode 100644 index fc14e70..0000000 --- a/vendor/github.com/deckarep/golang-set/v2/iterator.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Open Source Initiative OSI - The MIT License (MIT):Licensing - -The MIT License (MIT) -Copyright (c) 2013 - 2022 Ralph Caraveo (deckarep@gmail.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -package mapset - -// Iterator defines an iterator over a Set, its C channel can be used to range over the Set's -// elements. -type Iterator[T comparable] struct { - C <-chan T - stop chan struct{} -} - -// Stop stops the Iterator, no further elements will be received on C, C will be closed. -func (i *Iterator[T]) Stop() { - // Allows for Stop() to be called multiple times - // (close() panics when called on already closed channel) - defer func() { - recover() - }() - - close(i.stop) - - // Exhaust any remaining elements. - for range i.C { - } -} - -// newIterator returns a new Iterator instance together with its item and stop channels. -func newIterator[T comparable]() (*Iterator[T], chan<- T, <-chan struct{}) { - itemChan := make(chan T) - stopChan := make(chan struct{}) - return &Iterator[T]{ - C: itemChan, - stop: stopChan, - }, itemChan, stopChan -} diff --git a/vendor/github.com/deckarep/golang-set/v2/new_improved.jpeg b/vendor/github.com/deckarep/golang-set/v2/new_improved.jpeg Binary files differdeleted file mode 100644 index 429752a..0000000 --- a/vendor/github.com/deckarep/golang-set/v2/new_improved.jpeg +++ /dev/null diff --git a/vendor/github.com/deckarep/golang-set/v2/set.go b/vendor/github.com/deckarep/golang-set/v2/set.go deleted file mode 100644 index e9409aa..0000000 --- a/vendor/github.com/deckarep/golang-set/v2/set.go +++ /dev/null @@ -1,269 +0,0 @@ -/* -Open Source Initiative OSI - The MIT License (MIT):Licensing - -The MIT License (MIT) -Copyright (c) 2013 - 2022 Ralph Caraveo (deckarep@gmail.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -// Package mapset implements a simple and set collection. -// Items stored within it are unordered and unique. It supports -// typical set operations: membership testing, intersection, union, -// difference, symmetric difference and cloning. -// -// Package mapset provides two implementations of the Set -// interface. The default implementation is safe for concurrent -// access, but a non-thread-safe implementation is also provided for -// programs that can benefit from the slight speed improvement and -// that can enforce mutual exclusion through other means. -package mapset - -// Set is the primary interface provided by the mapset package. It -// represents an unordered set of data and a large number of -// operations that can be applied to that set. -type Set[T comparable] interface { - // Add adds an element to the set. Returns whether - // the item was added. - Add(val T) bool - - // Append multiple elements to the set. Returns - // the number of elements added. - Append(val ...T) int - - // Cardinality returns the number of elements in the set. - Cardinality() int - - // Clear removes all elements from the set, leaving - // the empty set. - Clear() - - // Clone returns a clone of the set using the same - // implementation, duplicating all keys. - Clone() Set[T] - - // Contains returns whether the given items - // are all in the set. - Contains(val ...T) bool - - // ContainsOne returns whether the given item - // is in the set. - // - // Contains may cause the argument to escape to the heap. - // See: https://github.com/deckarep/golang-set/issues/118 - ContainsOne(val T) bool - - // ContainsAny returns whether at least one of the - // given items are in the set. - ContainsAny(val ...T) bool - - // ContainsAnyElement returns whether at least one of the - // given element are in the set. - ContainsAnyElement(other Set[T]) bool - - // Difference returns the difference between this set - // and other. The returned set will contain - // all elements of this set that are not also - // elements of other. - // - // Note that the argument to Difference - // must be of the same type as the receiver - // of the method. Otherwise, Difference will - // panic. - Difference(other Set[T]) Set[T] - - // Equal determines if two sets are equal to each - // other. If they have the same cardinality - // and contain the same elements, they are - // considered equal. The order in which - // the elements were added is irrelevant. - // - // Note that the argument to Equal must be - // of the same type as the receiver of the - // method. Otherwise, Equal will panic. - Equal(other Set[T]) bool - - // Intersect returns a new set containing only the elements - // that exist only in both sets. - // - // Note that the argument to Intersect - // must be of the same type as the receiver - // of the method. Otherwise, Intersect will - // panic. - Intersect(other Set[T]) Set[T] - - // IsEmpty determines if there are elements in the set. - IsEmpty() bool - - // IsProperSubset determines if every element in this set is in - // the other set but the two sets are not equal. - // - // Note that the argument to IsProperSubset - // must be of the same type as the receiver - // of the method. Otherwise, IsProperSubset - // will panic. - IsProperSubset(other Set[T]) bool - - // IsProperSuperset determines if every element in the other set - // is in this set but the two sets are not - // equal. - // - // Note that the argument to IsSuperset - // must be of the same type as the receiver - // of the method. Otherwise, IsSuperset will - // panic. - IsProperSuperset(other Set[T]) bool - - // IsSubset determines if every element in this set is in - // the other set. - // - // Note that the argument to IsSubset - // must be of the same type as the receiver - // of the method. Otherwise, IsSubset will - // panic. - IsSubset(other Set[T]) bool - - // IsSuperset determines if every element in the other set - // is in this set. - // - // Note that the argument to IsSuperset - // must be of the same type as the receiver - // of the method. Otherwise, IsSuperset will - // panic. - IsSuperset(other Set[T]) bool - - // Each iterates over elements and executes the passed func against each element. - // If passed func returns true, stop iteration at the time. - Each(func(T) bool) - - // Iter returns a channel of elements that you can - // range over. - Iter() <-chan T - - // Iterator returns an Iterator object that you can - // use to range over the set. - Iterator() *Iterator[T] - - // Remove removes a single element from the set. - Remove(i T) - - // RemoveAll removes multiple elements from the set. - RemoveAll(i ...T) - - // String provides a convenient string representation - // of the current state of the set. - String() string - - // SymmetricDifference returns a new set with all elements which are - // in either this set or the other set but not in both. - // - // Note that the argument to SymmetricDifference - // must be of the same type as the receiver - // of the method. Otherwise, SymmetricDifference - // will panic. - SymmetricDifference(other Set[T]) Set[T] - - // Union returns a new set with all elements in both sets. - // - // Note that the argument to Union must be of the - // same type as the receiver of the method. - // Otherwise, Union will panic. - Union(other Set[T]) Set[T] - - // Pop removes and returns an arbitrary item from the set. - Pop() (T, bool) - - // ToSlice returns the members of the set as a slice. - ToSlice() []T - - // MarshalJSON will marshal the set into a JSON-based representation. - MarshalJSON() ([]byte, error) - - // UnmarshalJSON will unmarshal a JSON-based byte slice into a full Set datastructure. - // For this to work, set subtypes must implemented the Marshal/Unmarshal interface. - UnmarshalJSON(b []byte) error -} - -// NewSet creates and returns a new set with the given elements. -// Operations on the resulting set are thread-safe. -func NewSet[T comparable](vals ...T) Set[T] { - s := newThreadSafeSetWithSize[T](len(vals)) - for _, item := range vals { - s.Add(item) - } - return s -} - -// NewSetWithSize creates and returns a reference to an empty set with a specified -// capacity. Operations on the resulting set are thread-safe. -func NewSetWithSize[T comparable](cardinality int) Set[T] { - s := newThreadSafeSetWithSize[T](cardinality) - return s -} - -// NewThreadUnsafeSet creates and returns a new set with the given elements. -// Operations on the resulting set are not thread-safe. -func NewThreadUnsafeSet[T comparable](vals ...T) Set[T] { - s := newThreadUnsafeSetWithSize[T](len(vals)) - for _, item := range vals { - s.Add(item) - } - return s -} - -// NewThreadUnsafeSetWithSize creates and returns a reference to an empty set with -// a specified capacity. Operations on the resulting set are not thread-safe. -func NewThreadUnsafeSetWithSize[T comparable](cardinality int) Set[T] { - s := newThreadUnsafeSetWithSize[T](cardinality) - return s -} - -// NewSetFromMapKeys creates and returns a new set with the given keys of the map. -// Operations on the resulting set are thread-safe. -func NewSetFromMapKeys[T comparable, V any](val map[T]V) Set[T] { - s := NewSetWithSize[T](len(val)) - - for k := range val { - s.Add(k) - } - - return s -} - -// NewThreadUnsafeSetFromMapKeys creates and returns a new set with the given keys of the map. -// Operations on the resulting set are not thread-safe. -func NewThreadUnsafeSetFromMapKeys[T comparable, V any](val map[T]V) Set[T] { - s := NewThreadUnsafeSetWithSize[T](len(val)) - - for k := range val { - s.Add(k) - } - - return s -} - -// Elements returns an iterator that yields the elements of the set. Starting -// with Go 1.23, users can use a for loop to iterate over it. -func Elements[T comparable](s Set[T]) func(func(element T) bool) { - return func(yield func(element T) bool) { - s.Each(func(t T) bool { - return !yield(t) - }) - } -} diff --git a/vendor/github.com/deckarep/golang-set/v2/sorted.go b/vendor/github.com/deckarep/golang-set/v2/sorted.go deleted file mode 100644 index 8ee2e70..0000000 --- a/vendor/github.com/deckarep/golang-set/v2/sorted.go +++ /dev/null @@ -1,42 +0,0 @@ -//go:build go1.21 -// +build go1.21 - -/* -Open Source Initiative OSI - The MIT License (MIT):Licensing - -The MIT License (MIT) -Copyright (c) 2013 - 2023 Ralph Caraveo (deckarep@gmail.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -package mapset - -import ( - "cmp" - "slices" -) - -// Sorted returns a sorted slice of a set of any ordered type in ascending order. -// When sorting floating-point numbers, NaNs are ordered before other values. -func Sorted[E cmp.Ordered](set Set[E]) []E { - s := set.ToSlice() - slices.Sort(s) - return s -} diff --git a/vendor/github.com/deckarep/golang-set/v2/threadsafe.go b/vendor/github.com/deckarep/golang-set/v2/threadsafe.go deleted file mode 100644 index 664fc61..0000000 --- a/vendor/github.com/deckarep/golang-set/v2/threadsafe.go +++ /dev/null @@ -1,312 +0,0 @@ -/* -Open Source Initiative OSI - The MIT License (MIT):Licensing - -The MIT License (MIT) -Copyright (c) 2013 - 2022 Ralph Caraveo (deckarep@gmail.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -package mapset - -import "sync" - -type threadSafeSet[T comparable] struct { - sync.RWMutex - uss *threadUnsafeSet[T] -} - -func newThreadSafeSet[T comparable]() *threadSafeSet[T] { - return &threadSafeSet[T]{ - uss: newThreadUnsafeSet[T](), - } -} - -func newThreadSafeSetWithSize[T comparable](cardinality int) *threadSafeSet[T] { - return &threadSafeSet[T]{ - uss: newThreadUnsafeSetWithSize[T](cardinality), - } -} - -func (t *threadSafeSet[T]) Add(v T) bool { - t.Lock() - ret := t.uss.Add(v) - t.Unlock() - return ret -} - -func (t *threadSafeSet[T]) Append(v ...T) int { - t.Lock() - ret := t.uss.Append(v...) - t.Unlock() - return ret -} - -func (t *threadSafeSet[T]) Contains(v ...T) bool { - t.RLock() - ret := t.uss.Contains(v...) - t.RUnlock() - - return ret -} - -func (t *threadSafeSet[T]) ContainsOne(v T) bool { - t.RLock() - ret := t.uss.ContainsOne(v) - t.RUnlock() - - return ret -} - -func (t *threadSafeSet[T]) ContainsAny(v ...T) bool { - t.RLock() - ret := t.uss.ContainsAny(v...) - t.RUnlock() - - return ret -} - -func (t *threadSafeSet[T]) ContainsAnyElement(other Set[T]) bool { - o := other.(*threadSafeSet[T]) - - t.RLock() - o.RLock() - - ret := t.uss.ContainsAnyElement(o.uss) - - t.RUnlock() - o.RUnlock() - return ret -} - -func (t *threadSafeSet[T]) IsEmpty() bool { - return t.Cardinality() == 0 -} - -func (t *threadSafeSet[T]) IsSubset(other Set[T]) bool { - o := other.(*threadSafeSet[T]) - - t.RLock() - o.RLock() - - ret := t.uss.IsSubset(o.uss) - t.RUnlock() - o.RUnlock() - return ret -} - -func (t *threadSafeSet[T]) IsProperSubset(other Set[T]) bool { - o := other.(*threadSafeSet[T]) - - t.RLock() - defer t.RUnlock() - o.RLock() - defer o.RUnlock() - - return t.uss.IsProperSubset(o.uss) -} - -func (t *threadSafeSet[T]) IsSuperset(other Set[T]) bool { - return other.IsSubset(t) -} - -func (t *threadSafeSet[T]) IsProperSuperset(other Set[T]) bool { - return other.IsProperSubset(t) -} - -func (t *threadSafeSet[T]) Union(other Set[T]) Set[T] { - o := other.(*threadSafeSet[T]) - - t.RLock() - o.RLock() - - unsafeUnion := t.uss.Union(o.uss).(*threadUnsafeSet[T]) - ret := &threadSafeSet[T]{uss: unsafeUnion} - t.RUnlock() - o.RUnlock() - return ret -} - -func (t *threadSafeSet[T]) Intersect(other Set[T]) Set[T] { - o := other.(*threadSafeSet[T]) - - t.RLock() - o.RLock() - - unsafeIntersection := t.uss.Intersect(o.uss).(*threadUnsafeSet[T]) - ret := &threadSafeSet[T]{uss: unsafeIntersection} - t.RUnlock() - o.RUnlock() - return ret -} - -func (t *threadSafeSet[T]) Difference(other Set[T]) Set[T] { - o := other.(*threadSafeSet[T]) - - t.RLock() - o.RLock() - - unsafeDifference := t.uss.Difference(o.uss).(*threadUnsafeSet[T]) - ret := &threadSafeSet[T]{uss: unsafeDifference} - t.RUnlock() - o.RUnlock() - return ret -} - -func (t *threadSafeSet[T]) SymmetricDifference(other Set[T]) Set[T] { - o := other.(*threadSafeSet[T]) - - t.RLock() - o.RLock() - - unsafeDifference := t.uss.SymmetricDifference(o.uss).(*threadUnsafeSet[T]) - ret := &threadSafeSet[T]{uss: unsafeDifference} - t.RUnlock() - o.RUnlock() - return ret -} - -func (t *threadSafeSet[T]) Clear() { - t.Lock() - t.uss.Clear() - t.Unlock() -} - -func (t *threadSafeSet[T]) Remove(v T) { - t.Lock() - delete(*t.uss, v) - t.Unlock() -} - -func (t *threadSafeSet[T]) RemoveAll(i ...T) { - t.Lock() - t.uss.RemoveAll(i...) - t.Unlock() -} - -func (t *threadSafeSet[T]) Cardinality() int { - t.RLock() - defer t.RUnlock() - return len(*t.uss) -} - -func (t *threadSafeSet[T]) Each(cb func(T) bool) { - t.RLock() - for elem := range *t.uss { - if cb(elem) { - break - } - } - t.RUnlock() -} - -func (t *threadSafeSet[T]) Iter() <-chan T { - ch := make(chan T) - go func() { - t.RLock() - - for elem := range *t.uss { - ch <- elem - } - close(ch) - t.RUnlock() - }() - - return ch -} - -func (t *threadSafeSet[T]) Iterator() *Iterator[T] { - iterator, ch, stopCh := newIterator[T]() - - go func() { - t.RLock() - L: - for elem := range *t.uss { - select { - case <-stopCh: - break L - case ch <- elem: - } - } - close(ch) - t.RUnlock() - }() - - return iterator -} - -func (t *threadSafeSet[T]) Equal(other Set[T]) bool { - o := other.(*threadSafeSet[T]) - - t.RLock() - o.RLock() - - ret := t.uss.Equal(o.uss) - t.RUnlock() - o.RUnlock() - return ret -} - -func (t *threadSafeSet[T]) Clone() Set[T] { - t.RLock() - - unsafeClone := t.uss.Clone().(*threadUnsafeSet[T]) - ret := &threadSafeSet[T]{uss: unsafeClone} - t.RUnlock() - return ret -} - -func (t *threadSafeSet[T]) String() string { - t.RLock() - ret := t.uss.String() - t.RUnlock() - return ret -} - -func (t *threadSafeSet[T]) Pop() (T, bool) { - t.Lock() - defer t.Unlock() - return t.uss.Pop() -} - -func (t *threadSafeSet[T]) ToSlice() []T { - keys := make([]T, 0, t.Cardinality()) - t.RLock() - for elem := range *t.uss { - keys = append(keys, elem) - } - t.RUnlock() - return keys -} - -func (t *threadSafeSet[T]) MarshalJSON() ([]byte, error) { - t.RLock() - b, err := t.uss.MarshalJSON() - t.RUnlock() - - return b, err -} - -func (t *threadSafeSet[T]) UnmarshalJSON(p []byte) error { - t.RLock() - err := t.uss.UnmarshalJSON(p) - t.RUnlock() - - return err -} diff --git a/vendor/github.com/deckarep/golang-set/v2/threadunsafe.go b/vendor/github.com/deckarep/golang-set/v2/threadunsafe.go deleted file mode 100644 index c95d32b..0000000 --- a/vendor/github.com/deckarep/golang-set/v2/threadunsafe.go +++ /dev/null @@ -1,352 +0,0 @@ -/* -Open Source Initiative OSI - The MIT License (MIT):Licensing - -The MIT License (MIT) -Copyright (c) 2013 - 2022 Ralph Caraveo (deckarep@gmail.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -package mapset - -import ( - "encoding/json" - "fmt" - "strings" -) - -type threadUnsafeSet[T comparable] map[T]struct{} - -// Assert concrete type:threadUnsafeSet adheres to Set interface. -var _ Set[string] = (*threadUnsafeSet[string])(nil) - -func newThreadUnsafeSet[T comparable]() *threadUnsafeSet[T] { - t := make(threadUnsafeSet[T]) - return &t -} - -func newThreadUnsafeSetWithSize[T comparable](cardinality int) *threadUnsafeSet[T] { - t := make(threadUnsafeSet[T], cardinality) - return &t -} - -func (s threadUnsafeSet[T]) Add(v T) bool { - prevLen := len(s) - s[v] = struct{}{} - return prevLen != len(s) -} - -func (s *threadUnsafeSet[T]) Append(v ...T) int { - prevLen := len(*s) - for _, val := range v { - (*s)[val] = struct{}{} - } - return len(*s) - prevLen -} - -// private version of Add which doesn't return a value -func (s *threadUnsafeSet[T]) add(v T) { - (*s)[v] = struct{}{} -} - -func (s *threadUnsafeSet[T]) Cardinality() int { - return len(*s) -} - -func (s *threadUnsafeSet[T]) Clear() { - // Constructions like this are optimised by compiler, and replaced by - // mapclear() function, defined in - // https://github.com/golang/go/blob/29bbca5c2c1ad41b2a9747890d183b6dd3a4ace4/src/runtime/map.go#L993) - for key := range *s { - delete(*s, key) - } -} - -func (s *threadUnsafeSet[T]) Clone() Set[T] { - clonedSet := newThreadUnsafeSetWithSize[T](s.Cardinality()) - for elem := range *s { - clonedSet.add(elem) - } - return clonedSet -} - -func (s *threadUnsafeSet[T]) Contains(v ...T) bool { - for _, val := range v { - if _, ok := (*s)[val]; !ok { - return false - } - } - return true -} - -func (s *threadUnsafeSet[T]) ContainsOne(v T) bool { - _, ok := (*s)[v] - return ok -} - -func (s *threadUnsafeSet[T]) ContainsAny(v ...T) bool { - for _, val := range v { - if _, ok := (*s)[val]; ok { - return true - } - } - return false -} - -func (s *threadUnsafeSet[T]) ContainsAnyElement(other Set[T]) bool { - o := other.(*threadUnsafeSet[T]) - - // loop over smaller set - if s.Cardinality() < other.Cardinality() { - for elem := range *s { - if o.contains(elem) { - return true - } - } - } else { - for elem := range *o { - if s.contains(elem) { - return true - } - } - } - return false -} - -// private version of Contains for a single element v -func (s *threadUnsafeSet[T]) contains(v T) (ok bool) { - _, ok = (*s)[v] - return ok -} - -func (s *threadUnsafeSet[T]) Difference(other Set[T]) Set[T] { - o := other.(*threadUnsafeSet[T]) - - diff := newThreadUnsafeSet[T]() - for elem := range *s { - if !o.contains(elem) { - diff.add(elem) - } - } - return diff -} - -func (s *threadUnsafeSet[T]) Each(cb func(T) bool) { - for elem := range *s { - if cb(elem) { - break - } - } -} - -func (s *threadUnsafeSet[T]) Equal(other Set[T]) bool { - o := other.(*threadUnsafeSet[T]) - - if s.Cardinality() != other.Cardinality() { - return false - } - for elem := range *s { - if !o.contains(elem) { - return false - } - } - return true -} - -func (s *threadUnsafeSet[T]) Intersect(other Set[T]) Set[T] { - o := other.(*threadUnsafeSet[T]) - - intersection := newThreadUnsafeSet[T]() - // loop over smaller set - if s.Cardinality() < other.Cardinality() { - for elem := range *s { - if o.contains(elem) { - intersection.add(elem) - } - } - } else { - for elem := range *o { - if s.contains(elem) { - intersection.add(elem) - } - } - } - return intersection -} - -func (s *threadUnsafeSet[T]) IsEmpty() bool { - return s.Cardinality() == 0 -} - -func (s *threadUnsafeSet[T]) IsProperSubset(other Set[T]) bool { - return s.Cardinality() < other.Cardinality() && s.IsSubset(other) -} - -func (s *threadUnsafeSet[T]) IsProperSuperset(other Set[T]) bool { - return s.Cardinality() > other.Cardinality() && s.IsSuperset(other) -} - -func (s *threadUnsafeSet[T]) IsSubset(other Set[T]) bool { - o := other.(*threadUnsafeSet[T]) - if s.Cardinality() > other.Cardinality() { - return false - } - for elem := range *s { - if !o.contains(elem) { - return false - } - } - return true -} - -func (s *threadUnsafeSet[T]) IsSuperset(other Set[T]) bool { - return other.IsSubset(s) -} - -func (s *threadUnsafeSet[T]) Iter() <-chan T { - ch := make(chan T) - go func() { - for elem := range *s { - ch <- elem - } - close(ch) - }() - - return ch -} - -func (s *threadUnsafeSet[T]) Iterator() *Iterator[T] { - iterator, ch, stopCh := newIterator[T]() - - go func() { - L: - for elem := range *s { - select { - case <-stopCh: - break L - case ch <- elem: - } - } - close(ch) - }() - - return iterator -} - -// Pop returns a popped item in case set is not empty, or nil-value of T -// if set is already empty -func (s *threadUnsafeSet[T]) Pop() (v T, ok bool) { - for item := range *s { - delete(*s, item) - return item, true - } - return v, false -} - -func (s threadUnsafeSet[T]) Remove(v T) { - delete(s, v) -} - -func (s threadUnsafeSet[T]) RemoveAll(i ...T) { - for _, elem := range i { - delete(s, elem) - } -} - -func (s threadUnsafeSet[T]) String() string { - items := make([]string, 0, len(s)) - - for elem := range s { - items = append(items, fmt.Sprintf("%v", elem)) - } - return fmt.Sprintf("Set{%s}", strings.Join(items, ", ")) -} - -func (s *threadUnsafeSet[T]) SymmetricDifference(other Set[T]) Set[T] { - o := other.(*threadUnsafeSet[T]) - - sd := newThreadUnsafeSet[T]() - for elem := range *s { - if !o.contains(elem) { - sd.add(elem) - } - } - for elem := range *o { - if !s.contains(elem) { - sd.add(elem) - } - } - return sd -} - -func (s threadUnsafeSet[T]) ToSlice() []T { - keys := make([]T, 0, s.Cardinality()) - for elem := range s { - keys = append(keys, elem) - } - - return keys -} - -func (s threadUnsafeSet[T]) Union(other Set[T]) Set[T] { - o := other.(*threadUnsafeSet[T]) - - n := s.Cardinality() - if o.Cardinality() > n { - n = o.Cardinality() - } - unionedSet := make(threadUnsafeSet[T], n) - - for elem := range s { - unionedSet.add(elem) - } - for elem := range *o { - unionedSet.add(elem) - } - return &unionedSet -} - -// MarshalJSON creates a JSON array from the set, it marshals all elements -func (s threadUnsafeSet[T]) MarshalJSON() ([]byte, error) { - items := make([]string, 0, s.Cardinality()) - - for elem := range s { - b, err := json.Marshal(elem) - if err != nil { - return nil, err - } - - items = append(items, string(b)) - } - - return []byte(fmt.Sprintf("[%s]", strings.Join(items, ","))), nil -} - -// UnmarshalJSON recreates a set from a JSON array, it only decodes -// primitive types. Numbers are decoded as json.Number. -func (s *threadUnsafeSet[T]) UnmarshalJSON(b []byte) error { - var i []T - err := json.Unmarshal(b, &i) - if err != nil { - return err - } - s.Append(i...) - - return nil -} diff --git a/vendor/github.com/go-stack/stack/LICENSE.md b/vendor/github.com/go-stack/stack/LICENSE.md deleted file mode 100644 index 2abf98e..0000000 --- a/vendor/github.com/go-stack/stack/LICENSE.md +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Chris Hines - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/github.com/go-stack/stack/README.md b/vendor/github.com/go-stack/stack/README.md deleted file mode 100644 index f11cccc..0000000 --- a/vendor/github.com/go-stack/stack/README.md +++ /dev/null @@ -1,38 +0,0 @@ -[](https://godoc.org/github.com/go-stack/stack) -[](https://goreportcard.com/report/go-stack/stack) -[](https://travis-ci.org/go-stack/stack) -[](https://coveralls.io/github/go-stack/stack?branch=master) - -# stack - -Package stack implements utilities to capture, manipulate, and format call -stacks. It provides a simpler API than package runtime. - -The implementation takes care of the minutia and special cases of interpreting -the program counter (pc) values returned by runtime.Callers. - -## Versioning - -Package stack publishes releases via [semver](http://semver.org/) compatible Git -tags prefixed with a single 'v'. The master branch always contains the latest -release. The develop branch contains unreleased commits. - -## Formatting - -Package stack's types implement fmt.Formatter, which provides a simple and -flexible way to declaratively configure formatting when used with logging or -error tracking packages. - -```go -func DoTheThing() { - c := stack.Caller(0) - log.Print(c) // "source.go:10" - log.Printf("%+v", c) // "pkg/path/source.go:10" - log.Printf("%n", c) // "DoTheThing" - - s := stack.Trace().TrimRuntime() - log.Print(s) // "[source.go:15 caller.go:42 main.go:14]" -} -``` - -See the docs for all of the supported formatting options. diff --git a/vendor/github.com/go-stack/stack/stack.go b/vendor/github.com/go-stack/stack/stack.go deleted file mode 100644 index ac3b93b..0000000 --- a/vendor/github.com/go-stack/stack/stack.go +++ /dev/null @@ -1,400 +0,0 @@ -// +build go1.7 - -// Package stack implements utilities to capture, manipulate, and format call -// stacks. It provides a simpler API than package runtime. -// -// The implementation takes care of the minutia and special cases of -// interpreting the program counter (pc) values returned by runtime.Callers. -// -// Package stack's types implement fmt.Formatter, which provides a simple and -// flexible way to declaratively configure formatting when used with logging -// or error tracking packages. -package stack - -import ( - "bytes" - "errors" - "fmt" - "io" - "runtime" - "strconv" - "strings" -) - -// Call records a single function invocation from a goroutine stack. -type Call struct { - frame runtime.Frame -} - -// Caller returns a Call from the stack of the current goroutine. The argument -// skip is the number of stack frames to ascend, with 0 identifying the -// calling function. -func Caller(skip int) Call { - // As of Go 1.9 we need room for up to three PC entries. - // - // 0. An entry for the stack frame prior to the target to check for - // special handling needed if that prior entry is runtime.sigpanic. - // 1. A possible second entry to hold metadata about skipped inlined - // functions. If inline functions were not skipped the target frame - // PC will be here. - // 2. A third entry for the target frame PC when the second entry - // is used for skipped inline functions. - var pcs [3]uintptr - n := runtime.Callers(skip+1, pcs[:]) - frames := runtime.CallersFrames(pcs[:n]) - frame, _ := frames.Next() - frame, _ = frames.Next() - - return Call{ - frame: frame, - } -} - -// String implements fmt.Stinger. It is equivalent to fmt.Sprintf("%v", c). -func (c Call) String() string { - return fmt.Sprint(c) -} - -// MarshalText implements encoding.TextMarshaler. It formats the Call the same -// as fmt.Sprintf("%v", c). -func (c Call) MarshalText() ([]byte, error) { - if c.frame == (runtime.Frame{}) { - return nil, ErrNoFunc - } - - buf := bytes.Buffer{} - fmt.Fprint(&buf, c) - return buf.Bytes(), nil -} - -// ErrNoFunc means that the Call has a nil *runtime.Func. The most likely -// cause is a Call with the zero value. -var ErrNoFunc = errors.New("no call stack information") - -// Format implements fmt.Formatter with support for the following verbs. -// -// %s source file -// %d line number -// %n function name -// %k last segment of the package path -// %v equivalent to %s:%d -// -// It accepts the '+' and '#' flags for most of the verbs as follows. -// -// %+s path of source file relative to the compile time GOPATH, -// or the module path joined to the path of source file relative -// to module root -// %#s full path of source file -// %+n import path qualified function name -// %+k full package path -// %+v equivalent to %+s:%d -// %#v equivalent to %#s:%d -func (c Call) Format(s fmt.State, verb rune) { - if c.frame == (runtime.Frame{}) { - fmt.Fprintf(s, "%%!%c(NOFUNC)", verb) - return - } - - switch verb { - case 's', 'v': - file := c.frame.File - switch { - case s.Flag('#'): - // done - case s.Flag('+'): - file = pkgFilePath(&c.frame) - default: - const sep = "/" - if i := strings.LastIndex(file, sep); i != -1 { - file = file[i+len(sep):] - } - } - io.WriteString(s, file) - if verb == 'v' { - buf := [7]byte{':'} - s.Write(strconv.AppendInt(buf[:1], int64(c.frame.Line), 10)) - } - - case 'd': - buf := [6]byte{} - s.Write(strconv.AppendInt(buf[:0], int64(c.frame.Line), 10)) - - case 'k': - name := c.frame.Function - const pathSep = "/" - start, end := 0, len(name) - if i := strings.LastIndex(name, pathSep); i != -1 { - start = i + len(pathSep) - } - const pkgSep = "." - if i := strings.Index(name[start:], pkgSep); i != -1 { - end = start + i - } - if s.Flag('+') { - start = 0 - } - io.WriteString(s, name[start:end]) - - case 'n': - name := c.frame.Function - if !s.Flag('+') { - const pathSep = "/" - if i := strings.LastIndex(name, pathSep); i != -1 { - name = name[i+len(pathSep):] - } - const pkgSep = "." - if i := strings.Index(name, pkgSep); i != -1 { - name = name[i+len(pkgSep):] - } - } - io.WriteString(s, name) - } -} - -// Frame returns the call frame infomation for the Call. -func (c Call) Frame() runtime.Frame { - return c.frame -} - -// PC returns the program counter for this call frame; multiple frames may -// have the same PC value. -// -// Deprecated: Use Call.Frame instead. -func (c Call) PC() uintptr { - return c.frame.PC -} - -// CallStack records a sequence of function invocations from a goroutine -// stack. -type CallStack []Call - -// String implements fmt.Stinger. It is equivalent to fmt.Sprintf("%v", cs). -func (cs CallStack) String() string { - return fmt.Sprint(cs) -} - -var ( - openBracketBytes = []byte("[") - closeBracketBytes = []byte("]") - spaceBytes = []byte(" ") -) - -// MarshalText implements encoding.TextMarshaler. It formats the CallStack the -// same as fmt.Sprintf("%v", cs). -func (cs CallStack) MarshalText() ([]byte, error) { - buf := bytes.Buffer{} - buf.Write(openBracketBytes) - for i, pc := range cs { - if i > 0 { - buf.Write(spaceBytes) - } - fmt.Fprint(&buf, pc) - } - buf.Write(closeBracketBytes) - return buf.Bytes(), nil -} - -// Format implements fmt.Formatter by printing the CallStack as square brackets -// ([, ]) surrounding a space separated list of Calls each formatted with the -// supplied verb and options. -func (cs CallStack) Format(s fmt.State, verb rune) { - s.Write(openBracketBytes) - for i, pc := range cs { - if i > 0 { - s.Write(spaceBytes) - } - pc.Format(s, verb) - } - s.Write(closeBracketBytes) -} - -// Trace returns a CallStack for the current goroutine with element 0 -// identifying the calling function. -func Trace() CallStack { - var pcs [512]uintptr - n := runtime.Callers(1, pcs[:]) - - frames := runtime.CallersFrames(pcs[:n]) - cs := make(CallStack, 0, n) - - // Skip extra frame retrieved just to make sure the runtime.sigpanic - // special case is handled. - frame, more := frames.Next() - - for more { - frame, more = frames.Next() - cs = append(cs, Call{frame: frame}) - } - - return cs -} - -// TrimBelow returns a slice of the CallStack with all entries below c -// removed. -func (cs CallStack) TrimBelow(c Call) CallStack { - for len(cs) > 0 && cs[0] != c { - cs = cs[1:] - } - return cs -} - -// TrimAbove returns a slice of the CallStack with all entries above c -// removed. -func (cs CallStack) TrimAbove(c Call) CallStack { - for len(cs) > 0 && cs[len(cs)-1] != c { - cs = cs[:len(cs)-1] - } - return cs -} - -// pkgIndex returns the index that results in file[index:] being the path of -// file relative to the compile time GOPATH, and file[:index] being the -// $GOPATH/src/ portion of file. funcName must be the name of a function in -// file as returned by runtime.Func.Name. -func pkgIndex(file, funcName string) int { - // As of Go 1.6.2 there is no direct way to know the compile time GOPATH - // at runtime, but we can infer the number of path segments in the GOPATH. - // We note that runtime.Func.Name() returns the function name qualified by - // the import path, which does not include the GOPATH. Thus we can trim - // segments from the beginning of the file path until the number of path - // separators remaining is one more than the number of path separators in - // the function name. For example, given: - // - // GOPATH /home/user - // file /home/user/src/pkg/sub/file.go - // fn.Name() pkg/sub.Type.Method - // - // We want to produce: - // - // file[:idx] == /home/user/src/ - // file[idx:] == pkg/sub/file.go - // - // From this we can easily see that fn.Name() has one less path separator - // than our desired result for file[idx:]. We count separators from the - // end of the file path until it finds two more than in the function name - // and then move one character forward to preserve the initial path - // segment without a leading separator. - const sep = "/" - i := len(file) - for n := strings.Count(funcName, sep) + 2; n > 0; n-- { - i = strings.LastIndex(file[:i], sep) - if i == -1 { - i = -len(sep) - break - } - } - // get back to 0 or trim the leading separator - return i + len(sep) -} - -// pkgFilePath returns the frame's filepath relative to the compile-time GOPATH, -// or its module path joined to its path relative to the module root. -// -// As of Go 1.11 there is no direct way to know the compile time GOPATH or -// module paths at runtime, but we can piece together the desired information -// from available information. We note that runtime.Frame.Function contains the -// function name qualified by the package path, which includes the module path -// but not the GOPATH. We can extract the package path from that and append the -// last segments of the file path to arrive at the desired package qualified -// file path. For example, given: -// -// GOPATH /home/user -// import path pkg/sub -// frame.File /home/user/src/pkg/sub/file.go -// frame.Function pkg/sub.Type.Method -// Desired return pkg/sub/file.go -// -// It appears that we simply need to trim ".Type.Method" from frame.Function and -// append "/" + path.Base(file). -// -// But there are other wrinkles. Although it is idiomatic to do so, the internal -// name of a package is not required to match the last segment of its import -// path. In addition, the introduction of modules in Go 1.11 allows working -// without a GOPATH. So we also must make these work right: -// -// GOPATH /home/user -// import path pkg/go-sub -// package name sub -// frame.File /home/user/src/pkg/go-sub/file.go -// frame.Function pkg/sub.Type.Method -// Desired return pkg/go-sub/file.go -// -// Module path pkg/v2 -// import path pkg/v2/go-sub -// package name sub -// frame.File /home/user/cloned-pkg/go-sub/file.go -// frame.Function pkg/v2/sub.Type.Method -// Desired return pkg/v2/go-sub/file.go -// -// We can handle all of these situations by using the package path extracted -// from frame.Function up to, but not including, the last segment as the prefix -// and the last two segments of frame.File as the suffix of the returned path. -// This preserves the existing behavior when working in a GOPATH without modules -// and a semantically equivalent behavior when used in module aware project. -func pkgFilePath(frame *runtime.Frame) string { - pre := pkgPrefix(frame.Function) - post := pathSuffix(frame.File) - if pre == "" { - return post - } - return pre + "/" + post -} - -// pkgPrefix returns the import path of the function's package with the final -// segment removed. -func pkgPrefix(funcName string) string { - const pathSep = "/" - end := strings.LastIndex(funcName, pathSep) - if end == -1 { - return "" - } - return funcName[:end] -} - -// pathSuffix returns the last two segments of path. -func pathSuffix(path string) string { - const pathSep = "/" - lastSep := strings.LastIndex(path, pathSep) - if lastSep == -1 { - return path - } - return path[strings.LastIndex(path[:lastSep], pathSep)+1:] -} - -var runtimePath string - -func init() { - var pcs [3]uintptr - runtime.Callers(0, pcs[:]) - frames := runtime.CallersFrames(pcs[:]) - frame, _ := frames.Next() - file := frame.File - - idx := pkgIndex(frame.File, frame.Function) - - runtimePath = file[:idx] - if runtime.GOOS == "windows" { - runtimePath = strings.ToLower(runtimePath) - } -} - -func inGoroot(c Call) bool { - file := c.frame.File - if len(file) == 0 || file[0] == '?' { - return true - } - if runtime.GOOS == "windows" { - file = strings.ToLower(file) - } - return strings.HasPrefix(file, runtimePath) || strings.HasSuffix(file, "/_testmain.go") -} - -// TrimRuntime returns a slice of the CallStack with the topmost entries from -// the go runtime removed. It considers any calls originating from unknown -// files, files under GOROOT, or _testmain.go as part of the runtime. -func (cs CallStack) TrimRuntime() CallStack { - for len(cs) > 0 && inGoroot(cs[len(cs)-1]) { - cs = cs[:len(cs)-1] - } - return cs -} diff --git a/vendor/github.com/lib/pq/.gitignore b/vendor/github.com/lib/pq/.gitignore new file mode 100644 index 0000000..3243952 --- /dev/null +++ b/vendor/github.com/lib/pq/.gitignore @@ -0,0 +1,6 @@ +.db +*.test +*~ +*.swp +.idea +.vscode
\ No newline at end of file diff --git a/vendor/github.com/lib/pq/LICENSE.md b/vendor/github.com/lib/pq/LICENSE.md new file mode 100644 index 0000000..5773904 --- /dev/null +++ b/vendor/github.com/lib/pq/LICENSE.md @@ -0,0 +1,8 @@ +Copyright (c) 2011-2013, 'pq' Contributors +Portions Copyright (C) 2011 Blake Mizerany + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/lib/pq/README.md b/vendor/github.com/lib/pq/README.md new file mode 100644 index 0000000..126ee5d --- /dev/null +++ b/vendor/github.com/lib/pq/README.md @@ -0,0 +1,36 @@ +# pq - A pure Go postgres driver for Go's database/sql package + +[](https://pkg.go.dev/github.com/lib/pq?tab=doc) + +## Install + + go get github.com/lib/pq + +## Features + +* SSL +* Handles bad connections for `database/sql` +* Scan `time.Time` correctly (i.e. `timestamp[tz]`, `time[tz]`, `date`) +* Scan binary blobs correctly (i.e. `bytea`) +* Package for `hstore` support +* COPY FROM support +* pq.ParseURL for converting urls to connection strings for sql.Open. +* Many libpq compatible environment variables +* Unix socket support +* Notifications: `LISTEN`/`NOTIFY` +* pgpass support +* GSS (Kerberos) auth + +## Tests + +`go test` is used for testing. See [TESTS.md](TESTS.md) for more details. + +## Status + +This package is currently in maintenance mode, which means: +1. It generally does not accept new features. +2. It does accept bug fixes and version compatability changes provided by the community. +3. Maintainers usually do not resolve reported issues. +4. Community members are encouraged to help each other with reported issues. + +For users that require new features or reliable resolution of reported bugs, we recommend using [pgx](https://github.com/jackc/pgx) which is under active development. diff --git a/vendor/github.com/lib/pq/TESTS.md b/vendor/github.com/lib/pq/TESTS.md new file mode 100644 index 0000000..f050211 --- /dev/null +++ b/vendor/github.com/lib/pq/TESTS.md @@ -0,0 +1,33 @@ +# Tests + +## Running Tests + +`go test` is used for testing. A running PostgreSQL +server is required, with the ability to log in. The +database to connect to test with is "pqgotest," on +"localhost" but these can be overridden using [environment +variables](https://www.postgresql.org/docs/9.3/static/libpq-envars.html). + +Example: + + PGHOST=/run/postgresql go test + +## Benchmarks + +A benchmark suite can be run as part of the tests: + + go test -bench . + +## Example setup (Docker) + +Run a postgres container: + +``` +docker run --expose 5432:5432 postgres +``` + +Run tests: + +``` +PGHOST=localhost PGPORT=5432 PGUSER=postgres PGSSLMODE=disable PGDATABASE=postgres go test +``` diff --git a/vendor/github.com/lib/pq/array.go b/vendor/github.com/lib/pq/array.go new file mode 100644 index 0000000..39c8f7e --- /dev/null +++ b/vendor/github.com/lib/pq/array.go @@ -0,0 +1,895 @@ +package pq + +import ( + "bytes" + "database/sql" + "database/sql/driver" + "encoding/hex" + "fmt" + "reflect" + "strconv" + "strings" +) + +var typeByteSlice = reflect.TypeOf([]byte{}) +var typeDriverValuer = reflect.TypeOf((*driver.Valuer)(nil)).Elem() +var typeSQLScanner = reflect.TypeOf((*sql.Scanner)(nil)).Elem() + +// Array returns the optimal driver.Valuer and sql.Scanner for an array or +// slice of any dimension. +// +// For example: +// db.Query(`SELECT * FROM t WHERE id = ANY($1)`, pq.Array([]int{235, 401})) +// +// var x []sql.NullInt64 +// db.QueryRow(`SELECT ARRAY[235, 401]`).Scan(pq.Array(&x)) +// +// Scanning multi-dimensional arrays is not supported. Arrays where the lower +// bound is not one (such as `[0:0]={1}') are not supported. +func Array(a interface{}) interface { + driver.Valuer + sql.Scanner +} { + switch a := a.(type) { + case []bool: + return (*BoolArray)(&a) + case []float64: + return (*Float64Array)(&a) + case []float32: + return (*Float32Array)(&a) + case []int64: + return (*Int64Array)(&a) + case []int32: + return (*Int32Array)(&a) + case []string: + return (*StringArray)(&a) + case [][]byte: + return (*ByteaArray)(&a) + + case *[]bool: + return (*BoolArray)(a) + case *[]float64: + return (*Float64Array)(a) + case *[]float32: + return (*Float32Array)(a) + case *[]int64: + return (*Int64Array)(a) + case *[]int32: + return (*Int32Array)(a) + case *[]string: + return (*StringArray)(a) + case *[][]byte: + return (*ByteaArray)(a) + } + + return GenericArray{a} +} + +// ArrayDelimiter may be optionally implemented by driver.Valuer or sql.Scanner +// to override the array delimiter used by GenericArray. +type ArrayDelimiter interface { + // ArrayDelimiter returns the delimiter character(s) for this element's type. + ArrayDelimiter() string +} + +// BoolArray represents a one-dimensional array of the PostgreSQL boolean type. +type BoolArray []bool + +// Scan implements the sql.Scanner interface. +func (a *BoolArray) Scan(src interface{}) error { + switch src := src.(type) { + case []byte: + return a.scanBytes(src) + case string: + return a.scanBytes([]byte(src)) + case nil: + *a = nil + return nil + } + + return fmt.Errorf("pq: cannot convert %T to BoolArray", src) +} + +func (a *BoolArray) scanBytes(src []byte) error { + elems, err := scanLinearArray(src, []byte{','}, "BoolArray") + if err != nil { + return err + } + if *a != nil && len(elems) == 0 { + *a = (*a)[:0] + } else { + b := make(BoolArray, len(elems)) + for i, v := range elems { + if len(v) != 1 { + return fmt.Errorf("pq: could not parse boolean array index %d: invalid boolean %q", i, v) + } + switch v[0] { + case 't': + b[i] = true + case 'f': + b[i] = false + default: + return fmt.Errorf("pq: could not parse boolean array index %d: invalid boolean %q", i, v) + } + } + *a = b + } + return nil +} + +// Value implements the driver.Valuer interface. +func (a BoolArray) Value() (driver.Value, error) { + if a == nil { + return nil, nil + } + + if n := len(a); n > 0 { + // There will be exactly two curly brackets, N bytes of values, + // and N-1 bytes of delimiters. + b := make([]byte, 1+2*n) + + for i := 0; i < n; i++ { + b[2*i] = ',' + if a[i] { + b[1+2*i] = 't' + } else { + b[1+2*i] = 'f' + } + } + + b[0] = '{' + b[2*n] = '}' + + return string(b), nil + } + + return "{}", nil +} + +// ByteaArray represents a one-dimensional array of the PostgreSQL bytea type. +type ByteaArray [][]byte + +// Scan implements the sql.Scanner interface. +func (a *ByteaArray) Scan(src interface{}) error { + switch src := src.(type) { + case []byte: + return a.scanBytes(src) + case string: + return a.scanBytes([]byte(src)) + case nil: + *a = nil + return nil + } + + return fmt.Errorf("pq: cannot convert %T to ByteaArray", src) +} + +func (a *ByteaArray) scanBytes(src []byte) error { + elems, err := scanLinearArray(src, []byte{','}, "ByteaArray") + if err != nil { + return err + } + if *a != nil && len(elems) == 0 { + *a = (*a)[:0] + } else { + b := make(ByteaArray, len(elems)) + for i, v := range elems { + b[i], err = parseBytea(v) + if err != nil { + return fmt.Errorf("could not parse bytea array index %d: %s", i, err.Error()) + } + } + *a = b + } + return nil +} + +// Value implements the driver.Valuer interface. It uses the "hex" format which +// is only supported on PostgreSQL 9.0 or newer. +func (a ByteaArray) Value() (driver.Value, error) { + if a == nil { + return nil, nil + } + + if n := len(a); n > 0 { + // There will be at least two curly brackets, 2*N bytes of quotes, + // 3*N bytes of hex formatting, and N-1 bytes of delimiters. + size := 1 + 6*n + for _, x := range a { + size += hex.EncodedLen(len(x)) + } + + b := make([]byte, size) + + for i, s := 0, b; i < n; i++ { + o := copy(s, `,"\\x`) + o += hex.Encode(s[o:], a[i]) + s[o] = '"' + s = s[o+1:] + } + + b[0] = '{' + b[size-1] = '}' + + return string(b), nil + } + + return "{}", nil +} + +// Float64Array represents a one-dimensional array of the PostgreSQL double +// precision type. +type Float64Array []float64 + +// Scan implements the sql.Scanner interface. +func (a *Float64Array) Scan(src interface{}) error { + switch src := src.(type) { + case []byte: + return a.scanBytes(src) + case string: + return a.scanBytes([]byte(src)) + case nil: + *a = nil + return nil + } + + return fmt.Errorf("pq: cannot convert %T to Float64Array", src) +} + +func (a *Float64Array) scanBytes(src []byte) error { + elems, err := scanLinearArray(src, []byte{','}, "Float64Array") + if err != nil { + return err + } + if *a != nil && len(elems) == 0 { + *a = (*a)[:0] + } else { + b := make(Float64Array, len(elems)) + for i, v := range elems { + if b[i], err = strconv.ParseFloat(string(v), 64); err != nil { + return fmt.Errorf("pq: parsing array element index %d: %v", i, err) + } + } + *a = b + } + return nil +} + +// Value implements the driver.Valuer interface. +func (a Float64Array) Value() (driver.Value, error) { + if a == nil { + return nil, nil + } + + if n := len(a); n > 0 { + // There will be at least two curly brackets, N bytes of values, + // and N-1 bytes of delimiters. + b := make([]byte, 1, 1+2*n) + b[0] = '{' + + b = strconv.AppendFloat(b, a[0], 'f', -1, 64) + for i := 1; i < n; i++ { + b = append(b, ',') + b = strconv.AppendFloat(b, a[i], 'f', -1, 64) + } + + return string(append(b, '}')), nil + } + + return "{}", nil +} + +// Float32Array represents a one-dimensional array of the PostgreSQL double +// precision type. +type Float32Array []float32 + +// Scan implements the sql.Scanner interface. +func (a *Float32Array) Scan(src interface{}) error { + switch src := src.(type) { + case []byte: + return a.scanBytes(src) + case string: + return a.scanBytes([]byte(src)) + case nil: + *a = nil + return nil + } + + return fmt.Errorf("pq: cannot convert %T to Float32Array", src) +} + +func (a *Float32Array) scanBytes(src []byte) error { + elems, err := scanLinearArray(src, []byte{','}, "Float32Array") + if err != nil { + return err + } + if *a != nil && len(elems) == 0 { + *a = (*a)[:0] + } else { + b := make(Float32Array, len(elems)) + for i, v := range elems { + var x float64 + if x, err = strconv.ParseFloat(string(v), 32); err != nil { + return fmt.Errorf("pq: parsing array element index %d: %v", i, err) + } + b[i] = float32(x) + } + *a = b + } + return nil +} + +// Value implements the driver.Valuer interface. +func (a Float32Array) Value() (driver.Value, error) { + if a == nil { + return nil, nil + } + + if n := len(a); n > 0 { + // There will be at least two curly brackets, N bytes of values, + // and N-1 bytes of delimiters. + b := make([]byte, 1, 1+2*n) + b[0] = '{' + + b = strconv.AppendFloat(b, float64(a[0]), 'f', -1, 32) + for i := 1; i < n; i++ { + b = append(b, ',') + b = strconv.AppendFloat(b, float64(a[i]), 'f', -1, 32) + } + + return string(append(b, '}')), nil + } + + return "{}", nil +} + +// GenericArray implements the driver.Valuer and sql.Scanner interfaces for +// an array or slice of any dimension. +type GenericArray struct{ A interface{} } + +func (GenericArray) evaluateDestination(rt reflect.Type) (reflect.Type, func([]byte, reflect.Value) error, string) { + var assign func([]byte, reflect.Value) error + var del = "," + + // TODO calculate the assign function for other types + // TODO repeat this section on the element type of arrays or slices (multidimensional) + { + if reflect.PtrTo(rt).Implements(typeSQLScanner) { + // dest is always addressable because it is an element of a slice. + assign = func(src []byte, dest reflect.Value) (err error) { + ss := dest.Addr().Interface().(sql.Scanner) + if src == nil { + err = ss.Scan(nil) + } else { + err = ss.Scan(src) + } + return + } + goto FoundType + } + + assign = func([]byte, reflect.Value) error { + return fmt.Errorf("pq: scanning to %s is not implemented; only sql.Scanner", rt) + } + } + +FoundType: + + if ad, ok := reflect.Zero(rt).Interface().(ArrayDelimiter); ok { + del = ad.ArrayDelimiter() + } + + return rt, assign, del +} + +// Scan implements the sql.Scanner interface. +func (a GenericArray) Scan(src interface{}) error { + dpv := reflect.ValueOf(a.A) + switch { + case dpv.Kind() != reflect.Ptr: + return fmt.Errorf("pq: destination %T is not a pointer to array or slice", a.A) + case dpv.IsNil(): + return fmt.Errorf("pq: destination %T is nil", a.A) + } + + dv := dpv.Elem() + switch dv.Kind() { + case reflect.Slice: + case reflect.Array: + default: + return fmt.Errorf("pq: destination %T is not a pointer to array or slice", a.A) + } + + switch src := src.(type) { + case []byte: + return a.scanBytes(src, dv) + case string: + return a.scanBytes([]byte(src), dv) + case nil: + if dv.Kind() == reflect.Slice { + dv.Set(reflect.Zero(dv.Type())) + return nil + } + } + + return fmt.Errorf("pq: cannot convert %T to %s", src, dv.Type()) +} + +func (a GenericArray) scanBytes(src []byte, dv reflect.Value) error { + dtype, assign, del := a.evaluateDestination(dv.Type().Elem()) + dims, elems, err := parseArray(src, []byte(del)) + if err != nil { + return err + } + + // TODO allow multidimensional + + if len(dims) > 1 { + return fmt.Errorf("pq: scanning from multidimensional ARRAY%s is not implemented", + strings.Replace(fmt.Sprint(dims), " ", "][", -1)) + } + + // Treat a zero-dimensional array like an array with a single dimension of zero. + if len(dims) == 0 { + dims = append(dims, 0) + } + + for i, rt := 0, dv.Type(); i < len(dims); i, rt = i+1, rt.Elem() { + switch rt.Kind() { + case reflect.Slice: + case reflect.Array: + if rt.Len() != dims[i] { + return fmt.Errorf("pq: cannot convert ARRAY%s to %s", + strings.Replace(fmt.Sprint(dims), " ", "][", -1), dv.Type()) + } + default: + // TODO handle multidimensional + } + } + + values := reflect.MakeSlice(reflect.SliceOf(dtype), len(elems), len(elems)) + for i, e := range elems { + if err := assign(e, values.Index(i)); err != nil { + return fmt.Errorf("pq: parsing array element index %d: %v", i, err) + } + } + + // TODO handle multidimensional + + switch dv.Kind() { + case reflect.Slice: + dv.Set(values.Slice(0, dims[0])) + case reflect.Array: + for i := 0; i < dims[0]; i++ { + dv.Index(i).Set(values.Index(i)) + } + } + + return nil +} + +// Value implements the driver.Valuer interface. +func (a GenericArray) Value() (driver.Value, error) { + if a.A == nil { + return nil, nil + } + + rv := reflect.ValueOf(a.A) + + switch rv.Kind() { + case reflect.Slice: + if rv.IsNil() { + return nil, nil + } + case reflect.Array: + default: + return nil, fmt.Errorf("pq: Unable to convert %T to array", a.A) + } + + if n := rv.Len(); n > 0 { + // There will be at least two curly brackets, N bytes of values, + // and N-1 bytes of delimiters. + b := make([]byte, 0, 1+2*n) + + b, _, err := appendArray(b, rv, n) + return string(b), err + } + + return "{}", nil +} + +// Int64Array represents a one-dimensional array of the PostgreSQL integer types. +type Int64Array []int64 + +// Scan implements the sql.Scanner interface. +func (a *Int64Array) Scan(src interface{}) error { + switch src := src.(type) { + case []byte: + return a.scanBytes(src) + case string: + return a.scanBytes([]byte(src)) + case nil: + *a = nil + return nil + } + + return fmt.Errorf("pq: cannot convert %T to Int64Array", src) +} + +func (a *Int64Array) scanBytes(src []byte) error { + elems, err := scanLinearArray(src, []byte{','}, "Int64Array") + if err != nil { + return err + } + if *a != nil && len(elems) == 0 { + *a = (*a)[:0] + } else { + b := make(Int64Array, len(elems)) + for i, v := range elems { + if b[i], err = strconv.ParseInt(string(v), 10, 64); err != nil { + return fmt.Errorf("pq: parsing array element index %d: %v", i, err) + } + } + *a = b + } + return nil +} + +// Value implements the driver.Valuer interface. +func (a Int64Array) Value() (driver.Value, error) { + if a == nil { + return nil, nil + } + + if n := len(a); n > 0 { + // There will be at least two curly brackets, N bytes of values, + // and N-1 bytes of delimiters. + b := make([]byte, 1, 1+2*n) + b[0] = '{' + + b = strconv.AppendInt(b, a[0], 10) + for i := 1; i < n; i++ { + b = append(b, ',') + b = strconv.AppendInt(b, a[i], 10) + } + + return string(append(b, '}')), nil + } + + return "{}", nil +} + +// Int32Array represents a one-dimensional array of the PostgreSQL integer types. +type Int32Array []int32 + +// Scan implements the sql.Scanner interface. +func (a *Int32Array) Scan(src interface{}) error { + switch src := src.(type) { + case []byte: + return a.scanBytes(src) + case string: + return a.scanBytes([]byte(src)) + case nil: + *a = nil + return nil + } + + return fmt.Errorf("pq: cannot convert %T to Int32Array", src) +} + +func (a *Int32Array) scanBytes(src []byte) error { + elems, err := scanLinearArray(src, []byte{','}, "Int32Array") + if err != nil { + return err + } + if *a != nil && len(elems) == 0 { + *a = (*a)[:0] + } else { + b := make(Int32Array, len(elems)) + for i, v := range elems { + x, err := strconv.ParseInt(string(v), 10, 32) + if err != nil { + return fmt.Errorf("pq: parsing array element index %d: %v", i, err) + } + b[i] = int32(x) + } + *a = b + } + return nil +} + +// Value implements the driver.Valuer interface. +func (a Int32Array) Value() (driver.Value, error) { + if a == nil { + return nil, nil + } + + if n := len(a); n > 0 { + // There will be at least two curly brackets, N bytes of values, + // and N-1 bytes of delimiters. + b := make([]byte, 1, 1+2*n) + b[0] = '{' + + b = strconv.AppendInt(b, int64(a[0]), 10) + for i := 1; i < n; i++ { + b = append(b, ',') + b = strconv.AppendInt(b, int64(a[i]), 10) + } + + return string(append(b, '}')), nil + } + + return "{}", nil +} + +// StringArray represents a one-dimensional array of the PostgreSQL character types. +type StringArray []string + +// Scan implements the sql.Scanner interface. +func (a *StringArray) Scan(src interface{}) error { + switch src := src.(type) { + case []byte: + return a.scanBytes(src) + case string: + return a.scanBytes([]byte(src)) + case nil: + *a = nil + return nil + } + + return fmt.Errorf("pq: cannot convert %T to StringArray", src) +} + +func (a *StringArray) scanBytes(src []byte) error { + elems, err := scanLinearArray(src, []byte{','}, "StringArray") + if err != nil { + return err + } + if *a != nil && len(elems) == 0 { + *a = (*a)[:0] + } else { + b := make(StringArray, len(elems)) + for i, v := range elems { + if b[i] = string(v); v == nil { + return fmt.Errorf("pq: parsing array element index %d: cannot convert nil to string", i) + } + } + *a = b + } + return nil +} + +// Value implements the driver.Valuer interface. +func (a StringArray) Value() (driver.Value, error) { + if a == nil { + return nil, nil + } + + if n := len(a); n > 0 { + // There will be at least two curly brackets, 2*N bytes of quotes, + // and N-1 bytes of delimiters. + b := make([]byte, 1, 1+3*n) + b[0] = '{' + + b = appendArrayQuotedBytes(b, []byte(a[0])) + for i := 1; i < n; i++ { + b = append(b, ',') + b = appendArrayQuotedBytes(b, []byte(a[i])) + } + + return string(append(b, '}')), nil + } + + return "{}", nil +} + +// appendArray appends rv to the buffer, returning the extended buffer and +// the delimiter used between elements. +// +// It panics when n <= 0 or rv's Kind is not reflect.Array nor reflect.Slice. +func appendArray(b []byte, rv reflect.Value, n int) ([]byte, string, error) { + var del string + var err error + + b = append(b, '{') + + if b, del, err = appendArrayElement(b, rv.Index(0)); err != nil { + return b, del, err + } + + for i := 1; i < n; i++ { + b = append(b, del...) + if b, del, err = appendArrayElement(b, rv.Index(i)); err != nil { + return b, del, err + } + } + + return append(b, '}'), del, nil +} + +// appendArrayElement appends rv to the buffer, returning the extended buffer +// and the delimiter to use before the next element. +// +// When rv's Kind is neither reflect.Array nor reflect.Slice, it is converted +// using driver.DefaultParameterConverter and the resulting []byte or string +// is double-quoted. +// +// See http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO +func appendArrayElement(b []byte, rv reflect.Value) ([]byte, string, error) { + if k := rv.Kind(); k == reflect.Array || k == reflect.Slice { + if t := rv.Type(); t != typeByteSlice && !t.Implements(typeDriverValuer) { + if n := rv.Len(); n > 0 { + return appendArray(b, rv, n) + } + + return b, "", nil + } + } + + var del = "," + var err error + var iv interface{} = rv.Interface() + + if ad, ok := iv.(ArrayDelimiter); ok { + del = ad.ArrayDelimiter() + } + + if iv, err = driver.DefaultParameterConverter.ConvertValue(iv); err != nil { + return b, del, err + } + + switch v := iv.(type) { + case nil: + return append(b, "NULL"...), del, nil + case []byte: + return appendArrayQuotedBytes(b, v), del, nil + case string: + return appendArrayQuotedBytes(b, []byte(v)), del, nil + } + + b, err = appendValue(b, iv) + return b, del, err +} + +func appendArrayQuotedBytes(b, v []byte) []byte { + b = append(b, '"') + for { + i := bytes.IndexAny(v, `"\`) + if i < 0 { + b = append(b, v...) + break + } + if i > 0 { + b = append(b, v[:i]...) + } + b = append(b, '\\', v[i]) + v = v[i+1:] + } + return append(b, '"') +} + +func appendValue(b []byte, v driver.Value) ([]byte, error) { + return append(b, encode(nil, v, 0)...), nil +} + +// parseArray extracts the dimensions and elements of an array represented in +// text format. Only representations emitted by the backend are supported. +// Notably, whitespace around brackets and delimiters is significant, and NULL +// is case-sensitive. +// +// See http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO +func parseArray(src, del []byte) (dims []int, elems [][]byte, err error) { + var depth, i int + + if len(src) < 1 || src[0] != '{' { + return nil, nil, fmt.Errorf("pq: unable to parse array; expected %q at offset %d", '{', 0) + } + +Open: + for i < len(src) { + switch src[i] { + case '{': + depth++ + i++ + case '}': + elems = make([][]byte, 0) + goto Close + default: + break Open + } + } + dims = make([]int, i) + +Element: + for i < len(src) { + switch src[i] { + case '{': + if depth == len(dims) { + break Element + } + depth++ + dims[depth-1] = 0 + i++ + case '"': + var elem = []byte{} + var escape bool + for i++; i < len(src); i++ { + if escape { + elem = append(elem, src[i]) + escape = false + } else { + switch src[i] { + default: + elem = append(elem, src[i]) + case '\\': + escape = true + case '"': + elems = append(elems, elem) + i++ + break Element + } + } + } + default: + for start := i; i < len(src); i++ { + if bytes.HasPrefix(src[i:], del) || src[i] == '}' { + elem := src[start:i] + if len(elem) == 0 { + return nil, nil, fmt.Errorf("pq: unable to parse array; unexpected %q at offset %d", src[i], i) + } + if bytes.Equal(elem, []byte("NULL")) { + elem = nil + } + elems = append(elems, elem) + break Element + } + } + } + } + + for i < len(src) { + if bytes.HasPrefix(src[i:], del) && depth > 0 { + dims[depth-1]++ + i += len(del) + goto Element + } else if src[i] == '}' && depth > 0 { + dims[depth-1]++ + depth-- + i++ + } else { + return nil, nil, fmt.Errorf("pq: unable to parse array; unexpected %q at offset %d", src[i], i) + } + } + +Close: + for i < len(src) { + if src[i] == '}' && depth > 0 { + depth-- + i++ + } else { + return nil, nil, fmt.Errorf("pq: unable to parse array; unexpected %q at offset %d", src[i], i) + } + } + if depth > 0 { + err = fmt.Errorf("pq: unable to parse array; expected %q at offset %d", '}', i) + } + if err == nil { + for _, d := range dims { + if (len(elems) % d) != 0 { + err = fmt.Errorf("pq: multidimensional arrays must have elements with matching dimensions") + } + } + } + return +} + +func scanLinearArray(src, del []byte, typ string) (elems [][]byte, err error) { + dims, elems, err := parseArray(src, del) + if err != nil { + return nil, err + } + if len(dims) > 1 { + return nil, fmt.Errorf("pq: cannot convert ARRAY%s to %s", strings.Replace(fmt.Sprint(dims), " ", "][", -1), typ) + } + return elems, err +} diff --git a/vendor/github.com/lib/pq/buf.go b/vendor/github.com/lib/pq/buf.go new file mode 100644 index 0000000..4b0a0a8 --- /dev/null +++ b/vendor/github.com/lib/pq/buf.go @@ -0,0 +1,91 @@ +package pq + +import ( + "bytes" + "encoding/binary" + + "github.com/lib/pq/oid" +) + +type readBuf []byte + +func (b *readBuf) int32() (n int) { + n = int(int32(binary.BigEndian.Uint32(*b))) + *b = (*b)[4:] + return +} + +func (b *readBuf) oid() (n oid.Oid) { + n = oid.Oid(binary.BigEndian.Uint32(*b)) + *b = (*b)[4:] + return +} + +// N.B: this is actually an unsigned 16-bit integer, unlike int32 +func (b *readBuf) int16() (n int) { + n = int(binary.BigEndian.Uint16(*b)) + *b = (*b)[2:] + return +} + +func (b *readBuf) string() string { + i := bytes.IndexByte(*b, 0) + if i < 0 { + errorf("invalid message format; expected string terminator") + } + s := (*b)[:i] + *b = (*b)[i+1:] + return string(s) +} + +func (b *readBuf) next(n int) (v []byte) { + v = (*b)[:n] + *b = (*b)[n:] + return +} + +func (b *readBuf) byte() byte { + return b.next(1)[0] +} + +type writeBuf struct { + buf []byte + pos int +} + +func (b *writeBuf) int32(n int) { + x := make([]byte, 4) + binary.BigEndian.PutUint32(x, uint32(n)) + b.buf = append(b.buf, x...) +} + +func (b *writeBuf) int16(n int) { + x := make([]byte, 2) + binary.BigEndian.PutUint16(x, uint16(n)) + b.buf = append(b.buf, x...) +} + +func (b *writeBuf) string(s string) { + b.buf = append(append(b.buf, s...), '\000') +} + +func (b *writeBuf) byte(c byte) { + b.buf = append(b.buf, c) +} + +func (b *writeBuf) bytes(v []byte) { + b.buf = append(b.buf, v...) +} + +func (b *writeBuf) wrap() []byte { + p := b.buf[b.pos:] + binary.BigEndian.PutUint32(p, uint32(len(p))) + return b.buf +} + +func (b *writeBuf) next(c byte) { + p := b.buf[b.pos:] + binary.BigEndian.PutUint32(p, uint32(len(p))) + b.pos = len(b.buf) + 1 + b.buf = append(b.buf, c, 0, 0, 0, 0) +} diff --git a/vendor/github.com/lib/pq/conn.go b/vendor/github.com/lib/pq/conn.go new file mode 100644 index 0000000..da4ff9d --- /dev/null +++ b/vendor/github.com/lib/pq/conn.go @@ -0,0 +1,2112 @@ +package pq + +import ( + "bufio" + "bytes" + "context" + "crypto/md5" + "crypto/sha256" + "database/sql" + "database/sql/driver" + "encoding/binary" + "errors" + "fmt" + "io" + "net" + "os" + "os/user" + "path" + "path/filepath" + "strconv" + "strings" + "sync" + "time" + "unicode" + + "github.com/lib/pq/oid" + "github.com/lib/pq/scram" +) + +// Common error types +var ( + ErrNotSupported = errors.New("pq: Unsupported command") + ErrInFailedTransaction = errors.New("pq: Could not complete operation in a failed transaction") + ErrSSLNotSupported = errors.New("pq: SSL is not enabled on the server") + ErrSSLKeyUnknownOwnership = errors.New("pq: Could not get owner information for private key, may not be properly protected") + ErrSSLKeyHasWorldPermissions = errors.New("pq: Private key has world access. Permissions should be u=rw,g=r (0640) if owned by root, or u=rw (0600), or less") + + ErrCouldNotDetectUsername = errors.New("pq: Could not detect default username. Please provide one explicitly") + + errUnexpectedReady = errors.New("unexpected ReadyForQuery") + errNoRowsAffected = errors.New("no RowsAffected available after the empty statement") + errNoLastInsertID = errors.New("no LastInsertId available after the empty statement") +) + +// Compile time validation that our types implement the expected interfaces +var ( + _ driver.Driver = Driver{} +) + +// Driver is the Postgres database driver. +type Driver struct{} + +// Open opens a new connection to the database. name is a connection string. +// Most users should only use it through database/sql package from the standard +// library. +func (d Driver) Open(name string) (driver.Conn, error) { + return Open(name) +} + +func init() { + sql.Register("postgres", &Driver{}) +} + +type parameterStatus struct { + // server version in the same format as server_version_num, or 0 if + // unavailable + serverVersion int + + // the current location based on the TimeZone value of the session, if + // available + currentLocation *time.Location +} + +type transactionStatus byte + +const ( + txnStatusIdle transactionStatus = 'I' + txnStatusIdleInTransaction transactionStatus = 'T' + txnStatusInFailedTransaction transactionStatus = 'E' +) + +func (s transactionStatus) String() string { + switch s { + case txnStatusIdle: + return "idle" + case txnStatusIdleInTransaction: + return "idle in transaction" + case txnStatusInFailedTransaction: + return "in a failed transaction" + default: + errorf("unknown transactionStatus %d", s) + } + + panic("not reached") +} + +// Dialer is the dialer interface. It can be used to obtain more control over +// how pq creates network connections. +type Dialer interface { + Dial(network, address string) (net.Conn, error) + DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) +} + +// DialerContext is the context-aware dialer interface. +type DialerContext interface { + DialContext(ctx context.Context, network, address string) (net.Conn, error) +} + +type defaultDialer struct { + d net.Dialer +} + +func (d defaultDialer) Dial(network, address string) (net.Conn, error) { + return d.d.Dial(network, address) +} +func (d defaultDialer) DialTimeout( + network, address string, timeout time.Duration, +) (net.Conn, error) { + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + return d.DialContext(ctx, network, address) +} +func (d defaultDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) { + return d.d.DialContext(ctx, network, address) +} + +type conn struct { + c net.Conn + buf *bufio.Reader + namei int + scratch [512]byte + txnStatus transactionStatus + txnFinish func() + + // Save connection arguments to use during CancelRequest. + dialer Dialer + opts values + + // Cancellation key data for use with CancelRequest messages. + processID int + secretKey int + + parameterStatus parameterStatus + + saveMessageType byte + saveMessageBuffer []byte + + // If an error is set, this connection is bad and all public-facing + // functions should return the appropriate error by calling get() + // (ErrBadConn) or getForNext(). + err syncErr + + // If set, this connection should never use the binary format when + // receiving query results from prepared statements. Only provided for + // debugging. + disablePreparedBinaryResult bool + + // Whether to always send []byte parameters over as binary. Enables single + // round-trip mode for non-prepared Query calls. + binaryParameters bool + + // If true this connection is in the middle of a COPY + inCopy bool + + // If not nil, notices will be synchronously sent here + noticeHandler func(*Error) + + // If not nil, notifications will be synchronously sent here + notificationHandler func(*Notification) + + // GSSAPI context + gss GSS +} + +type syncErr struct { + err error + sync.Mutex +} + +// Return ErrBadConn if connection is bad. +func (e *syncErr) get() error { + e.Lock() + defer e.Unlock() + if e.err != nil { + return driver.ErrBadConn + } + return nil +} + +// Return the error set on the connection. Currently only used by rows.Next. +func (e *syncErr) getForNext() error { + e.Lock() + defer e.Unlock() + return e.err +} + +// Set error, only if it isn't set yet. +func (e *syncErr) set(err error) { + if err == nil { + panic("attempt to set nil err") + } + e.Lock() + defer e.Unlock() + if e.err == nil { + e.err = err + } +} + +// Handle driver-side settings in parsed connection string. +func (cn *conn) handleDriverSettings(o values) (err error) { + boolSetting := func(key string, val *bool) error { + if value, ok := o[key]; ok { + if value == "yes" { + *val = true + } else if value == "no" { + *val = false + } else { + return fmt.Errorf("unrecognized value %q for %s", value, key) + } + } + return nil + } + + err = boolSetting("disable_prepared_binary_result", &cn.disablePreparedBinaryResult) + if err != nil { + return err + } + return boolSetting("binary_parameters", &cn.binaryParameters) +} + +func (cn *conn) handlePgpass(o values) { + // if a password was supplied, do not process .pgpass + if _, ok := o["password"]; ok { + return + } + filename := os.Getenv("PGPASSFILE") + if filename == "" { + // XXX this code doesn't work on Windows where the default filename is + // XXX %APPDATA%\postgresql\pgpass.conf + // Prefer $HOME over user.Current due to glibc bug: golang.org/issue/13470 + userHome := os.Getenv("HOME") + if userHome == "" { + user, err := user.Current() + if err != nil { + return + } + userHome = user.HomeDir + } + filename = filepath.Join(userHome, ".pgpass") + } + fileinfo, err := os.Stat(filename) + if err != nil { + return + } + mode := fileinfo.Mode() + if mode&(0x77) != 0 { + // XXX should warn about incorrect .pgpass permissions as psql does + return + } + file, err := os.Open(filename) + if err != nil { + return + } + defer file.Close() + scanner := bufio.NewScanner(io.Reader(file)) + // From: https://github.com/tg/pgpass/blob/master/reader.go + for scanner.Scan() { + if scanText(scanner.Text(), o) { + break + } + } +} + +// GetFields is a helper function for scanText. +func getFields(s string) []string { + fs := make([]string, 0, 5) + f := make([]rune, 0, len(s)) + + var esc bool + for _, c := range s { + switch { + case esc: + f = append(f, c) + esc = false + case c == '\\': + esc = true + case c == ':': + fs = append(fs, string(f)) + f = f[:0] + default: + f = append(f, c) + } + } + return append(fs, string(f)) +} + +// ScanText assists HandlePgpass in it's objective. +func scanText(line string, o values) bool { + hostname := o["host"] + ntw, _ := network(o) + port := o["port"] + db := o["dbname"] + username := o["user"] + if len(line) == 0 || line[0] == '#' { + return false + } + split := getFields(line) + if len(split) != 5 { + return false + } + if (split[0] == "*" || split[0] == hostname || (split[0] == "localhost" && (hostname == "" || ntw == "unix"))) && (split[1] == "*" || split[1] == port) && (split[2] == "*" || split[2] == db) && (split[3] == "*" || split[3] == username) { + o["password"] = split[4] + return true + } + return false +} + +func (cn *conn) writeBuf(b byte) *writeBuf { + cn.scratch[0] = b + return &writeBuf{ + buf: cn.scratch[:5], + pos: 1, + } +} + +// Open opens a new connection to the database. dsn is a connection string. +// Most users should only use it through database/sql package from the standard +// library. +func Open(dsn string) (_ driver.Conn, err error) { + return DialOpen(defaultDialer{}, dsn) +} + +// DialOpen opens a new connection to the database using a dialer. +func DialOpen(d Dialer, dsn string) (_ driver.Conn, err error) { + c, err := NewConnector(dsn) + if err != nil { + return nil, err + } + c.Dialer(d) + return c.open(context.Background()) +} + +func (c *Connector) open(ctx context.Context) (cn *conn, err error) { + // Handle any panics during connection initialization. Note that we + // specifically do *not* want to use errRecover(), as that would turn any + // connection errors into ErrBadConns, hiding the real error message from + // the user. + defer errRecoverNoErrBadConn(&err) + + // Create a new values map (copy). This makes it so maps in different + // connections do not reference the same underlying data structure, so it + // is safe for multiple connections to concurrently write to their opts. + o := make(values) + for k, v := range c.opts { + o[k] = v + } + + cn = &conn{ + opts: o, + dialer: c.dialer, + } + err = cn.handleDriverSettings(o) + if err != nil { + return nil, err + } + cn.handlePgpass(o) + + cn.c, err = dial(ctx, c.dialer, o) + if err != nil { + return nil, err + } + + err = cn.ssl(o) + if err != nil { + if cn.c != nil { + cn.c.Close() + } + return nil, err + } + + // cn.startup panics on error. Make sure we don't leak cn.c. + panicking := true + defer func() { + if panicking { + cn.c.Close() + } + }() + + cn.buf = bufio.NewReader(cn.c) + cn.startup(o) + + // reset the deadline, in case one was set (see dial) + if timeout, ok := o["connect_timeout"]; ok && timeout != "0" { + err = cn.c.SetDeadline(time.Time{}) + } + panicking = false + return cn, err +} + +func dial(ctx context.Context, d Dialer, o values) (net.Conn, error) { + network, address := network(o) + + // Zero or not specified means wait indefinitely. + if timeout, ok := o["connect_timeout"]; ok && timeout != "0" { + seconds, err := strconv.ParseInt(timeout, 10, 0) + if err != nil { + return nil, fmt.Errorf("invalid value for parameter connect_timeout: %s", err) + } + duration := time.Duration(seconds) * time.Second + + // connect_timeout should apply to the entire connection establishment + // procedure, so we both use a timeout for the TCP connection + // establishment and set a deadline for doing the initial handshake. + // The deadline is then reset after startup() is done. + deadline := time.Now().Add(duration) + var conn net.Conn + if dctx, ok := d.(DialerContext); ok { + ctx, cancel := context.WithTimeout(ctx, duration) + defer cancel() + conn, err = dctx.DialContext(ctx, network, address) + } else { + conn, err = d.DialTimeout(network, address, duration) + } + if err != nil { + return nil, err + } + err = conn.SetDeadline(deadline) + return conn, err + } + if dctx, ok := d.(DialerContext); ok { + return dctx.DialContext(ctx, network, address) + } + return d.Dial(network, address) +} + +func network(o values) (string, string) { + host := o["host"] + + if strings.HasPrefix(host, "/") { + sockPath := path.Join(host, ".s.PGSQL."+o["port"]) + return "unix", sockPath + } + + return "tcp", net.JoinHostPort(host, o["port"]) +} + +type values map[string]string + +// scanner implements a tokenizer for libpq-style option strings. +type scanner struct { + s []rune + i int +} + +// newScanner returns a new scanner initialized with the option string s. +func newScanner(s string) *scanner { + return &scanner{[]rune(s), 0} +} + +// Next returns the next rune. +// It returns 0, false if the end of the text has been reached. +func (s *scanner) Next() (rune, bool) { + if s.i >= len(s.s) { + return 0, false + } + r := s.s[s.i] + s.i++ + return r, true +} + +// SkipSpaces returns the next non-whitespace rune. +// It returns 0, false if the end of the text has been reached. +func (s *scanner) SkipSpaces() (rune, bool) { + r, ok := s.Next() + for unicode.IsSpace(r) && ok { + r, ok = s.Next() + } + return r, ok +} + +// parseOpts parses the options from name and adds them to the values. +// +// The parsing code is based on conninfo_parse from libpq's fe-connect.c +func parseOpts(name string, o values) error { + s := newScanner(name) + + for { + var ( + keyRunes, valRunes []rune + r rune + ok bool + ) + + if r, ok = s.SkipSpaces(); !ok { + break + } + + // Scan the key + for !unicode.IsSpace(r) && r != '=' { + keyRunes = append(keyRunes, r) + if r, ok = s.Next(); !ok { + break + } + } + + // Skip any whitespace if we're not at the = yet + if r != '=' { + r, ok = s.SkipSpaces() + } + + // The current character should be = + if r != '=' || !ok { + return fmt.Errorf(`missing "=" after %q in connection info string"`, string(keyRunes)) + } + + // Skip any whitespace after the = + if r, ok = s.SkipSpaces(); !ok { + // If we reach the end here, the last value is just an empty string as per libpq. + o[string(keyRunes)] = "" + break + } + + if r != '\'' { + for !unicode.IsSpace(r) { + if r == '\\' { + if r, ok = s.Next(); !ok { + return fmt.Errorf(`missing character after backslash`) + } + } + valRunes = append(valRunes, r) + + if r, ok = s.Next(); !ok { + break + } + } + } else { + quote: + for { + if r, ok = s.Next(); !ok { + return fmt.Errorf(`unterminated quoted string literal in connection string`) + } + switch r { + case '\'': + break quote + case '\\': + r, _ = s.Next() + fallthrough + default: + valRunes = append(valRunes, r) + } + } + } + + o[string(keyRunes)] = string(valRunes) + } + + return nil +} + +func (cn *conn) isInTransaction() bool { + return cn.txnStatus == txnStatusIdleInTransaction || + cn.txnStatus == txnStatusInFailedTransaction +} + +func (cn *conn) checkIsInTransaction(intxn bool) { + if cn.isInTransaction() != intxn { + cn.err.set(driver.ErrBadConn) + errorf("unexpected transaction status %v", cn.txnStatus) + } +} + +func (cn *conn) Begin() (_ driver.Tx, err error) { + return cn.begin("") +} + +func (cn *conn) begin(mode string) (_ driver.Tx, err error) { + if err := cn.err.get(); err != nil { + return nil, err + } + defer cn.errRecover(&err) + + cn.checkIsInTransaction(false) + _, commandTag, err := cn.simpleExec("BEGIN" + mode) + if err != nil { + return nil, err + } + if commandTag != "BEGIN" { + cn.err.set(driver.ErrBadConn) + return nil, fmt.Errorf("unexpected command tag %s", commandTag) + } + if cn.txnStatus != txnStatusIdleInTransaction { + cn.err.set(driver.ErrBadConn) + return nil, fmt.Errorf("unexpected transaction status %v", cn.txnStatus) + } + return cn, nil +} + +func (cn *conn) closeTxn() { + if finish := cn.txnFinish; finish != nil { + finish() + } +} + +func (cn *conn) Commit() (err error) { + defer cn.closeTxn() + if err := cn.err.get(); err != nil { + return err + } + defer cn.errRecover(&err) + + cn.checkIsInTransaction(true) + // We don't want the client to think that everything is okay if it tries + // to commit a failed transaction. However, no matter what we return, + // database/sql will release this connection back into the free connection + // pool so we have to abort the current transaction here. Note that you + // would get the same behaviour if you issued a COMMIT in a failed + // transaction, so it's also the least surprising thing to do here. + if cn.txnStatus == txnStatusInFailedTransaction { + if err := cn.rollback(); err != nil { + return err + } + return ErrInFailedTransaction + } + + _, commandTag, err := cn.simpleExec("COMMIT") + if err != nil { + if cn.isInTransaction() { + cn.err.set(driver.ErrBadConn) + } + return err + } + if commandTag != "COMMIT" { + cn.err.set(driver.ErrBadConn) + return fmt.Errorf("unexpected command tag %s", commandTag) + } + cn.checkIsInTransaction(false) + return nil +} + +func (cn *conn) Rollback() (err error) { + defer cn.closeTxn() + if err := cn.err.get(); err != nil { + return err + } + defer cn.errRecover(&err) + return cn.rollback() +} + +func (cn *conn) rollback() (err error) { + cn.checkIsInTransaction(true) + _, commandTag, err := cn.simpleExec("ROLLBACK") + if err != nil { + if cn.isInTransaction() { + cn.err.set(driver.ErrBadConn) + } + return err + } + if commandTag != "ROLLBACK" { + return fmt.Errorf("unexpected command tag %s", commandTag) + } + cn.checkIsInTransaction(false) + return nil +} + +func (cn *conn) gname() string { + cn.namei++ + return strconv.FormatInt(int64(cn.namei), 10) +} + +func (cn *conn) simpleExec(q string) (res driver.Result, commandTag string, err error) { + b := cn.writeBuf('Q') + b.string(q) + cn.send(b) + + for { + t, r := cn.recv1() + switch t { + case 'C': + res, commandTag = cn.parseComplete(r.string()) + case 'Z': + cn.processReadyForQuery(r) + if res == nil && err == nil { + err = errUnexpectedReady + } + // done + return + case 'E': + err = parseError(r) + case 'I': + res = emptyRows + case 'T', 'D': + // ignore any results + default: + cn.err.set(driver.ErrBadConn) + errorf("unknown response for simple query: %q", t) + } + } +} + +func (cn *conn) simpleQuery(q string) (res *rows, err error) { + defer cn.errRecover(&err) + + b := cn.writeBuf('Q') + b.string(q) + cn.send(b) + + for { + t, r := cn.recv1() + switch t { + case 'C', 'I': + // We allow queries which don't return any results through Query as + // well as Exec. We still have to give database/sql a rows object + // the user can close, though, to avoid connections from being + // leaked. A "rows" with done=true works fine for that purpose. + if err != nil { + cn.err.set(driver.ErrBadConn) + errorf("unexpected message %q in simple query execution", t) + } + if res == nil { + res = &rows{ + cn: cn, + } + } + // Set the result and tag to the last command complete if there wasn't a + // query already run. Although queries usually return from here and cede + // control to Next, a query with zero results does not. + if t == 'C' { + res.result, res.tag = cn.parseComplete(r.string()) + if res.colNames != nil { + return + } + } + res.done = true + case 'Z': + cn.processReadyForQuery(r) + // done + return + case 'E': + res = nil + err = parseError(r) + case 'D': + if res == nil { + cn.err.set(driver.ErrBadConn) + errorf("unexpected DataRow in simple query execution") + } + // the query didn't fail; kick off to Next + cn.saveMessage(t, r) + return + case 'T': + // res might be non-nil here if we received a previous + // CommandComplete, but that's fine; just overwrite it + res = &rows{cn: cn} + res.rowsHeader = parsePortalRowDescribe(r) + + // To work around a bug in QueryRow in Go 1.2 and earlier, wait + // until the first DataRow has been received. + default: + cn.err.set(driver.ErrBadConn) + errorf("unknown response for simple query: %q", t) + } + } +} + +type noRows struct{} + +var emptyRows noRows + +var _ driver.Result = noRows{} + +func (noRows) LastInsertId() (int64, error) { + return 0, errNoLastInsertID +} + +func (noRows) RowsAffected() (int64, error) { + return 0, errNoRowsAffected +} + +// Decides which column formats to use for a prepared statement. The input is +// an array of type oids, one element per result column. +func decideColumnFormats( + colTyps []fieldDesc, forceText bool, +) (colFmts []format, colFmtData []byte) { + if len(colTyps) == 0 { + return nil, colFmtDataAllText + } + + colFmts = make([]format, len(colTyps)) + if forceText { + return colFmts, colFmtDataAllText + } + + allBinary := true + allText := true + for i, t := range colTyps { + switch t.OID { + // This is the list of types to use binary mode for when receiving them + // through a prepared statement. If a type appears in this list, it + // must also be implemented in binaryDecode in encode.go. + case oid.T_bytea: + fallthrough + case oid.T_int8: + fallthrough + case oid.T_int4: + fallthrough + case oid.T_int2: + fallthrough + case oid.T_uuid: + colFmts[i] = formatBinary + allText = false + + default: + allBinary = false + } + } + + if allBinary { + return colFmts, colFmtDataAllBinary + } else if allText { + return colFmts, colFmtDataAllText + } else { + colFmtData = make([]byte, 2+len(colFmts)*2) + binary.BigEndian.PutUint16(colFmtData, uint16(len(colFmts))) + for i, v := range colFmts { + binary.BigEndian.PutUint16(colFmtData[2+i*2:], uint16(v)) + } + return colFmts, colFmtData + } +} + +func (cn *conn) prepareTo(q, stmtName string) *stmt { + st := &stmt{cn: cn, name: stmtName} + + b := cn.writeBuf('P') + b.string(st.name) + b.string(q) + b.int16(0) + + b.next('D') + b.byte('S') + b.string(st.name) + + b.next('S') + cn.send(b) + + cn.readParseResponse() + st.paramTyps, st.colNames, st.colTyps = cn.readStatementDescribeResponse() + st.colFmts, st.colFmtData = decideColumnFormats(st.colTyps, cn.disablePreparedBinaryResult) + cn.readReadyForQuery() + return st +} + +func (cn *conn) Prepare(q string) (_ driver.Stmt, err error) { + if err := cn.err.get(); err != nil { + return nil, err + } + defer cn.errRecover(&err) + + if len(q) >= 4 && strings.EqualFold(q[:4], "COPY") { + s, err := cn.prepareCopyIn(q) + if err == nil { + cn.inCopy = true + } + return s, err + } + return cn.prepareTo(q, cn.gname()), nil +} + +func (cn *conn) Close() (err error) { + // Skip cn.bad return here because we always want to close a connection. + defer cn.errRecover(&err) + + // Ensure that cn.c.Close is always run. Since error handling is done with + // panics and cn.errRecover, the Close must be in a defer. + defer func() { + cerr := cn.c.Close() + if err == nil { + err = cerr + } + }() + + // Don't go through send(); ListenerConn relies on us not scribbling on the + // scratch buffer of this connection. + return cn.sendSimpleMessage('X') +} + +// Implement the "Queryer" interface +func (cn *conn) Query(query string, args []driver.Value) (driver.Rows, error) { + return cn.query(query, args) +} + +func (cn *conn) query(query string, args []driver.Value) (_ *rows, err error) { + if err := cn.err.get(); err != nil { + return nil, err + } + if cn.inCopy { + return nil, errCopyInProgress + } + defer cn.errRecover(&err) + + // Check to see if we can use the "simpleQuery" interface, which is + // *much* faster than going through prepare/exec + if len(args) == 0 { + return cn.simpleQuery(query) + } + + if cn.binaryParameters { + cn.sendBinaryModeQuery(query, args) + + cn.readParseResponse() + cn.readBindResponse() + rows := &rows{cn: cn} + rows.rowsHeader = cn.readPortalDescribeResponse() + cn.postExecuteWorkaround() + return rows, nil + } + st := cn.prepareTo(query, "") + st.exec(args) + return &rows{ + cn: cn, + rowsHeader: st.rowsHeader, + }, nil +} + +// Implement the optional "Execer" interface for one-shot queries +func (cn *conn) Exec(query string, args []driver.Value) (res driver.Result, err error) { + if err := cn.err.get(); err != nil { + return nil, err + } + defer cn.errRecover(&err) + + // Check to see if we can use the "simpleExec" interface, which is + // *much* faster than going through prepare/exec + if len(args) == 0 { + // ignore commandTag, our caller doesn't care + r, _, err := cn.simpleExec(query) + return r, err + } + + if cn.binaryParameters { + cn.sendBinaryModeQuery(query, args) + + cn.readParseResponse() + cn.readBindResponse() + cn.readPortalDescribeResponse() + cn.postExecuteWorkaround() + res, _, err = cn.readExecuteResponse("Execute") + return res, err + } + // Use the unnamed statement to defer planning until bind + // time, or else value-based selectivity estimates cannot be + // used. + st := cn.prepareTo(query, "") + r, err := st.Exec(args) + if err != nil { + panic(err) + } + return r, err +} + +type safeRetryError struct { + Err error +} + +func (se *safeRetryError) Error() string { + return se.Err.Error() +} + +func (cn *conn) send(m *writeBuf) { + n, err := cn.c.Write(m.wrap()) + if err != nil { + if n == 0 { + err = &safeRetryError{Err: err} + } + panic(err) + } +} + +func (cn *conn) sendStartupPacket(m *writeBuf) error { + _, err := cn.c.Write((m.wrap())[1:]) + return err +} + +// Send a message of type typ to the server on the other end of cn. The +// message should have no payload. This method does not use the scratch +// buffer. +func (cn *conn) sendSimpleMessage(typ byte) (err error) { + _, err = cn.c.Write([]byte{typ, '\x00', '\x00', '\x00', '\x04'}) + return err +} + +// saveMessage memorizes a message and its buffer in the conn struct. +// recvMessage will then return these values on the next call to it. This +// method is useful in cases where you have to see what the next message is +// going to be (e.g. to see whether it's an error or not) but you can't handle +// the message yourself. +func (cn *conn) saveMessage(typ byte, buf *readBuf) { + if cn.saveMessageType != 0 { + cn.err.set(driver.ErrBadConn) + errorf("unexpected saveMessageType %d", cn.saveMessageType) + } + cn.saveMessageType = typ + cn.saveMessageBuffer = *buf +} + +// recvMessage receives any message from the backend, or returns an error if +// a problem occurred while reading the message. +func (cn *conn) recvMessage(r *readBuf) (byte, error) { + // workaround for a QueryRow bug, see exec + if cn.saveMessageType != 0 { + t := cn.saveMessageType + *r = cn.saveMessageBuffer + cn.saveMessageType = 0 + cn.saveMessageBuffer = nil + return t, nil + } + + x := cn.scratch[:5] + _, err := io.ReadFull(cn.buf, x) + if err != nil { + return 0, err + } + + // read the type and length of the message that follows + t := x[0] + n := int(binary.BigEndian.Uint32(x[1:])) - 4 + var y []byte + if n <= len(cn.scratch) { + y = cn.scratch[:n] + } else { + y = make([]byte, n) + } + _, err = io.ReadFull(cn.buf, y) + if err != nil { + return 0, err + } + *r = y + return t, nil +} + +// recv receives a message from the backend, but if an error happened while +// reading the message or the received message was an ErrorResponse, it panics. +// NoticeResponses are ignored. This function should generally be used only +// during the startup sequence. +func (cn *conn) recv() (t byte, r *readBuf) { + for { + var err error + r = &readBuf{} + t, err = cn.recvMessage(r) + if err != nil { + panic(err) + } + switch t { + case 'E': + panic(parseError(r)) + case 'N': + if n := cn.noticeHandler; n != nil { + n(parseError(r)) + } + case 'A': + if n := cn.notificationHandler; n != nil { + n(recvNotification(r)) + } + default: + return + } + } +} + +// recv1Buf is exactly equivalent to recv1, except it uses a buffer supplied by +// the caller to avoid an allocation. +func (cn *conn) recv1Buf(r *readBuf) byte { + for { + t, err := cn.recvMessage(r) + if err != nil { + panic(err) + } + + switch t { + case 'A': + if n := cn.notificationHandler; n != nil { + n(recvNotification(r)) + } + case 'N': + if n := cn.noticeHandler; n != nil { + n(parseError(r)) + } + case 'S': + cn.processParameterStatus(r) + default: + return t + } + } +} + +// recv1 receives a message from the backend, panicking if an error occurs +// while attempting to read it. All asynchronous messages are ignored, with +// the exception of ErrorResponse. +func (cn *conn) recv1() (t byte, r *readBuf) { + r = &readBuf{} + t = cn.recv1Buf(r) + return t, r +} + +func (cn *conn) ssl(o values) error { + upgrade, err := ssl(o) + if err != nil { + return err + } + + if upgrade == nil { + // Nothing to do + return nil + } + + w := cn.writeBuf(0) + w.int32(80877103) + if err = cn.sendStartupPacket(w); err != nil { + return err + } + + b := cn.scratch[:1] + _, err = io.ReadFull(cn.c, b) + if err != nil { + return err + } + + if b[0] != 'S' { + return ErrSSLNotSupported + } + + cn.c, err = upgrade(cn.c) + return err +} + +// isDriverSetting returns true iff a setting is purely for configuring the +// driver's options and should not be sent to the server in the connection +// startup packet. +func isDriverSetting(key string) bool { + switch key { + case "host", "port": + return true + case "password": + return true + case "sslmode", "sslcert", "sslkey", "sslrootcert", "sslinline", "sslsni": + return true + case "fallback_application_name": + return true + case "connect_timeout": + return true + case "disable_prepared_binary_result": + return true + case "binary_parameters": + return true + case "krbsrvname": + return true + case "krbspn": + return true + default: + return false + } +} + +func (cn *conn) startup(o values) { + w := cn.writeBuf(0) + w.int32(196608) + // Send the backend the name of the database we want to connect to, and the + // user we want to connect as. Additionally, we send over any run-time + // parameters potentially included in the connection string. If the server + // doesn't recognize any of them, it will reply with an error. + for k, v := range o { + if isDriverSetting(k) { + // skip options which can't be run-time parameters + continue + } + // The protocol requires us to supply the database name as "database" + // instead of "dbname". + if k == "dbname" { + k = "database" + } + w.string(k) + w.string(v) + } + w.string("") + if err := cn.sendStartupPacket(w); err != nil { + panic(err) + } + + for { + t, r := cn.recv() + switch t { + case 'K': + cn.processBackendKeyData(r) + case 'S': + cn.processParameterStatus(r) + case 'R': + cn.auth(r, o) + case 'Z': + cn.processReadyForQuery(r) + return + default: + errorf("unknown response for startup: %q", t) + } + } +} + +func (cn *conn) auth(r *readBuf, o values) { + switch code := r.int32(); code { + case 0: + // OK + case 3: + w := cn.writeBuf('p') + w.string(o["password"]) + cn.send(w) + + t, r := cn.recv() + if t != 'R' { + errorf("unexpected password response: %q", t) + } + + if r.int32() != 0 { + errorf("unexpected authentication response: %q", t) + } + case 5: + s := string(r.next(4)) + w := cn.writeBuf('p') + w.string("md5" + md5s(md5s(o["password"]+o["user"])+s)) + cn.send(w) + + t, r := cn.recv() + if t != 'R' { + errorf("unexpected password response: %q", t) + } + + if r.int32() != 0 { + errorf("unexpected authentication response: %q", t) + } + case 7: // GSSAPI, startup + if newGss == nil { + errorf("kerberos error: no GSSAPI provider registered (import github.com/lib/pq/auth/kerberos if you need Kerberos support)") + } + cli, err := newGss() + if err != nil { + errorf("kerberos error: %s", err.Error()) + } + + var token []byte + + if spn, ok := o["krbspn"]; ok { + // Use the supplied SPN if provided.. + token, err = cli.GetInitTokenFromSpn(spn) + } else { + // Allow the kerberos service name to be overridden + service := "postgres" + if val, ok := o["krbsrvname"]; ok { + service = val + } + + token, err = cli.GetInitToken(o["host"], service) + } + + if err != nil { + errorf("failed to get Kerberos ticket: %q", err) + } + + w := cn.writeBuf('p') + w.bytes(token) + cn.send(w) + + // Store for GSSAPI continue message + cn.gss = cli + + case 8: // GSSAPI continue + + if cn.gss == nil { + errorf("GSSAPI protocol error") + } + + b := []byte(*r) + + done, tokOut, err := cn.gss.Continue(b) + if err == nil && !done { + w := cn.writeBuf('p') + w.bytes(tokOut) + cn.send(w) + } + + // Errors fall through and read the more detailed message + // from the server.. + + case 10: + sc := scram.NewClient(sha256.New, o["user"], o["password"]) + sc.Step(nil) + if sc.Err() != nil { + errorf("SCRAM-SHA-256 error: %s", sc.Err().Error()) + } + scOut := sc.Out() + + w := cn.writeBuf('p') + w.string("SCRAM-SHA-256") + w.int32(len(scOut)) + w.bytes(scOut) + cn.send(w) + + t, r := cn.recv() + if t != 'R' { + errorf("unexpected password response: %q", t) + } + + if r.int32() != 11 { + errorf("unexpected authentication response: %q", t) + } + + nextStep := r.next(len(*r)) + sc.Step(nextStep) + if sc.Err() != nil { + errorf("SCRAM-SHA-256 error: %s", sc.Err().Error()) + } + + scOut = sc.Out() + w = cn.writeBuf('p') + w.bytes(scOut) + cn.send(w) + + t, r = cn.recv() + if t != 'R' { + errorf("unexpected password response: %q", t) + } + + if r.int32() != 12 { + errorf("unexpected authentication response: %q", t) + } + + nextStep = r.next(len(*r)) + sc.Step(nextStep) + if sc.Err() != nil { + errorf("SCRAM-SHA-256 error: %s", sc.Err().Error()) + } + + default: + errorf("unknown authentication response: %d", code) + } +} + +type format int + +const formatText format = 0 +const formatBinary format = 1 + +// One result-column format code with the value 1 (i.e. all binary). +var colFmtDataAllBinary = []byte{0, 1, 0, 1} + +// No result-column format codes (i.e. all text). +var colFmtDataAllText = []byte{0, 0} + +type stmt struct { + cn *conn + name string + rowsHeader + colFmtData []byte + paramTyps []oid.Oid + closed bool +} + +func (st *stmt) Close() (err error) { + if st.closed { + return nil + } + if err := st.cn.err.get(); err != nil { + return err + } + defer st.cn.errRecover(&err) + + w := st.cn.writeBuf('C') + w.byte('S') + w.string(st.name) + st.cn.send(w) + + st.cn.send(st.cn.writeBuf('S')) + + t, _ := st.cn.recv1() + if t != '3' { + st.cn.err.set(driver.ErrBadConn) + errorf("unexpected close response: %q", t) + } + st.closed = true + + t, r := st.cn.recv1() + if t != 'Z' { + st.cn.err.set(driver.ErrBadConn) + errorf("expected ready for query, but got: %q", t) + } + st.cn.processReadyForQuery(r) + + return nil +} + +func (st *stmt) Query(v []driver.Value) (r driver.Rows, err error) { + return st.query(v) +} + +func (st *stmt) query(v []driver.Value) (r *rows, err error) { + if err := st.cn.err.get(); err != nil { + return nil, err + } + defer st.cn.errRecover(&err) + + st.exec(v) + return &rows{ + cn: st.cn, + rowsHeader: st.rowsHeader, + }, nil +} + +func (st *stmt) Exec(v []driver.Value) (res driver.Result, err error) { + if err := st.cn.err.get(); err != nil { + return nil, err + } + defer st.cn.errRecover(&err) + + st.exec(v) + res, _, err = st.cn.readExecuteResponse("simple query") + return res, err +} + +func (st *stmt) exec(v []driver.Value) { + if len(v) >= 65536 { + errorf("got %d parameters but PostgreSQL only supports 65535 parameters", len(v)) + } + if len(v) != len(st.paramTyps) { + errorf("got %d parameters but the statement requires %d", len(v), len(st.paramTyps)) + } + + cn := st.cn + w := cn.writeBuf('B') + w.byte(0) // unnamed portal + w.string(st.name) + + if cn.binaryParameters { + cn.sendBinaryParameters(w, v) + } else { + w.int16(0) + w.int16(len(v)) + for i, x := range v { + if x == nil { + w.int32(-1) + } else { + b := encode(&cn.parameterStatus, x, st.paramTyps[i]) + w.int32(len(b)) + w.bytes(b) + } + } + } + w.bytes(st.colFmtData) + + w.next('E') + w.byte(0) + w.int32(0) + + w.next('S') + cn.send(w) + + cn.readBindResponse() + cn.postExecuteWorkaround() + +} + +func (st *stmt) NumInput() int { + return len(st.paramTyps) +} + +// parseComplete parses the "command tag" from a CommandComplete message, and +// returns the number of rows affected (if applicable) and a string +// identifying only the command that was executed, e.g. "ALTER TABLE". If the +// command tag could not be parsed, parseComplete panics. +func (cn *conn) parseComplete(commandTag string) (driver.Result, string) { + commandsWithAffectedRows := []string{ + "SELECT ", + // INSERT is handled below + "UPDATE ", + "DELETE ", + "FETCH ", + "MOVE ", + "COPY ", + } + + var affectedRows *string + for _, tag := range commandsWithAffectedRows { + if strings.HasPrefix(commandTag, tag) { + t := commandTag[len(tag):] + affectedRows = &t + commandTag = tag[:len(tag)-1] + break + } + } + // INSERT also includes the oid of the inserted row in its command tag. + // Oids in user tables are deprecated, and the oid is only returned when + // exactly one row is inserted, so it's unlikely to be of value to any + // real-world application and we can ignore it. + if affectedRows == nil && strings.HasPrefix(commandTag, "INSERT ") { + parts := strings.Split(commandTag, " ") + if len(parts) != 3 { + cn.err.set(driver.ErrBadConn) + errorf("unexpected INSERT command tag %s", commandTag) + } + affectedRows = &parts[len(parts)-1] + commandTag = "INSERT" + } + // There should be no affected rows attached to the tag, just return it + if affectedRows == nil { + return driver.RowsAffected(0), commandTag + } + n, err := strconv.ParseInt(*affectedRows, 10, 64) + if err != nil { + cn.err.set(driver.ErrBadConn) + errorf("could not parse commandTag: %s", err) + } + return driver.RowsAffected(n), commandTag +} + +type rowsHeader struct { + colNames []string + colTyps []fieldDesc + colFmts []format +} + +type rows struct { + cn *conn + finish func() + rowsHeader + done bool + rb readBuf + result driver.Result + tag string + + next *rowsHeader +} + +func (rs *rows) Close() error { + if finish := rs.finish; finish != nil { + defer finish() + } + // no need to look at cn.bad as Next() will + for { + err := rs.Next(nil) + switch err { + case nil: + case io.EOF: + // rs.Next can return io.EOF on both 'Z' (ready for query) and 'T' (row + // description, used with HasNextResultSet). We need to fetch messages until + // we hit a 'Z', which is done by waiting for done to be set. + if rs.done { + return nil + } + default: + return err + } + } +} + +func (rs *rows) Columns() []string { + return rs.colNames +} + +func (rs *rows) Result() driver.Result { + if rs.result == nil { + return emptyRows + } + return rs.result +} + +func (rs *rows) Tag() string { + return rs.tag +} + +func (rs *rows) Next(dest []driver.Value) (err error) { + if rs.done { + return io.EOF + } + + conn := rs.cn + if err := conn.err.getForNext(); err != nil { + return err + } + defer conn.errRecover(&err) + + for { + t := conn.recv1Buf(&rs.rb) + switch t { + case 'E': + err = parseError(&rs.rb) + case 'C', 'I': + if t == 'C' { + rs.result, rs.tag = conn.parseComplete(rs.rb.string()) + } + continue + case 'Z': + conn.processReadyForQuery(&rs.rb) + rs.done = true + if err != nil { + return err + } + return io.EOF + case 'D': + n := rs.rb.int16() + if err != nil { + conn.err.set(driver.ErrBadConn) + errorf("unexpected DataRow after error %s", err) + } + if n < len(dest) { + dest = dest[:n] + } + for i := range dest { + l := rs.rb.int32() + if l == -1 { + dest[i] = nil + continue + } + dest[i] = decode(&conn.parameterStatus, rs.rb.next(l), rs.colTyps[i].OID, rs.colFmts[i]) + } + return + case 'T': + next := parsePortalRowDescribe(&rs.rb) + rs.next = &next + return io.EOF + default: + errorf("unexpected message after execute: %q", t) + } + } +} + +func (rs *rows) HasNextResultSet() bool { + hasNext := rs.next != nil && !rs.done + return hasNext +} + +func (rs *rows) NextResultSet() error { + if rs.next == nil { + return io.EOF + } + rs.rowsHeader = *rs.next + rs.next = nil + return nil +} + +// QuoteIdentifier quotes an "identifier" (e.g. a table or a column name) to be +// used as part of an SQL statement. For example: +// +// tblname := "my_table" +// data := "my_data" +// quoted := pq.QuoteIdentifier(tblname) +// err := db.Exec(fmt.Sprintf("INSERT INTO %s VALUES ($1)", quoted), data) +// +// Any double quotes in name will be escaped. The quoted identifier will be +// case sensitive when used in a query. If the input string contains a zero +// byte, the result will be truncated immediately before it. +func QuoteIdentifier(name string) string { + end := strings.IndexRune(name, 0) + if end > -1 { + name = name[:end] + } + return `"` + strings.Replace(name, `"`, `""`, -1) + `"` +} + +// BufferQuoteIdentifier satisfies the same purpose as QuoteIdentifier, but backed by a +// byte buffer. +func BufferQuoteIdentifier(name string, buffer *bytes.Buffer) { + end := strings.IndexRune(name, 0) + if end > -1 { + name = name[:end] + } + buffer.WriteRune('"') + buffer.WriteString(strings.Replace(name, `"`, `""`, -1)) + buffer.WriteRune('"') +} + +// QuoteLiteral quotes a 'literal' (e.g. a parameter, often used to pass literal +// to DDL and other statements that do not accept parameters) to be used as part +// of an SQL statement. For example: +// +// exp_date := pq.QuoteLiteral("2023-01-05 15:00:00Z") +// err := db.Exec(fmt.Sprintf("CREATE ROLE my_user VALID UNTIL %s", exp_date)) +// +// Any single quotes in name will be escaped. Any backslashes (i.e. "\") will be +// replaced by two backslashes (i.e. "\\") and the C-style escape identifier +// that PostgreSQL provides ('E') will be prepended to the string. +func QuoteLiteral(literal string) string { + // This follows the PostgreSQL internal algorithm for handling quoted literals + // from libpq, which can be found in the "PQEscapeStringInternal" function, + // which is found in the libpq/fe-exec.c source file: + // https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/interfaces/libpq/fe-exec.c + // + // substitute any single-quotes (') with two single-quotes ('') + literal = strings.Replace(literal, `'`, `''`, -1) + // determine if the string has any backslashes (\) in it. + // if it does, replace any backslashes (\) with two backslashes (\\) + // then, we need to wrap the entire string with a PostgreSQL + // C-style escape. Per how "PQEscapeStringInternal" handles this case, we + // also add a space before the "E" + if strings.Contains(literal, `\`) { + literal = strings.Replace(literal, `\`, `\\`, -1) + literal = ` E'` + literal + `'` + } else { + // otherwise, we can just wrap the literal with a pair of single quotes + literal = `'` + literal + `'` + } + return literal +} + +func md5s(s string) string { + h := md5.New() + h.Write([]byte(s)) + return fmt.Sprintf("%x", h.Sum(nil)) +} + +func (cn *conn) sendBinaryParameters(b *writeBuf, args []driver.Value) { + // Do one pass over the parameters to see if we're going to send any of + // them over in binary. If we are, create a paramFormats array at the + // same time. + var paramFormats []int + for i, x := range args { + _, ok := x.([]byte) + if ok { + if paramFormats == nil { + paramFormats = make([]int, len(args)) + } + paramFormats[i] = 1 + } + } + if paramFormats == nil { + b.int16(0) + } else { + b.int16(len(paramFormats)) + for _, x := range paramFormats { + b.int16(x) + } + } + + b.int16(len(args)) + for _, x := range args { + if x == nil { + b.int32(-1) + } else { + datum := binaryEncode(&cn.parameterStatus, x) + b.int32(len(datum)) + b.bytes(datum) + } + } +} + +func (cn *conn) sendBinaryModeQuery(query string, args []driver.Value) { + if len(args) >= 65536 { + errorf("got %d parameters but PostgreSQL only supports 65535 parameters", len(args)) + } + + b := cn.writeBuf('P') + b.byte(0) // unnamed statement + b.string(query) + b.int16(0) + + b.next('B') + b.int16(0) // unnamed portal and statement + cn.sendBinaryParameters(b, args) + b.bytes(colFmtDataAllText) + + b.next('D') + b.byte('P') + b.byte(0) // unnamed portal + + b.next('E') + b.byte(0) + b.int32(0) + + b.next('S') + cn.send(b) +} + +func (cn *conn) processParameterStatus(r *readBuf) { + var err error + + param := r.string() + switch param { + case "server_version": + var major1 int + var major2 int + _, err = fmt.Sscanf(r.string(), "%d.%d", &major1, &major2) + if err == nil { + cn.parameterStatus.serverVersion = major1*10000 + major2*100 + } + + case "TimeZone": + cn.parameterStatus.currentLocation, err = time.LoadLocation(r.string()) + if err != nil { + cn.parameterStatus.currentLocation = nil + } + + default: + // ignore + } +} + +func (cn *conn) processReadyForQuery(r *readBuf) { + cn.txnStatus = transactionStatus(r.byte()) +} + +func (cn *conn) readReadyForQuery() { + t, r := cn.recv1() + switch t { + case 'Z': + cn.processReadyForQuery(r) + return + default: + cn.err.set(driver.ErrBadConn) + errorf("unexpected message %q; expected ReadyForQuery", t) + } +} + +func (cn *conn) processBackendKeyData(r *readBuf) { + cn.processID = r.int32() + cn.secretKey = r.int32() +} + +func (cn *conn) readParseResponse() { + t, r := cn.recv1() + switch t { + case '1': + return + case 'E': + err := parseError(r) + cn.readReadyForQuery() + panic(err) + default: + cn.err.set(driver.ErrBadConn) + errorf("unexpected Parse response %q", t) + } +} + +func (cn *conn) readStatementDescribeResponse() ( + paramTyps []oid.Oid, + colNames []string, + colTyps []fieldDesc, +) { + for { + t, r := cn.recv1() + switch t { + case 't': + nparams := r.int16() + paramTyps = make([]oid.Oid, nparams) + for i := range paramTyps { + paramTyps[i] = r.oid() + } + case 'n': + return paramTyps, nil, nil + case 'T': + colNames, colTyps = parseStatementRowDescribe(r) + return paramTyps, colNames, colTyps + case 'E': + err := parseError(r) + cn.readReadyForQuery() + panic(err) + default: + cn.err.set(driver.ErrBadConn) + errorf("unexpected Describe statement response %q", t) + } + } +} + +func (cn *conn) readPortalDescribeResponse() rowsHeader { + t, r := cn.recv1() + switch t { + case 'T': + return parsePortalRowDescribe(r) + case 'n': + return rowsHeader{} + case 'E': + err := parseError(r) + cn.readReadyForQuery() + panic(err) + default: + cn.err.set(driver.ErrBadConn) + errorf("unexpected Describe response %q", t) + } + panic("not reached") +} + +func (cn *conn) readBindResponse() { + t, r := cn.recv1() + switch t { + case '2': + return + case 'E': + err := parseError(r) + cn.readReadyForQuery() + panic(err) + default: + cn.err.set(driver.ErrBadConn) + errorf("unexpected Bind response %q", t) + } +} + +func (cn *conn) postExecuteWorkaround() { + // Work around a bug in sql.DB.QueryRow: in Go 1.2 and earlier it ignores + // any errors from rows.Next, which masks errors that happened during the + // execution of the query. To avoid the problem in common cases, we wait + // here for one more message from the database. If it's not an error the + // query will likely succeed (or perhaps has already, if it's a + // CommandComplete), so we push the message into the conn struct; recv1 + // will return it as the next message for rows.Next or rows.Close. + // However, if it's an error, we wait until ReadyForQuery and then return + // the error to our caller. + for { + t, r := cn.recv1() + switch t { + case 'E': + err := parseError(r) + cn.readReadyForQuery() + panic(err) + case 'C', 'D', 'I': + // the query didn't fail, but we can't process this message + cn.saveMessage(t, r) + return + default: + cn.err.set(driver.ErrBadConn) + errorf("unexpected message during extended query execution: %q", t) + } + } +} + +// Only for Exec(), since we ignore the returned data +func (cn *conn) readExecuteResponse( + protocolState string, +) (res driver.Result, commandTag string, err error) { + for { + t, r := cn.recv1() + switch t { + case 'C': + if err != nil { + cn.err.set(driver.ErrBadConn) + errorf("unexpected CommandComplete after error %s", err) + } + res, commandTag = cn.parseComplete(r.string()) + case 'Z': + cn.processReadyForQuery(r) + if res == nil && err == nil { + err = errUnexpectedReady + } + return res, commandTag, err + case 'E': + err = parseError(r) + case 'T', 'D', 'I': + if err != nil { + cn.err.set(driver.ErrBadConn) + errorf("unexpected %q after error %s", t, err) + } + if t == 'I' { + res = emptyRows + } + // ignore any results + default: + cn.err.set(driver.ErrBadConn) + errorf("unknown %s response: %q", protocolState, t) + } + } +} + +func parseStatementRowDescribe(r *readBuf) (colNames []string, colTyps []fieldDesc) { + n := r.int16() + colNames = make([]string, n) + colTyps = make([]fieldDesc, n) + for i := range colNames { + colNames[i] = r.string() + r.next(6) + colTyps[i].OID = r.oid() + colTyps[i].Len = r.int16() + colTyps[i].Mod = r.int32() + // format code not known when describing a statement; always 0 + r.next(2) + } + return +} + +func parsePortalRowDescribe(r *readBuf) rowsHeader { + n := r.int16() + colNames := make([]string, n) + colFmts := make([]format, n) + colTyps := make([]fieldDesc, n) + for i := range colNames { + colNames[i] = r.string() + r.next(6) + colTyps[i].OID = r.oid() + colTyps[i].Len = r.int16() + colTyps[i].Mod = r.int32() + colFmts[i] = format(r.int16()) + } + return rowsHeader{ + colNames: colNames, + colFmts: colFmts, + colTyps: colTyps, + } +} + +// parseEnviron tries to mimic some of libpq's environment handling +// +// To ease testing, it does not directly reference os.Environ, but is +// designed to accept its output. +// +// Environment-set connection information is intended to have a higher +// precedence than a library default but lower than any explicitly +// passed information (such as in the URL or connection string). +func parseEnviron(env []string) (out map[string]string) { + out = make(map[string]string) + + for _, v := range env { + parts := strings.SplitN(v, "=", 2) + + accrue := func(keyname string) { + out[keyname] = parts[1] + } + unsupported := func() { + panic(fmt.Sprintf("setting %v not supported", parts[0])) + } + + // The order of these is the same as is seen in the + // PostgreSQL 9.1 manual. Unsupported but well-defined + // keys cause a panic; these should be unset prior to + // execution. Options which pq expects to be set to a + // certain value are allowed, but must be set to that + // value if present (they can, of course, be absent). + switch parts[0] { + case "PGHOST": + accrue("host") + case "PGHOSTADDR": + unsupported() + case "PGPORT": + accrue("port") + case "PGDATABASE": + accrue("dbname") + case "PGUSER": + accrue("user") + case "PGPASSWORD": + accrue("password") + case "PGSERVICE", "PGSERVICEFILE", "PGREALM": + unsupported() + case "PGOPTIONS": + accrue("options") + case "PGAPPNAME": + accrue("application_name") + case "PGSSLMODE": + accrue("sslmode") + case "PGSSLCERT": + accrue("sslcert") + case "PGSSLKEY": + accrue("sslkey") + case "PGSSLROOTCERT": + accrue("sslrootcert") + case "PGSSLSNI": + accrue("sslsni") + case "PGREQUIRESSL", "PGSSLCRL": + unsupported() + case "PGREQUIREPEER": + unsupported() + case "PGKRBSRVNAME", "PGGSSLIB": + unsupported() + case "PGCONNECT_TIMEOUT": + accrue("connect_timeout") + case "PGCLIENTENCODING": + accrue("client_encoding") + case "PGDATESTYLE": + accrue("datestyle") + case "PGTZ": + accrue("timezone") + case "PGGEQO": + accrue("geqo") + case "PGSYSCONFDIR", "PGLOCALEDIR": + unsupported() + } + } + + return out +} + +// isUTF8 returns whether name is a fuzzy variation of the string "UTF-8". +func isUTF8(name string) bool { + // Recognize all sorts of silly things as "UTF-8", like Postgres does + s := strings.Map(alnumLowerASCII, name) + return s == "utf8" || s == "unicode" +} + +func alnumLowerASCII(ch rune) rune { + if 'A' <= ch && ch <= 'Z' { + return ch + ('a' - 'A') + } + if 'a' <= ch && ch <= 'z' || '0' <= ch && ch <= '9' { + return ch + } + return -1 // discard +} + +// The database/sql/driver package says: +// All Conn implementations should implement the following interfaces: Pinger, SessionResetter, and Validator. +var _ driver.Pinger = &conn{} +var _ driver.SessionResetter = &conn{} + +func (cn *conn) ResetSession(ctx context.Context) error { + // Ensure bad connections are reported: From database/sql/driver: + // If a connection is never returned to the connection pool but immediately reused, then + // ResetSession is called prior to reuse but IsValid is not called. + return cn.err.get() +} + +func (cn *conn) IsValid() bool { + return cn.err.get() == nil +} diff --git a/vendor/github.com/lib/pq/conn_go115.go b/vendor/github.com/lib/pq/conn_go115.go new file mode 100644 index 0000000..f4ef030 --- /dev/null +++ b/vendor/github.com/lib/pq/conn_go115.go @@ -0,0 +1,8 @@ +//go:build go1.15 +// +build go1.15 + +package pq + +import "database/sql/driver" + +var _ driver.Validator = &conn{} diff --git a/vendor/github.com/lib/pq/conn_go18.go b/vendor/github.com/lib/pq/conn_go18.go new file mode 100644 index 0000000..63d4ca6 --- /dev/null +++ b/vendor/github.com/lib/pq/conn_go18.go @@ -0,0 +1,247 @@ +package pq + +import ( + "context" + "database/sql" + "database/sql/driver" + "fmt" + "io" + "io/ioutil" + "time" +) + +const ( + watchCancelDialContextTimeout = time.Second * 10 +) + +// Implement the "QueryerContext" interface +func (cn *conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { + list := make([]driver.Value, len(args)) + for i, nv := range args { + list[i] = nv.Value + } + finish := cn.watchCancel(ctx) + r, err := cn.query(query, list) + if err != nil { + if finish != nil { + finish() + } + return nil, err + } + r.finish = finish + return r, nil +} + +// Implement the "ExecerContext" interface +func (cn *conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) { + list := make([]driver.Value, len(args)) + for i, nv := range args { + list[i] = nv.Value + } + + if finish := cn.watchCancel(ctx); finish != nil { + defer finish() + } + + return cn.Exec(query, list) +} + +// Implement the "ConnPrepareContext" interface +func (cn *conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { + if finish := cn.watchCancel(ctx); finish != nil { + defer finish() + } + return cn.Prepare(query) +} + +// Implement the "ConnBeginTx" interface +func (cn *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { + var mode string + + switch sql.IsolationLevel(opts.Isolation) { + case sql.LevelDefault: + // Don't touch mode: use the server's default + case sql.LevelReadUncommitted: + mode = " ISOLATION LEVEL READ UNCOMMITTED" + case sql.LevelReadCommitted: + mode = " ISOLATION LEVEL READ COMMITTED" + case sql.LevelRepeatableRead: + mode = " ISOLATION LEVEL REPEATABLE READ" + case sql.LevelSerializable: + mode = " ISOLATION LEVEL SERIALIZABLE" + default: + return nil, fmt.Errorf("pq: isolation level not supported: %d", opts.Isolation) + } + + if opts.ReadOnly { + mode += " READ ONLY" + } else { + mode += " READ WRITE" + } + + tx, err := cn.begin(mode) + if err != nil { + return nil, err + } + cn.txnFinish = cn.watchCancel(ctx) + return tx, nil +} + +func (cn *conn) Ping(ctx context.Context) error { + if finish := cn.watchCancel(ctx); finish != nil { + defer finish() + } + rows, err := cn.simpleQuery(";") + if err != nil { + return driver.ErrBadConn // https://golang.org/pkg/database/sql/driver/#Pinger + } + rows.Close() + return nil +} + +func (cn *conn) watchCancel(ctx context.Context) func() { + if done := ctx.Done(); done != nil { + finished := make(chan struct{}, 1) + go func() { + select { + case <-done: + select { + case finished <- struct{}{}: + default: + // We raced with the finish func, let the next query handle this with the + // context. + return + } + + // Set the connection state to bad so it does not get reused. + cn.err.set(ctx.Err()) + + // At this point the function level context is canceled, + // so it must not be used for the additional network + // request to cancel the query. + // Create a new context to pass into the dial. + ctxCancel, cancel := context.WithTimeout(context.Background(), watchCancelDialContextTimeout) + defer cancel() + + _ = cn.cancel(ctxCancel) + case <-finished: + } + }() + return func() { + select { + case <-finished: + cn.err.set(ctx.Err()) + cn.Close() + case finished <- struct{}{}: + } + } + } + return nil +} + +func (cn *conn) cancel(ctx context.Context) error { + // Create a new values map (copy). This makes sure the connection created + // in this method cannot write to the same underlying data, which could + // cause a concurrent map write panic. This is necessary because cancel + // is called from a goroutine in watchCancel. + o := make(values) + for k, v := range cn.opts { + o[k] = v + } + + c, err := dial(ctx, cn.dialer, o) + if err != nil { + return err + } + defer c.Close() + + { + can := conn{ + c: c, + } + err = can.ssl(o) + if err != nil { + return err + } + + w := can.writeBuf(0) + w.int32(80877102) // cancel request code + w.int32(cn.processID) + w.int32(cn.secretKey) + + if err := can.sendStartupPacket(w); err != nil { + return err + } + } + + // Read until EOF to ensure that the server received the cancel. + { + _, err := io.Copy(ioutil.Discard, c) + return err + } +} + +// Implement the "StmtQueryContext" interface +func (st *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) { + list := make([]driver.Value, len(args)) + for i, nv := range args { + list[i] = nv.Value + } + finish := st.watchCancel(ctx) + r, err := st.query(list) + if err != nil { + if finish != nil { + finish() + } + return nil, err + } + r.finish = finish + return r, nil +} + +// Implement the "StmtExecContext" interface +func (st *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) { + list := make([]driver.Value, len(args)) + for i, nv := range args { + list[i] = nv.Value + } + + if finish := st.watchCancel(ctx); finish != nil { + defer finish() + } + + return st.Exec(list) +} + +// watchCancel is implemented on stmt in order to not mark the parent conn as bad +func (st *stmt) watchCancel(ctx context.Context) func() { + if done := ctx.Done(); done != nil { + finished := make(chan struct{}) + go func() { + select { + case <-done: + // At this point the function level context is canceled, + // so it must not be used for the additional network + // request to cancel the query. + // Create a new context to pass into the dial. + ctxCancel, cancel := context.WithTimeout(context.Background(), watchCancelDialContextTimeout) + defer cancel() + + _ = st.cancel(ctxCancel) + finished <- struct{}{} + case <-finished: + } + }() + return func() { + select { + case <-finished: + case finished <- struct{}{}: + } + } + } + return nil +} + +func (st *stmt) cancel(ctx context.Context) error { + return st.cn.cancel(ctx) +} diff --git a/vendor/github.com/lib/pq/connector.go b/vendor/github.com/lib/pq/connector.go new file mode 100644 index 0000000..1145e12 --- /dev/null +++ b/vendor/github.com/lib/pq/connector.go @@ -0,0 +1,120 @@ +package pq + +import ( + "context" + "database/sql/driver" + "errors" + "fmt" + "os" + "strings" +) + +// Connector represents a fixed configuration for the pq driver with a given +// name. Connector satisfies the database/sql/driver Connector interface and +// can be used to create any number of DB Conn's via the database/sql OpenDB +// function. +// +// See https://golang.org/pkg/database/sql/driver/#Connector. +// See https://golang.org/pkg/database/sql/#OpenDB. +type Connector struct { + opts values + dialer Dialer +} + +// Connect returns a connection to the database using the fixed configuration +// of this Connector. Context is not used. +func (c *Connector) Connect(ctx context.Context) (driver.Conn, error) { + return c.open(ctx) +} + +// Dialer allows change the dialer used to open connections. +func (c *Connector) Dialer(dialer Dialer) { + c.dialer = dialer +} + +// Driver returns the underlying driver of this Connector. +func (c *Connector) Driver() driver.Driver { + return &Driver{} +} + +// NewConnector returns a connector for the pq driver in a fixed configuration +// with the given dsn. The returned connector can be used to create any number +// of equivalent Conn's. The returned connector is intended to be used with +// database/sql.OpenDB. +// +// See https://golang.org/pkg/database/sql/driver/#Connector. +// See https://golang.org/pkg/database/sql/#OpenDB. +func NewConnector(dsn string) (*Connector, error) { + var err error + o := make(values) + + // A number of defaults are applied here, in this order: + // + // * Very low precedence defaults applied in every situation + // * Environment variables + // * Explicitly passed connection information + o["host"] = "localhost" + o["port"] = "5432" + // N.B.: Extra float digits should be set to 3, but that breaks + // Postgres 8.4 and older, where the max is 2. + o["extra_float_digits"] = "2" + for k, v := range parseEnviron(os.Environ()) { + o[k] = v + } + + if strings.HasPrefix(dsn, "postgres://") || strings.HasPrefix(dsn, "postgresql://") { + dsn, err = ParseURL(dsn) + if err != nil { + return nil, err + } + } + + if err := parseOpts(dsn, o); err != nil { + return nil, err + } + + // Use the "fallback" application name if necessary + if fallback, ok := o["fallback_application_name"]; ok { + if _, ok := o["application_name"]; !ok { + o["application_name"] = fallback + } + } + + // We can't work with any client_encoding other than UTF-8 currently. + // However, we have historically allowed the user to set it to UTF-8 + // explicitly, and there's no reason to break such programs, so allow that. + // Note that the "options" setting could also set client_encoding, but + // parsing its value is not worth it. Instead, we always explicitly send + // client_encoding as a separate run-time parameter, which should override + // anything set in options. + if enc, ok := o["client_encoding"]; ok && !isUTF8(enc) { + return nil, errors.New("client_encoding must be absent or 'UTF8'") + } + o["client_encoding"] = "UTF8" + // DateStyle needs a similar treatment. + if datestyle, ok := o["datestyle"]; ok { + if datestyle != "ISO, MDY" { + return nil, fmt.Errorf("setting datestyle must be absent or %v; got %v", "ISO, MDY", datestyle) + } + } else { + o["datestyle"] = "ISO, MDY" + } + + // If a user is not provided by any other means, the last + // resort is to use the current operating system provided user + // name. + if _, ok := o["user"]; !ok { + u, err := userCurrent() + if err != nil { + return nil, err + } + o["user"] = u + } + + // SSL is not necessary or supported over UNIX domain sockets + if network, _ := network(o); network == "unix" { + o["sslmode"] = "disable" + } + + return &Connector{opts: o, dialer: defaultDialer{}}, nil +} diff --git a/vendor/github.com/lib/pq/copy.go b/vendor/github.com/lib/pq/copy.go new file mode 100644 index 0000000..a8f16b2 --- /dev/null +++ b/vendor/github.com/lib/pq/copy.go @@ -0,0 +1,348 @@ +package pq + +import ( + "bytes" + "context" + "database/sql/driver" + "encoding/binary" + "errors" + "fmt" + "sync" +) + +var ( + errCopyInClosed = errors.New("pq: copyin statement has already been closed") + errBinaryCopyNotSupported = errors.New("pq: only text format supported for COPY") + errCopyToNotSupported = errors.New("pq: COPY TO is not supported") + errCopyNotSupportedOutsideTxn = errors.New("pq: COPY is only allowed inside a transaction") + errCopyInProgress = errors.New("pq: COPY in progress") +) + +// CopyIn creates a COPY FROM statement which can be prepared with +// Tx.Prepare(). The target table should be visible in search_path. +func CopyIn(table string, columns ...string) string { + buffer := bytes.NewBufferString("COPY ") + BufferQuoteIdentifier(table, buffer) + buffer.WriteString(" (") + makeStmt(buffer, columns...) + return buffer.String() +} + +// MakeStmt makes the stmt string for CopyIn and CopyInSchema. +func makeStmt(buffer *bytes.Buffer, columns ...string) { + //s := bytes.NewBufferString() + for i, col := range columns { + if i != 0 { + buffer.WriteString(", ") + } + BufferQuoteIdentifier(col, buffer) + } + buffer.WriteString(") FROM STDIN") +} + +// CopyInSchema creates a COPY FROM statement which can be prepared with +// Tx.Prepare(). +func CopyInSchema(schema, table string, columns ...string) string { + buffer := bytes.NewBufferString("COPY ") + BufferQuoteIdentifier(schema, buffer) + buffer.WriteRune('.') + BufferQuoteIdentifier(table, buffer) + buffer.WriteString(" (") + makeStmt(buffer, columns...) + return buffer.String() +} + +type copyin struct { + cn *conn + buffer []byte + rowData chan []byte + done chan bool + + closed bool + + mu struct { + sync.Mutex + err error + driver.Result + } +} + +const ciBufferSize = 64 * 1024 + +// flush buffer before the buffer is filled up and needs reallocation +const ciBufferFlushSize = 63 * 1024 + +func (cn *conn) prepareCopyIn(q string) (_ driver.Stmt, err error) { + if !cn.isInTransaction() { + return nil, errCopyNotSupportedOutsideTxn + } + + ci := ©in{ + cn: cn, + buffer: make([]byte, 0, ciBufferSize), + rowData: make(chan []byte), + done: make(chan bool, 1), + } + // add CopyData identifier + 4 bytes for message length + ci.buffer = append(ci.buffer, 'd', 0, 0, 0, 0) + + b := cn.writeBuf('Q') + b.string(q) + cn.send(b) + +awaitCopyInResponse: + for { + t, r := cn.recv1() + switch t { + case 'G': + if r.byte() != 0 { + err = errBinaryCopyNotSupported + break awaitCopyInResponse + } + go ci.resploop() + return ci, nil + case 'H': + err = errCopyToNotSupported + break awaitCopyInResponse + case 'E': + err = parseError(r) + case 'Z': + if err == nil { + ci.setBad(driver.ErrBadConn) + errorf("unexpected ReadyForQuery in response to COPY") + } + cn.processReadyForQuery(r) + return nil, err + default: + ci.setBad(driver.ErrBadConn) + errorf("unknown response for copy query: %q", t) + } + } + + // something went wrong, abort COPY before we return + b = cn.writeBuf('f') + b.string(err.Error()) + cn.send(b) + + for { + t, r := cn.recv1() + switch t { + case 'c', 'C', 'E': + case 'Z': + // correctly aborted, we're done + cn.processReadyForQuery(r) + return nil, err + default: + ci.setBad(driver.ErrBadConn) + errorf("unknown response for CopyFail: %q", t) + } + } +} + +func (ci *copyin) flush(buf []byte) { + // set message length (without message identifier) + binary.BigEndian.PutUint32(buf[1:], uint32(len(buf)-1)) + + _, err := ci.cn.c.Write(buf) + if err != nil { + panic(err) + } +} + +func (ci *copyin) resploop() { + for { + var r readBuf + t, err := ci.cn.recvMessage(&r) + if err != nil { + ci.setBad(driver.ErrBadConn) + ci.setError(err) + ci.done <- true + return + } + switch t { + case 'C': + // complete + res, _ := ci.cn.parseComplete(r.string()) + ci.setResult(res) + case 'N': + if n := ci.cn.noticeHandler; n != nil { + n(parseError(&r)) + } + case 'Z': + ci.cn.processReadyForQuery(&r) + ci.done <- true + return + case 'E': + err := parseError(&r) + ci.setError(err) + default: + ci.setBad(driver.ErrBadConn) + ci.setError(fmt.Errorf("unknown response during CopyIn: %q", t)) + ci.done <- true + return + } + } +} + +func (ci *copyin) setBad(err error) { + ci.cn.err.set(err) +} + +func (ci *copyin) getBad() error { + return ci.cn.err.get() +} + +func (ci *copyin) err() error { + ci.mu.Lock() + err := ci.mu.err + ci.mu.Unlock() + return err +} + +// setError() sets ci.err if one has not been set already. Caller must not be +// holding ci.Mutex. +func (ci *copyin) setError(err error) { + ci.mu.Lock() + if ci.mu.err == nil { + ci.mu.err = err + } + ci.mu.Unlock() +} + +func (ci *copyin) setResult(result driver.Result) { + ci.mu.Lock() + ci.mu.Result = result + ci.mu.Unlock() +} + +func (ci *copyin) getResult() driver.Result { + ci.mu.Lock() + result := ci.mu.Result + ci.mu.Unlock() + if result == nil { + return driver.RowsAffected(0) + } + return result +} + +func (ci *copyin) NumInput() int { + return -1 +} + +func (ci *copyin) Query(v []driver.Value) (r driver.Rows, err error) { + return nil, ErrNotSupported +} + +// Exec inserts values into the COPY stream. The insert is asynchronous +// and Exec can return errors from previous Exec calls to the same +// COPY stmt. +// +// You need to call Exec(nil) to sync the COPY stream and to get any +// errors from pending data, since Stmt.Close() doesn't return errors +// to the user. +func (ci *copyin) Exec(v []driver.Value) (r driver.Result, err error) { + if ci.closed { + return nil, errCopyInClosed + } + + if err := ci.getBad(); err != nil { + return nil, err + } + defer ci.cn.errRecover(&err) + + if err := ci.err(); err != nil { + return nil, err + } + + if len(v) == 0 { + if err := ci.Close(); err != nil { + return driver.RowsAffected(0), err + } + + return ci.getResult(), nil + } + + numValues := len(v) + for i, value := range v { + ci.buffer = appendEncodedText(&ci.cn.parameterStatus, ci.buffer, value) + if i < numValues-1 { + ci.buffer = append(ci.buffer, '\t') + } + } + + ci.buffer = append(ci.buffer, '\n') + + if len(ci.buffer) > ciBufferFlushSize { + ci.flush(ci.buffer) + // reset buffer, keep bytes for message identifier and length + ci.buffer = ci.buffer[:5] + } + + return driver.RowsAffected(0), nil +} + +// CopyData inserts a raw string into the COPY stream. The insert is +// asynchronous and CopyData can return errors from previous CopyData calls to +// the same COPY stmt. +// +// You need to call Exec(nil) to sync the COPY stream and to get any +// errors from pending data, since Stmt.Close() doesn't return errors +// to the user. +func (ci *copyin) CopyData(ctx context.Context, line string) (r driver.Result, err error) { + if ci.closed { + return nil, errCopyInClosed + } + + if finish := ci.cn.watchCancel(ctx); finish != nil { + defer finish() + } + + if err := ci.getBad(); err != nil { + return nil, err + } + defer ci.cn.errRecover(&err) + + if err := ci.err(); err != nil { + return nil, err + } + + ci.buffer = append(ci.buffer, []byte(line)...) + ci.buffer = append(ci.buffer, '\n') + + if len(ci.buffer) > ciBufferFlushSize { + ci.flush(ci.buffer) + // reset buffer, keep bytes for message identifier and length + ci.buffer = ci.buffer[:5] + } + + return driver.RowsAffected(0), nil +} + +func (ci *copyin) Close() (err error) { + if ci.closed { // Don't do anything, we're already closed + return nil + } + ci.closed = true + + if err := ci.getBad(); err != nil { + return err + } + defer ci.cn.errRecover(&err) + + if len(ci.buffer) > 0 { + ci.flush(ci.buffer) + } + // Avoid touching the scratch buffer as resploop could be using it. + err = ci.cn.sendSimpleMessage('c') + if err != nil { + return err + } + + <-ci.done + ci.cn.inCopy = false + + if err := ci.err(); err != nil { + return err + } + return nil +} diff --git a/vendor/github.com/lib/pq/doc.go b/vendor/github.com/lib/pq/doc.go new file mode 100644 index 0000000..b571848 --- /dev/null +++ b/vendor/github.com/lib/pq/doc.go @@ -0,0 +1,268 @@ +/* +Package pq is a pure Go Postgres driver for the database/sql package. + +In most cases clients will use the database/sql package instead of +using this package directly. For example: + + import ( + "database/sql" + + _ "github.com/lib/pq" + ) + + func main() { + connStr := "user=pqgotest dbname=pqgotest sslmode=verify-full" + db, err := sql.Open("postgres", connStr) + if err != nil { + log.Fatal(err) + } + + age := 21 + rows, err := db.Query("SELECT name FROM users WHERE age = $1", age) + … + } + +You can also connect to a database using a URL. For example: + + connStr := "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full" + db, err := sql.Open("postgres", connStr) + + +Connection String Parameters + + +Similarly to libpq, when establishing a connection using pq you are expected to +supply a connection string containing zero or more parameters. +A subset of the connection parameters supported by libpq are also supported by pq. +Additionally, pq also lets you specify run-time parameters (such as search_path or work_mem) +directly in the connection string. This is different from libpq, which does not allow +run-time parameters in the connection string, instead requiring you to supply +them in the options parameter. + +For compatibility with libpq, the following special connection parameters are +supported: + + * dbname - The name of the database to connect to + * user - The user to sign in as + * password - The user's password + * host - The host to connect to. Values that start with / are for unix + domain sockets. (default is localhost) + * port - The port to bind to. (default is 5432) + * sslmode - Whether or not to use SSL (default is require, this is not + the default for libpq) + * fallback_application_name - An application_name to fall back to if one isn't provided. + * connect_timeout - Maximum wait for connection, in seconds. Zero or + not specified means wait indefinitely. + * sslcert - Cert file location. The file must contain PEM encoded data. + * sslkey - Key file location. The file must contain PEM encoded data. + * sslrootcert - The location of the root certificate file. The file + must contain PEM encoded data. + +Valid values for sslmode are: + + * disable - No SSL + * require - Always SSL (skip verification) + * verify-ca - Always SSL (verify that the certificate presented by the + server was signed by a trusted CA) + * verify-full - Always SSL (verify that the certification presented by + the server was signed by a trusted CA and the server host name + matches the one in the certificate) + +See http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING +for more information about connection string parameters. + +Use single quotes for values that contain whitespace: + + "user=pqgotest password='with spaces'" + +A backslash will escape the next character in values: + + "user=space\ man password='it\'s valid'" + +Note that the connection parameter client_encoding (which sets the +text encoding for the connection) may be set but must be "UTF8", +matching with the same rules as Postgres. It is an error to provide +any other value. + +In addition to the parameters listed above, any run-time parameter that can be +set at backend start time can be set in the connection string. For more +information, see +http://www.postgresql.org/docs/current/static/runtime-config.html. + +Most environment variables as specified at http://www.postgresql.org/docs/current/static/libpq-envars.html +supported by libpq are also supported by pq. If any of the environment +variables not supported by pq are set, pq will panic during connection +establishment. Environment variables have a lower precedence than explicitly +provided connection parameters. + +The pgpass mechanism as described in http://www.postgresql.org/docs/current/static/libpq-pgpass.html +is supported, but on Windows PGPASSFILE must be specified explicitly. + + +Queries + + +database/sql does not dictate any specific format for parameter +markers in query strings, and pq uses the Postgres-native ordinal markers, +as shown above. The same marker can be reused for the same parameter: + + rows, err := db.Query(`SELECT name FROM users WHERE favorite_fruit = $1 + OR age BETWEEN $2 AND $2 + 3`, "orange", 64) + +pq does not support the LastInsertId() method of the Result type in database/sql. +To return the identifier of an INSERT (or UPDATE or DELETE), use the Postgres +RETURNING clause with a standard Query or QueryRow call: + + var userid int + err := db.QueryRow(`INSERT INTO users(name, favorite_fruit, age) + VALUES('beatrice', 'starfruit', 93) RETURNING id`).Scan(&userid) + +For more details on RETURNING, see the Postgres documentation: + + http://www.postgresql.org/docs/current/static/sql-insert.html + http://www.postgresql.org/docs/current/static/sql-update.html + http://www.postgresql.org/docs/current/static/sql-delete.html + +For additional instructions on querying see the documentation for the database/sql package. + + +Data Types + + +Parameters pass through driver.DefaultParameterConverter before they are handled +by this package. When the binary_parameters connection option is enabled, +[]byte values are sent directly to the backend as data in binary format. + +This package returns the following types for values from the PostgreSQL backend: + + - integer types smallint, integer, and bigint are returned as int64 + - floating-point types real and double precision are returned as float64 + - character types char, varchar, and text are returned as string + - temporal types date, time, timetz, timestamp, and timestamptz are + returned as time.Time + - the boolean type is returned as bool + - the bytea type is returned as []byte + +All other types are returned directly from the backend as []byte values in text format. + + +Errors + + +pq may return errors of type *pq.Error which can be interrogated for error details: + + if err, ok := err.(*pq.Error); ok { + fmt.Println("pq error:", err.Code.Name()) + } + +See the pq.Error type for details. + + +Bulk imports + +You can perform bulk imports by preparing a statement returned by pq.CopyIn (or +pq.CopyInSchema) in an explicit transaction (sql.Tx). The returned statement +handle can then be repeatedly "executed" to copy data into the target table. +After all data has been processed you should call Exec() once with no arguments +to flush all buffered data. Any call to Exec() might return an error which +should be handled appropriately, but because of the internal buffering an error +returned by Exec() might not be related to the data passed in the call that +failed. + +CopyIn uses COPY FROM internally. It is not possible to COPY outside of an +explicit transaction in pq. + +Usage example: + + txn, err := db.Begin() + if err != nil { + log.Fatal(err) + } + + stmt, err := txn.Prepare(pq.CopyIn("users", "name", "age")) + if err != nil { + log.Fatal(err) + } + + for _, user := range users { + _, err = stmt.Exec(user.Name, int64(user.Age)) + if err != nil { + log.Fatal(err) + } + } + + _, err = stmt.Exec() + if err != nil { + log.Fatal(err) + } + + err = stmt.Close() + if err != nil { + log.Fatal(err) + } + + err = txn.Commit() + if err != nil { + log.Fatal(err) + } + + +Notifications + + +PostgreSQL supports a simple publish/subscribe model over database +connections. See http://www.postgresql.org/docs/current/static/sql-notify.html +for more information about the general mechanism. + +To start listening for notifications, you first have to open a new connection +to the database by calling NewListener. This connection can not be used for +anything other than LISTEN / NOTIFY. Calling Listen will open a "notification +channel"; once a notification channel is open, a notification generated on that +channel will effect a send on the Listener.Notify channel. A notification +channel will remain open until Unlisten is called, though connection loss might +result in some notifications being lost. To solve this problem, Listener sends +a nil pointer over the Notify channel any time the connection is re-established +following a connection loss. The application can get information about the +state of the underlying connection by setting an event callback in the call to +NewListener. + +A single Listener can safely be used from concurrent goroutines, which means +that there is often no need to create more than one Listener in your +application. However, a Listener is always connected to a single database, so +you will need to create a new Listener instance for every database you want to +receive notifications in. + +The channel name in both Listen and Unlisten is case sensitive, and can contain +any characters legal in an identifier (see +http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS +for more information). Note that the channel name will be truncated to 63 +bytes by the PostgreSQL server. + +You can find a complete, working example of Listener usage at +https://godoc.org/github.com/lib/pq/example/listen. + + +Kerberos Support + + +If you need support for Kerberos authentication, add the following to your main +package: + + import "github.com/lib/pq/auth/kerberos" + + func init() { + pq.RegisterGSSProvider(func() (pq.Gss, error) { return kerberos.NewGSS() }) + } + +This package is in a separate module so that users who don't need Kerberos +don't have to download unnecessary dependencies. + +When imported, additional connection string parameters are supported: + + * krbsrvname - GSS (Kerberos) service name when constructing the + SPN (default is `postgres`). This will be combined with the host + to form the full SPN: `krbsrvname/host`. + * krbspn - GSS (Kerberos) SPN. This takes priority over + `krbsrvname` if present. +*/ +package pq diff --git a/vendor/github.com/lib/pq/encode.go b/vendor/github.com/lib/pq/encode.go new file mode 100644 index 0000000..bffe609 --- /dev/null +++ b/vendor/github.com/lib/pq/encode.go @@ -0,0 +1,632 @@ +package pq + +import ( + "bytes" + "database/sql/driver" + "encoding/binary" + "encoding/hex" + "errors" + "fmt" + "math" + "regexp" + "strconv" + "strings" + "sync" + "time" + + "github.com/lib/pq/oid" +) + +var time2400Regex = regexp.MustCompile(`^(24:00(?::00(?:\.0+)?)?)(?:[Z+-].*)?$`) + +func binaryEncode(parameterStatus *parameterStatus, x interface{}) []byte { + switch v := x.(type) { + case []byte: + return v + default: + return encode(parameterStatus, x, oid.T_unknown) + } +} + +func encode(parameterStatus *parameterStatus, x interface{}, pgtypOid oid.Oid) []byte { + switch v := x.(type) { + case int64: + return strconv.AppendInt(nil, v, 10) + case float64: + return strconv.AppendFloat(nil, v, 'f', -1, 64) + case []byte: + if pgtypOid == oid.T_bytea { + return encodeBytea(parameterStatus.serverVersion, v) + } + + return v + case string: + if pgtypOid == oid.T_bytea { + return encodeBytea(parameterStatus.serverVersion, []byte(v)) + } + + return []byte(v) + case bool: + return strconv.AppendBool(nil, v) + case time.Time: + return formatTs(v) + + default: + errorf("encode: unknown type for %T", v) + } + + panic("not reached") +} + +func decode(parameterStatus *parameterStatus, s []byte, typ oid.Oid, f format) interface{} { + switch f { + case formatBinary: + return binaryDecode(parameterStatus, s, typ) + case formatText: + return textDecode(parameterStatus, s, typ) + default: + panic("not reached") + } +} + +func binaryDecode(parameterStatus *parameterStatus, s []byte, typ oid.Oid) interface{} { + switch typ { + case oid.T_bytea: + return s + case oid.T_int8: + return int64(binary.BigEndian.Uint64(s)) + case oid.T_int4: + return int64(int32(binary.BigEndian.Uint32(s))) + case oid.T_int2: + return int64(int16(binary.BigEndian.Uint16(s))) + case oid.T_uuid: + b, err := decodeUUIDBinary(s) + if err != nil { + panic(err) + } + return b + + default: + errorf("don't know how to decode binary parameter of type %d", uint32(typ)) + } + + panic("not reached") +} + +func textDecode(parameterStatus *parameterStatus, s []byte, typ oid.Oid) interface{} { + switch typ { + case oid.T_char, oid.T_varchar, oid.T_text: + return string(s) + case oid.T_bytea: + b, err := parseBytea(s) + if err != nil { + errorf("%s", err) + } + return b + case oid.T_timestamptz: + return parseTs(parameterStatus.currentLocation, string(s)) + case oid.T_timestamp, oid.T_date: + return parseTs(nil, string(s)) + case oid.T_time: + return mustParse("15:04:05", typ, s) + case oid.T_timetz: + return mustParse("15:04:05-07", typ, s) + case oid.T_bool: + return s[0] == 't' + case oid.T_int8, oid.T_int4, oid.T_int2: + i, err := strconv.ParseInt(string(s), 10, 64) + if err != nil { + errorf("%s", err) + } + return i + case oid.T_float4, oid.T_float8: + // We always use 64 bit parsing, regardless of whether the input text is for + // a float4 or float8, because clients expect float64s for all float datatypes + // and returning a 32-bit parsed float64 produces lossy results. + f, err := strconv.ParseFloat(string(s), 64) + if err != nil { + errorf("%s", err) + } + return f + } + + return s +} + +// appendEncodedText encodes item in text format as required by COPY +// and appends to buf +func appendEncodedText(parameterStatus *parameterStatus, buf []byte, x interface{}) []byte { + switch v := x.(type) { + case int64: + return strconv.AppendInt(buf, v, 10) + case float64: + return strconv.AppendFloat(buf, v, 'f', -1, 64) + case []byte: + encodedBytea := encodeBytea(parameterStatus.serverVersion, v) + return appendEscapedText(buf, string(encodedBytea)) + case string: + return appendEscapedText(buf, v) + case bool: + return strconv.AppendBool(buf, v) + case time.Time: + return append(buf, formatTs(v)...) + case nil: + return append(buf, "\\N"...) + default: + errorf("encode: unknown type for %T", v) + } + + panic("not reached") +} + +func appendEscapedText(buf []byte, text string) []byte { + escapeNeeded := false + startPos := 0 + var c byte + + // check if we need to escape + for i := 0; i < len(text); i++ { + c = text[i] + if c == '\\' || c == '\n' || c == '\r' || c == '\t' { + escapeNeeded = true + startPos = i + break + } + } + if !escapeNeeded { + return append(buf, text...) + } + + // copy till first char to escape, iterate the rest + result := append(buf, text[:startPos]...) + for i := startPos; i < len(text); i++ { + c = text[i] + switch c { + case '\\': + result = append(result, '\\', '\\') + case '\n': + result = append(result, '\\', 'n') + case '\r': + result = append(result, '\\', 'r') + case '\t': + result = append(result, '\\', 't') + default: + result = append(result, c) + } + } + return result +} + +func mustParse(f string, typ oid.Oid, s []byte) time.Time { + str := string(s) + + // Check for a minute and second offset in the timezone. + if typ == oid.T_timestamptz || typ == oid.T_timetz { + for i := 3; i <= 6; i += 3 { + if str[len(str)-i] == ':' { + f += ":00" + continue + } + break + } + } + + // Special case for 24:00 time. + // Unfortunately, golang does not parse 24:00 as a proper time. + // In this case, we want to try "round to the next day", to differentiate. + // As such, we find if the 24:00 time matches at the beginning; if so, + // we default it back to 00:00 but add a day later. + var is2400Time bool + switch typ { + case oid.T_timetz, oid.T_time: + if matches := time2400Regex.FindStringSubmatch(str); matches != nil { + // Concatenate timezone information at the back. + str = "00:00:00" + str[len(matches[1]):] + is2400Time = true + } + } + t, err := time.Parse(f, str) + if err != nil { + errorf("decode: %s", err) + } + if is2400Time { + t = t.Add(24 * time.Hour) + } + return t +} + +var errInvalidTimestamp = errors.New("invalid timestamp") + +type timestampParser struct { + err error +} + +func (p *timestampParser) expect(str string, char byte, pos int) { + if p.err != nil { + return + } + if pos+1 > len(str) { + p.err = errInvalidTimestamp + return + } + if c := str[pos]; c != char && p.err == nil { + p.err = fmt.Errorf("expected '%v' at position %v; got '%v'", char, pos, c) + } +} + +func (p *timestampParser) mustAtoi(str string, begin int, end int) int { + if p.err != nil { + return 0 + } + if begin < 0 || end < 0 || begin > end || end > len(str) { + p.err = errInvalidTimestamp + return 0 + } + result, err := strconv.Atoi(str[begin:end]) + if err != nil { + if p.err == nil { + p.err = fmt.Errorf("expected number; got '%v'", str) + } + return 0 + } + return result +} + +// The location cache caches the time zones typically used by the client. +type locationCache struct { + cache map[int]*time.Location + lock sync.Mutex +} + +// All connections share the same list of timezones. Benchmarking shows that +// about 5% speed could be gained by putting the cache in the connection and +// losing the mutex, at the cost of a small amount of memory and a somewhat +// significant increase in code complexity. +var globalLocationCache = newLocationCache() + +func newLocationCache() *locationCache { + return &locationCache{cache: make(map[int]*time.Location)} +} + +// Returns the cached timezone for the specified offset, creating and caching +// it if necessary. +func (c *locationCache) getLocation(offset int) *time.Location { + c.lock.Lock() + defer c.lock.Unlock() + + location, ok := c.cache[offset] + if !ok { + location = time.FixedZone("", offset) + c.cache[offset] = location + } + + return location +} + +var infinityTsEnabled = false +var infinityTsNegative time.Time +var infinityTsPositive time.Time + +const ( + infinityTsEnabledAlready = "pq: infinity timestamp enabled already" + infinityTsNegativeMustBeSmaller = "pq: infinity timestamp: negative value must be smaller (before) than positive" +) + +// EnableInfinityTs controls the handling of Postgres' "-infinity" and +// "infinity" "timestamp"s. +// +// If EnableInfinityTs is not called, "-infinity" and "infinity" will return +// []byte("-infinity") and []byte("infinity") respectively, and potentially +// cause error "sql: Scan error on column index 0: unsupported driver -> Scan +// pair: []uint8 -> *time.Time", when scanning into a time.Time value. +// +// Once EnableInfinityTs has been called, all connections created using this +// driver will decode Postgres' "-infinity" and "infinity" for "timestamp", +// "timestamp with time zone" and "date" types to the predefined minimum and +// maximum times, respectively. When encoding time.Time values, any time which +// equals or precedes the predefined minimum time will be encoded to +// "-infinity". Any values at or past the maximum time will similarly be +// encoded to "infinity". +// +// If EnableInfinityTs is called with negative >= positive, it will panic. +// Calling EnableInfinityTs after a connection has been established results in +// undefined behavior. If EnableInfinityTs is called more than once, it will +// panic. +func EnableInfinityTs(negative time.Time, positive time.Time) { + if infinityTsEnabled { + panic(infinityTsEnabledAlready) + } + if !negative.Before(positive) { + panic(infinityTsNegativeMustBeSmaller) + } + infinityTsEnabled = true + infinityTsNegative = negative + infinityTsPositive = positive +} + +/* + * Testing might want to toggle infinityTsEnabled + */ +func disableInfinityTs() { + infinityTsEnabled = false +} + +// This is a time function specific to the Postgres default DateStyle +// setting ("ISO, MDY"), the only one we currently support. This +// accounts for the discrepancies between the parsing available with +// time.Parse and the Postgres date formatting quirks. +func parseTs(currentLocation *time.Location, str string) interface{} { + switch str { + case "-infinity": + if infinityTsEnabled { + return infinityTsNegative + } + return []byte(str) + case "infinity": + if infinityTsEnabled { + return infinityTsPositive + } + return []byte(str) + } + t, err := ParseTimestamp(currentLocation, str) + if err != nil { + panic(err) + } + return t +} + +// ParseTimestamp parses Postgres' text format. It returns a time.Time in +// currentLocation iff that time's offset agrees with the offset sent from the +// Postgres server. Otherwise, ParseTimestamp returns a time.Time with the +// fixed offset offset provided by the Postgres server. +func ParseTimestamp(currentLocation *time.Location, str string) (time.Time, error) { + p := timestampParser{} + + monSep := strings.IndexRune(str, '-') + // this is Gregorian year, not ISO Year + // In Gregorian system, the year 1 BC is followed by AD 1 + year := p.mustAtoi(str, 0, monSep) + daySep := monSep + 3 + month := p.mustAtoi(str, monSep+1, daySep) + p.expect(str, '-', daySep) + timeSep := daySep + 3 + day := p.mustAtoi(str, daySep+1, timeSep) + + minLen := monSep + len("01-01") + 1 + + isBC := strings.HasSuffix(str, " BC") + if isBC { + minLen += 3 + } + + var hour, minute, second int + if len(str) > minLen { + p.expect(str, ' ', timeSep) + minSep := timeSep + 3 + p.expect(str, ':', minSep) + hour = p.mustAtoi(str, timeSep+1, minSep) + secSep := minSep + 3 + p.expect(str, ':', secSep) + minute = p.mustAtoi(str, minSep+1, secSep) + secEnd := secSep + 3 + second = p.mustAtoi(str, secSep+1, secEnd) + } + remainderIdx := monSep + len("01-01 00:00:00") + 1 + // Three optional (but ordered) sections follow: the + // fractional seconds, the time zone offset, and the BC + // designation. We set them up here and adjust the other + // offsets if the preceding sections exist. + + nanoSec := 0 + tzOff := 0 + + if remainderIdx < len(str) && str[remainderIdx] == '.' { + fracStart := remainderIdx + 1 + fracOff := strings.IndexAny(str[fracStart:], "-+Z ") + if fracOff < 0 { + fracOff = len(str) - fracStart + } + fracSec := p.mustAtoi(str, fracStart, fracStart+fracOff) + nanoSec = fracSec * (1000000000 / int(math.Pow(10, float64(fracOff)))) + + remainderIdx += fracOff + 1 + } + if tzStart := remainderIdx; tzStart < len(str) && (str[tzStart] == '-' || str[tzStart] == '+') { + // time zone separator is always '-' or '+' or 'Z' (UTC is +00) + var tzSign int + switch c := str[tzStart]; c { + case '-': + tzSign = -1 + case '+': + tzSign = +1 + default: + return time.Time{}, fmt.Errorf("expected '-' or '+' at position %v; got %v", tzStart, c) + } + tzHours := p.mustAtoi(str, tzStart+1, tzStart+3) + remainderIdx += 3 + var tzMin, tzSec int + if remainderIdx < len(str) && str[remainderIdx] == ':' { + tzMin = p.mustAtoi(str, remainderIdx+1, remainderIdx+3) + remainderIdx += 3 + } + if remainderIdx < len(str) && str[remainderIdx] == ':' { + tzSec = p.mustAtoi(str, remainderIdx+1, remainderIdx+3) + remainderIdx += 3 + } + tzOff = tzSign * ((tzHours * 60 * 60) + (tzMin * 60) + tzSec) + } else if tzStart < len(str) && str[tzStart] == 'Z' { + // time zone Z separator indicates UTC is +00 + remainderIdx += 1 + } + + var isoYear int + + if isBC { + isoYear = 1 - year + remainderIdx += 3 + } else { + isoYear = year + } + if remainderIdx < len(str) { + return time.Time{}, fmt.Errorf("expected end of input, got %v", str[remainderIdx:]) + } + t := time.Date(isoYear, time.Month(month), day, + hour, minute, second, nanoSec, + globalLocationCache.getLocation(tzOff)) + + if currentLocation != nil { + // Set the location of the returned Time based on the session's + // TimeZone value, but only if the local time zone database agrees with + // the remote database on the offset. + lt := t.In(currentLocation) + _, newOff := lt.Zone() + if newOff == tzOff { + t = lt + } + } + + return t, p.err +} + +// formatTs formats t into a format postgres understands. +func formatTs(t time.Time) []byte { + if infinityTsEnabled { + // t <= -infinity : ! (t > -infinity) + if !t.After(infinityTsNegative) { + return []byte("-infinity") + } + // t >= infinity : ! (!t < infinity) + if !t.Before(infinityTsPositive) { + return []byte("infinity") + } + } + return FormatTimestamp(t) +} + +// FormatTimestamp formats t into Postgres' text format for timestamps. +func FormatTimestamp(t time.Time) []byte { + // Need to send dates before 0001 A.D. with " BC" suffix, instead of the + // minus sign preferred by Go. + // Beware, "0000" in ISO is "1 BC", "-0001" is "2 BC" and so on + bc := false + if t.Year() <= 0 { + // flip year sign, and add 1, e.g: "0" will be "1", and "-10" will be "11" + t = t.AddDate((-t.Year())*2+1, 0, 0) + bc = true + } + b := []byte(t.Format("2006-01-02 15:04:05.999999999Z07:00")) + + _, offset := t.Zone() + offset %= 60 + if offset != 0 { + // RFC3339Nano already printed the minus sign + if offset < 0 { + offset = -offset + } + + b = append(b, ':') + if offset < 10 { + b = append(b, '0') + } + b = strconv.AppendInt(b, int64(offset), 10) + } + + if bc { + b = append(b, " BC"...) + } + return b +} + +// Parse a bytea value received from the server. Both "hex" and the legacy +// "escape" format are supported. +func parseBytea(s []byte) (result []byte, err error) { + if len(s) >= 2 && bytes.Equal(s[:2], []byte("\\x")) { + // bytea_output = hex + s = s[2:] // trim off leading "\\x" + result = make([]byte, hex.DecodedLen(len(s))) + _, err := hex.Decode(result, s) + if err != nil { + return nil, err + } + } else { + // bytea_output = escape + for len(s) > 0 { + if s[0] == '\\' { + // escaped '\\' + if len(s) >= 2 && s[1] == '\\' { + result = append(result, '\\') + s = s[2:] + continue + } + + // '\\' followed by an octal number + if len(s) < 4 { + return nil, fmt.Errorf("invalid bytea sequence %v", s) + } + r, err := strconv.ParseUint(string(s[1:4]), 8, 8) + if err != nil { + return nil, fmt.Errorf("could not parse bytea value: %s", err.Error()) + } + result = append(result, byte(r)) + s = s[4:] + } else { + // We hit an unescaped, raw byte. Try to read in as many as + // possible in one go. + i := bytes.IndexByte(s, '\\') + if i == -1 { + result = append(result, s...) + break + } + result = append(result, s[:i]...) + s = s[i:] + } + } + } + + return result, nil +} + +func encodeBytea(serverVersion int, v []byte) (result []byte) { + if serverVersion >= 90000 { + // Use the hex format if we know that the server supports it + result = make([]byte, 2+hex.EncodedLen(len(v))) + result[0] = '\\' + result[1] = 'x' + hex.Encode(result[2:], v) + } else { + // .. or resort to "escape" + for _, b := range v { + if b == '\\' { + result = append(result, '\\', '\\') + } else if b < 0x20 || b > 0x7e { + result = append(result, []byte(fmt.Sprintf("\\%03o", b))...) + } else { + result = append(result, b) + } + } + } + + return result +} + +// NullTime represents a time.Time that may be null. NullTime implements the +// sql.Scanner interface so it can be used as a scan destination, similar to +// sql.NullString. +type NullTime struct { + Time time.Time + Valid bool // Valid is true if Time is not NULL +} + +// Scan implements the Scanner interface. +func (nt *NullTime) Scan(value interface{}) error { + nt.Time, nt.Valid = value.(time.Time) + return nil +} + +// Value implements the driver Valuer interface. +func (nt NullTime) Value() (driver.Value, error) { + if !nt.Valid { + return nil, nil + } + return nt.Time, nil +} diff --git a/vendor/github.com/lib/pq/error.go b/vendor/github.com/lib/pq/error.go new file mode 100644 index 0000000..f67c5a5 --- /dev/null +++ b/vendor/github.com/lib/pq/error.go @@ -0,0 +1,523 @@ +package pq + +import ( + "database/sql/driver" + "fmt" + "io" + "net" + "runtime" +) + +// Error severities +const ( + Efatal = "FATAL" + Epanic = "PANIC" + Ewarning = "WARNING" + Enotice = "NOTICE" + Edebug = "DEBUG" + Einfo = "INFO" + Elog = "LOG" +) + +// Error represents an error communicating with the server. +// +// See http://www.postgresql.org/docs/current/static/protocol-error-fields.html for details of the fields +type Error struct { + Severity string + Code ErrorCode + Message string + Detail string + Hint string + Position string + InternalPosition string + InternalQuery string + Where string + Schema string + Table string + Column string + DataTypeName string + Constraint string + File string + Line string + Routine string +} + +// ErrorCode is a five-character error code. +type ErrorCode string + +// Name returns a more human friendly rendering of the error code, namely the +// "condition name". +// +// See http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html for +// details. +func (ec ErrorCode) Name() string { + return errorCodeNames[ec] +} + +// ErrorClass is only the class part of an error code. +type ErrorClass string + +// Name returns the condition name of an error class. It is equivalent to the +// condition name of the "standard" error code (i.e. the one having the last +// three characters "000"). +func (ec ErrorClass) Name() string { + return errorCodeNames[ErrorCode(ec+"000")] +} + +// Class returns the error class, e.g. "28". +// +// See http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html for +// details. +func (ec ErrorCode) Class() ErrorClass { + return ErrorClass(ec[0:2]) +} + +// errorCodeNames is a mapping between the five-character error codes and the +// human readable "condition names". It is derived from the list at +// http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html +var errorCodeNames = map[ErrorCode]string{ + // Class 00 - Successful Completion + "00000": "successful_completion", + // Class 01 - Warning + "01000": "warning", + "0100C": "dynamic_result_sets_returned", + "01008": "implicit_zero_bit_padding", + "01003": "null_value_eliminated_in_set_function", + "01007": "privilege_not_granted", + "01006": "privilege_not_revoked", + "01004": "string_data_right_truncation", + "01P01": "deprecated_feature", + // Class 02 - No Data (this is also a warning class per the SQL standard) + "02000": "no_data", + "02001": "no_additional_dynamic_result_sets_returned", + // Class 03 - SQL Statement Not Yet Complete + "03000": "sql_statement_not_yet_complete", + // Class 08 - Connection Exception + "08000": "connection_exception", + "08003": "connection_does_not_exist", + "08006": "connection_failure", + "08001": "sqlclient_unable_to_establish_sqlconnection", + "08004": "sqlserver_rejected_establishment_of_sqlconnection", + "08007": "transaction_resolution_unknown", + "08P01": "protocol_violation", + // Class 09 - Triggered Action Exception + "09000": "triggered_action_exception", + // Class 0A - Feature Not Supported + "0A000": "feature_not_supported", + // Class 0B - Invalid Transaction Initiation + "0B000": "invalid_transaction_initiation", + // Class 0F - Locator Exception + "0F000": "locator_exception", + "0F001": "invalid_locator_specification", + // Class 0L - Invalid Grantor + "0L000": "invalid_grantor", + "0LP01": "invalid_grant_operation", + // Class 0P - Invalid Role Specification + "0P000": "invalid_role_specification", + // Class 0Z - Diagnostics Exception + "0Z000": "diagnostics_exception", + "0Z002": "stacked_diagnostics_accessed_without_active_handler", + // Class 20 - Case Not Found + "20000": "case_not_found", + // Class 21 - Cardinality Violation + "21000": "cardinality_violation", + // Class 22 - Data Exception + "22000": "data_exception", + "2202E": "array_subscript_error", + "22021": "character_not_in_repertoire", + "22008": "datetime_field_overflow", + "22012": "division_by_zero", + "22005": "error_in_assignment", + "2200B": "escape_character_conflict", + "22022": "indicator_overflow", + "22015": "interval_field_overflow", + "2201E": "invalid_argument_for_logarithm", + "22014": "invalid_argument_for_ntile_function", + "22016": "invalid_argument_for_nth_value_function", + "2201F": "invalid_argument_for_power_function", + "2201G": "invalid_argument_for_width_bucket_function", + "22018": "invalid_character_value_for_cast", + "22007": "invalid_datetime_format", + "22019": "invalid_escape_character", + "2200D": "invalid_escape_octet", + "22025": "invalid_escape_sequence", + "22P06": "nonstandard_use_of_escape_character", + "22010": "invalid_indicator_parameter_value", + "22023": "invalid_parameter_value", + "2201B": "invalid_regular_expression", + "2201W": "invalid_row_count_in_limit_clause", + "2201X": "invalid_row_count_in_result_offset_clause", + "22009": "invalid_time_zone_displacement_value", + "2200C": "invalid_use_of_escape_character", + "2200G": "most_specific_type_mismatch", + "22004": "null_value_not_allowed", + "22002": "null_value_no_indicator_parameter", + "22003": "numeric_value_out_of_range", + "2200H": "sequence_generator_limit_exceeded", + "22026": "string_data_length_mismatch", + "22001": "string_data_right_truncation", + "22011": "substring_error", + "22027": "trim_error", + "22024": "unterminated_c_string", + "2200F": "zero_length_character_string", + "22P01": "floating_point_exception", + "22P02": "invalid_text_representation", + "22P03": "invalid_binary_representation", + "22P04": "bad_copy_file_format", + "22P05": "untranslatable_character", + "2200L": "not_an_xml_document", + "2200M": "invalid_xml_document", + "2200N": "invalid_xml_content", + "2200S": "invalid_xml_comment", + "2200T": "invalid_xml_processing_instruction", + // Class 23 - Integrity Constraint Violation + "23000": "integrity_constraint_violation", + "23001": "restrict_violation", + "23502": "not_null_violation", + "23503": "foreign_key_violation", + "23505": "unique_violation", + "23514": "check_violation", + "23P01": "exclusion_violation", + // Class 24 - Invalid Cursor State + "24000": "invalid_cursor_state", + // Class 25 - Invalid Transaction State + "25000": "invalid_transaction_state", + "25001": "active_sql_transaction", + "25002": "branch_transaction_already_active", + "25008": "held_cursor_requires_same_isolation_level", + "25003": "inappropriate_access_mode_for_branch_transaction", + "25004": "inappropriate_isolation_level_for_branch_transaction", + "25005": "no_active_sql_transaction_for_branch_transaction", + "25006": "read_only_sql_transaction", + "25007": "schema_and_data_statement_mixing_not_supported", + "25P01": "no_active_sql_transaction", + "25P02": "in_failed_sql_transaction", + // Class 26 - Invalid SQL Statement Name + "26000": "invalid_sql_statement_name", + // Class 27 - Triggered Data Change Violation + "27000": "triggered_data_change_violation", + // Class 28 - Invalid Authorization Specification + "28000": "invalid_authorization_specification", + "28P01": "invalid_password", + // Class 2B - Dependent Privilege Descriptors Still Exist + "2B000": "dependent_privilege_descriptors_still_exist", + "2BP01": "dependent_objects_still_exist", + // Class 2D - Invalid Transaction Termination + "2D000": "invalid_transaction_termination", + // Class 2F - SQL Routine Exception + "2F000": "sql_routine_exception", + "2F005": "function_executed_no_return_statement", + "2F002": "modifying_sql_data_not_permitted", + "2F003": "prohibited_sql_statement_attempted", + "2F004": "reading_sql_data_not_permitted", + // Class 34 - Invalid Cursor Name + "34000": "invalid_cursor_name", + // Class 38 - External Routine Exception + "38000": "external_routine_exception", + "38001": "containing_sql_not_permitted", + "38002": "modifying_sql_data_not_permitted", + "38003": "prohibited_sql_statement_attempted", + "38004": "reading_sql_data_not_permitted", + // Class 39 - External Routine Invocation Exception + "39000": "external_routine_invocation_exception", + "39001": "invalid_sqlstate_returned", + "39004": "null_value_not_allowed", + "39P01": "trigger_protocol_violated", + "39P02": "srf_protocol_violated", + // Class 3B - Savepoint Exception + "3B000": "savepoint_exception", + "3B001": "invalid_savepoint_specification", + // Class 3D - Invalid Catalog Name + "3D000": "invalid_catalog_name", + // Class 3F - Invalid Schema Name + "3F000": "invalid_schema_name", + // Class 40 - Transaction Rollback + "40000": "transaction_rollback", + "40002": "transaction_integrity_constraint_violation", + "40001": "serialization_failure", + "40003": "statement_completion_unknown", + "40P01": "deadlock_detected", + // Class 42 - Syntax Error or Access Rule Violation + "42000": "syntax_error_or_access_rule_violation", + "42601": "syntax_error", + "42501": "insufficient_privilege", + "42846": "cannot_coerce", + "42803": "grouping_error", + "42P20": "windowing_error", + "42P19": "invalid_recursion", + "42830": "invalid_foreign_key", + "42602": "invalid_name", + "42622": "name_too_long", + "42939": "reserved_name", + "42804": "datatype_mismatch", + "42P18": "indeterminate_datatype", + "42P21": "collation_mismatch", + "42P22": "indeterminate_collation", + "42809": "wrong_object_type", + "42703": "undefined_column", + "42883": "undefined_function", + "42P01": "undefined_table", + "42P02": "undefined_parameter", + "42704": "undefined_object", + "42701": "duplicate_column", + "42P03": "duplicate_cursor", + "42P04": "duplicate_database", + "42723": "duplicate_function", + "42P05": "duplicate_prepared_statement", + "42P06": "duplicate_schema", + "42P07": "duplicate_table", + "42712": "duplicate_alias", + "42710": "duplicate_object", + "42702": "ambiguous_column", + "42725": "ambiguous_function", + "42P08": "ambiguous_parameter", + "42P09": "ambiguous_alias", + "42P10": "invalid_column_reference", + "42611": "invalid_column_definition", + "42P11": "invalid_cursor_definition", + "42P12": "invalid_database_definition", + "42P13": "invalid_function_definition", + "42P14": "invalid_prepared_statement_definition", + "42P15": "invalid_schema_definition", + "42P16": "invalid_table_definition", + "42P17": "invalid_object_definition", + // Class 44 - WITH CHECK OPTION Violation + "44000": "with_check_option_violation", + // Class 53 - Insufficient Resources + "53000": "insufficient_resources", + "53100": "disk_full", + "53200": "out_of_memory", + "53300": "too_many_connections", + "53400": "configuration_limit_exceeded", + // Class 54 - Program Limit Exceeded + "54000": "program_limit_exceeded", + "54001": "statement_too_complex", + "54011": "too_many_columns", + "54023": "too_many_arguments", + // Class 55 - Object Not In Prerequisite State + "55000": "object_not_in_prerequisite_state", + "55006": "object_in_use", + "55P02": "cant_change_runtime_param", + "55P03": "lock_not_available", + // Class 57 - Operator Intervention + "57000": "operator_intervention", + "57014": "query_canceled", + "57P01": "admin_shutdown", + "57P02": "crash_shutdown", + "57P03": "cannot_connect_now", + "57P04": "database_dropped", + // Class 58 - System Error (errors external to PostgreSQL itself) + "58000": "system_error", + "58030": "io_error", + "58P01": "undefined_file", + "58P02": "duplicate_file", + // Class F0 - Configuration File Error + "F0000": "config_file_error", + "F0001": "lock_file_exists", + // Class HV - Foreign Data Wrapper Error (SQL/MED) + "HV000": "fdw_error", + "HV005": "fdw_column_name_not_found", + "HV002": "fdw_dynamic_parameter_value_needed", + "HV010": "fdw_function_sequence_error", + "HV021": "fdw_inconsistent_descriptor_information", + "HV024": "fdw_invalid_attribute_value", + "HV007": "fdw_invalid_column_name", + "HV008": "fdw_invalid_column_number", + "HV004": "fdw_invalid_data_type", + "HV006": "fdw_invalid_data_type_descriptors", + "HV091": "fdw_invalid_descriptor_field_identifier", + "HV00B": "fdw_invalid_handle", + "HV00C": "fdw_invalid_option_index", + "HV00D": "fdw_invalid_option_name", + "HV090": "fdw_invalid_string_length_or_buffer_length", + "HV00A": "fdw_invalid_string_format", + "HV009": "fdw_invalid_use_of_null_pointer", + "HV014": "fdw_too_many_handles", + "HV001": "fdw_out_of_memory", + "HV00P": "fdw_no_schemas", + "HV00J": "fdw_option_name_not_found", + "HV00K": "fdw_reply_handle", + "HV00Q": "fdw_schema_not_found", + "HV00R": "fdw_table_not_found", + "HV00L": "fdw_unable_to_create_execution", + "HV00M": "fdw_unable_to_create_reply", + "HV00N": "fdw_unable_to_establish_connection", + // Class P0 - PL/pgSQL Error + "P0000": "plpgsql_error", + "P0001": "raise_exception", + "P0002": "no_data_found", + "P0003": "too_many_rows", + // Class XX - Internal Error + "XX000": "internal_error", + "XX001": "data_corrupted", + "XX002": "index_corrupted", +} + +func parseError(r *readBuf) *Error { + err := new(Error) + for t := r.byte(); t != 0; t = r.byte() { + msg := r.string() + switch t { + case 'S': + err.Severity = msg + case 'C': + err.Code = ErrorCode(msg) + case 'M': + err.Message = msg + case 'D': + err.Detail = msg + case 'H': + err.Hint = msg + case 'P': + err.Position = msg + case 'p': + err.InternalPosition = msg + case 'q': + err.InternalQuery = msg + case 'W': + err.Where = msg + case 's': + err.Schema = msg + case 't': + err.Table = msg + case 'c': + err.Column = msg + case 'd': + err.DataTypeName = msg + case 'n': + err.Constraint = msg + case 'F': + err.File = msg + case 'L': + err.Line = msg + case 'R': + err.Routine = msg + } + } + return err +} + +// Fatal returns true if the Error Severity is fatal. +func (err *Error) Fatal() bool { + return err.Severity == Efatal +} + +// SQLState returns the SQLState of the error. +func (err *Error) SQLState() string { + return string(err.Code) +} + +// Get implements the legacy PGError interface. New code should use the fields +// of the Error struct directly. +func (err *Error) Get(k byte) (v string) { + switch k { + case 'S': + return err.Severity + case 'C': + return string(err.Code) + case 'M': + return err.Message + case 'D': + return err.Detail + case 'H': + return err.Hint + case 'P': + return err.Position + case 'p': + return err.InternalPosition + case 'q': + return err.InternalQuery + case 'W': + return err.Where + case 's': + return err.Schema + case 't': + return err.Table + case 'c': + return err.Column + case 'd': + return err.DataTypeName + case 'n': + return err.Constraint + case 'F': + return err.File + case 'L': + return err.Line + case 'R': + return err.Routine + } + return "" +} + +func (err *Error) Error() string { + return "pq: " + err.Message +} + +// PGError is an interface used by previous versions of pq. It is provided +// only to support legacy code. New code should use the Error type. +type PGError interface { + Error() string + Fatal() bool + Get(k byte) (v string) +} + +func errorf(s string, args ...interface{}) { + panic(fmt.Errorf("pq: %s", fmt.Sprintf(s, args...))) +} + +// TODO(ainar-g) Rename to errorf after removing panics. +func fmterrorf(s string, args ...interface{}) error { + return fmt.Errorf("pq: %s", fmt.Sprintf(s, args...)) +} + +func errRecoverNoErrBadConn(err *error) { + e := recover() + if e == nil { + // Do nothing + return + } + var ok bool + *err, ok = e.(error) + if !ok { + *err = fmt.Errorf("pq: unexpected error: %#v", e) + } +} + +func (cn *conn) errRecover(err *error) { + e := recover() + switch v := e.(type) { + case nil: + // Do nothing + case runtime.Error: + cn.err.set(driver.ErrBadConn) + panic(v) + case *Error: + if v.Fatal() { + *err = driver.ErrBadConn + } else { + *err = v + } + case *net.OpError: + cn.err.set(driver.ErrBadConn) + *err = v + case *safeRetryError: + cn.err.set(driver.ErrBadConn) + *err = driver.ErrBadConn + case error: + if v == io.EOF || v.Error() == "remote error: handshake failure" { + *err = driver.ErrBadConn + } else { + *err = v + } + + default: + cn.err.set(driver.ErrBadConn) + panic(fmt.Sprintf("unknown error: %#v", e)) + } + + // Any time we return ErrBadConn, we need to remember it since *Tx doesn't + // mark the connection bad in database/sql. + if *err == driver.ErrBadConn { + cn.err.set(driver.ErrBadConn) + } +} diff --git a/vendor/github.com/lib/pq/krb.go b/vendor/github.com/lib/pq/krb.go new file mode 100644 index 0000000..408ec01 --- /dev/null +++ b/vendor/github.com/lib/pq/krb.go @@ -0,0 +1,27 @@ +package pq + +// NewGSSFunc creates a GSS authentication provider, for use with +// RegisterGSSProvider. +type NewGSSFunc func() (GSS, error) + +var newGss NewGSSFunc + +// RegisterGSSProvider registers a GSS authentication provider. For example, if +// you need to use Kerberos to authenticate with your server, add this to your +// main package: +// +// import "github.com/lib/pq/auth/kerberos" +// +// func init() { +// pq.RegisterGSSProvider(func() (pq.GSS, error) { return kerberos.NewGSS() }) +// } +func RegisterGSSProvider(newGssArg NewGSSFunc) { + newGss = newGssArg +} + +// GSS provides GSSAPI authentication (e.g., Kerberos). +type GSS interface { + GetInitToken(host string, service string) ([]byte, error) + GetInitTokenFromSpn(spn string) ([]byte, error) + Continue(inToken []byte) (done bool, outToken []byte, err error) +} diff --git a/vendor/github.com/lib/pq/notice.go b/vendor/github.com/lib/pq/notice.go new file mode 100644 index 0000000..70ad122 --- /dev/null +++ b/vendor/github.com/lib/pq/notice.go @@ -0,0 +1,72 @@ +//go:build go1.10 +// +build go1.10 + +package pq + +import ( + "context" + "database/sql/driver" +) + +// NoticeHandler returns the notice handler on the given connection, if any. A +// runtime panic occurs if c is not a pq connection. This is rarely used +// directly, use ConnectorNoticeHandler and ConnectorWithNoticeHandler instead. +func NoticeHandler(c driver.Conn) func(*Error) { + return c.(*conn).noticeHandler +} + +// SetNoticeHandler sets the given notice handler on the given connection. A +// runtime panic occurs if c is not a pq connection. A nil handler may be used +// to unset it. This is rarely used directly, use ConnectorNoticeHandler and +// ConnectorWithNoticeHandler instead. +// +// Note: Notice handlers are executed synchronously by pq meaning commands +// won't continue to be processed until the handler returns. +func SetNoticeHandler(c driver.Conn, handler func(*Error)) { + c.(*conn).noticeHandler = handler +} + +// NoticeHandlerConnector wraps a regular connector and sets a notice handler +// on it. +type NoticeHandlerConnector struct { + driver.Connector + noticeHandler func(*Error) +} + +// Connect calls the underlying connector's connect method and then sets the +// notice handler. +func (n *NoticeHandlerConnector) Connect(ctx context.Context) (driver.Conn, error) { + c, err := n.Connector.Connect(ctx) + if err == nil { + SetNoticeHandler(c, n.noticeHandler) + } + return c, err +} + +// ConnectorNoticeHandler returns the currently set notice handler, if any. If +// the given connector is not a result of ConnectorWithNoticeHandler, nil is +// returned. +func ConnectorNoticeHandler(c driver.Connector) func(*Error) { + if c, ok := c.(*NoticeHandlerConnector); ok { + return c.noticeHandler + } + return nil +} + +// ConnectorWithNoticeHandler creates or sets the given handler for the given +// connector. If the given connector is a result of calling this function +// previously, it is simply set on the given connector and returned. Otherwise, +// this returns a new connector wrapping the given one and setting the notice +// handler. A nil notice handler may be used to unset it. +// +// The returned connector is intended to be used with database/sql.OpenDB. +// +// Note: Notice handlers are executed synchronously by pq meaning commands +// won't continue to be processed until the handler returns. +func ConnectorWithNoticeHandler(c driver.Connector, handler func(*Error)) *NoticeHandlerConnector { + if c, ok := c.(*NoticeHandlerConnector); ok { + c.noticeHandler = handler + return c + } + return &NoticeHandlerConnector{Connector: c, noticeHandler: handler} +} diff --git a/vendor/github.com/lib/pq/notify.go b/vendor/github.com/lib/pq/notify.go new file mode 100644 index 0000000..5c421fd --- /dev/null +++ b/vendor/github.com/lib/pq/notify.go @@ -0,0 +1,858 @@ +package pq + +// Package pq is a pure Go Postgres driver for the database/sql package. +// This module contains support for Postgres LISTEN/NOTIFY. + +import ( + "context" + "database/sql/driver" + "errors" + "fmt" + "sync" + "sync/atomic" + "time" +) + +// Notification represents a single notification from the database. +type Notification struct { + // Process ID (PID) of the notifying postgres backend. + BePid int + // Name of the channel the notification was sent on. + Channel string + // Payload, or the empty string if unspecified. + Extra string +} + +func recvNotification(r *readBuf) *Notification { + bePid := r.int32() + channel := r.string() + extra := r.string() + + return &Notification{bePid, channel, extra} +} + +// SetNotificationHandler sets the given notification handler on the given +// connection. A runtime panic occurs if c is not a pq connection. A nil handler +// may be used to unset it. +// +// Note: Notification handlers are executed synchronously by pq meaning commands +// won't continue to be processed until the handler returns. +func SetNotificationHandler(c driver.Conn, handler func(*Notification)) { + c.(*conn).notificationHandler = handler +} + +// NotificationHandlerConnector wraps a regular connector and sets a notification handler +// on it. +type NotificationHandlerConnector struct { + driver.Connector + notificationHandler func(*Notification) +} + +// Connect calls the underlying connector's connect method and then sets the +// notification handler. +func (n *NotificationHandlerConnector) Connect(ctx context.Context) (driver.Conn, error) { + c, err := n.Connector.Connect(ctx) + if err == nil { + SetNotificationHandler(c, n.notificationHandler) + } + return c, err +} + +// ConnectorNotificationHandler returns the currently set notification handler, if any. If +// the given connector is not a result of ConnectorWithNotificationHandler, nil is +// returned. +func ConnectorNotificationHandler(c driver.Connector) func(*Notification) { + if c, ok := c.(*NotificationHandlerConnector); ok { + return c.notificationHandler + } + return nil +} + +// ConnectorWithNotificationHandler creates or sets the given handler for the given +// connector. If the given connector is a result of calling this function +// previously, it is simply set on the given connector and returned. Otherwise, +// this returns a new connector wrapping the given one and setting the notification +// handler. A nil notification handler may be used to unset it. +// +// The returned connector is intended to be used with database/sql.OpenDB. +// +// Note: Notification handlers are executed synchronously by pq meaning commands +// won't continue to be processed until the handler returns. +func ConnectorWithNotificationHandler(c driver.Connector, handler func(*Notification)) *NotificationHandlerConnector { + if c, ok := c.(*NotificationHandlerConnector); ok { + c.notificationHandler = handler + return c + } + return &NotificationHandlerConnector{Connector: c, notificationHandler: handler} +} + +const ( + connStateIdle int32 = iota + connStateExpectResponse + connStateExpectReadyForQuery +) + +type message struct { + typ byte + err error +} + +var errListenerConnClosed = errors.New("pq: ListenerConn has been closed") + +// ListenerConn is a low-level interface for waiting for notifications. You +// should use Listener instead. +type ListenerConn struct { + // guards cn and err + connectionLock sync.Mutex + cn *conn + err error + + connState int32 + + // the sending goroutine will be holding this lock + senderLock sync.Mutex + + notificationChan chan<- *Notification + + replyChan chan message +} + +// NewListenerConn creates a new ListenerConn. Use NewListener instead. +func NewListenerConn(name string, notificationChan chan<- *Notification) (*ListenerConn, error) { + return newDialListenerConn(defaultDialer{}, name, notificationChan) +} + +func newDialListenerConn(d Dialer, name string, c chan<- *Notification) (*ListenerConn, error) { + cn, err := DialOpen(d, name) + if err != nil { + return nil, err + } + + l := &ListenerConn{ + cn: cn.(*conn), + notificationChan: c, + connState: connStateIdle, + replyChan: make(chan message, 2), + } + + go l.listenerConnMain() + + return l, nil +} + +// We can only allow one goroutine at a time to be running a query on the +// connection for various reasons, so the goroutine sending on the connection +// must be holding senderLock. +// +// Returns an error if an unrecoverable error has occurred and the ListenerConn +// should be abandoned. +func (l *ListenerConn) acquireSenderLock() error { + // we must acquire senderLock first to avoid deadlocks; see ExecSimpleQuery + l.senderLock.Lock() + + l.connectionLock.Lock() + err := l.err + l.connectionLock.Unlock() + if err != nil { + l.senderLock.Unlock() + return err + } + return nil +} + +func (l *ListenerConn) releaseSenderLock() { + l.senderLock.Unlock() +} + +// setState advances the protocol state to newState. Returns false if moving +// to that state from the current state is not allowed. +func (l *ListenerConn) setState(newState int32) bool { + var expectedState int32 + + switch newState { + case connStateIdle: + expectedState = connStateExpectReadyForQuery + case connStateExpectResponse: + expectedState = connStateIdle + case connStateExpectReadyForQuery: + expectedState = connStateExpectResponse + default: + panic(fmt.Sprintf("unexpected listenerConnState %d", newState)) + } + + return atomic.CompareAndSwapInt32(&l.connState, expectedState, newState) +} + +// Main logic is here: receive messages from the postgres backend, forward +// notifications and query replies and keep the internal state in sync with the +// protocol state. Returns when the connection has been lost, is about to go +// away or should be discarded because we couldn't agree on the state with the +// server backend. +func (l *ListenerConn) listenerConnLoop() (err error) { + defer errRecoverNoErrBadConn(&err) + + r := &readBuf{} + for { + t, err := l.cn.recvMessage(r) + if err != nil { + return err + } + + switch t { + case 'A': + // recvNotification copies all the data so we don't need to worry + // about the scratch buffer being overwritten. + l.notificationChan <- recvNotification(r) + + case 'T', 'D': + // only used by tests; ignore + + case 'E': + // We might receive an ErrorResponse even when not in a query; it + // is expected that the server will close the connection after + // that, but we should make sure that the error we display is the + // one from the stray ErrorResponse, not io.ErrUnexpectedEOF. + if !l.setState(connStateExpectReadyForQuery) { + return parseError(r) + } + l.replyChan <- message{t, parseError(r)} + + case 'C', 'I': + if !l.setState(connStateExpectReadyForQuery) { + // protocol out of sync + return fmt.Errorf("unexpected CommandComplete") + } + // ExecSimpleQuery doesn't need to know about this message + + case 'Z': + if !l.setState(connStateIdle) { + // protocol out of sync + return fmt.Errorf("unexpected ReadyForQuery") + } + l.replyChan <- message{t, nil} + + case 'S': + // ignore + case 'N': + if n := l.cn.noticeHandler; n != nil { + n(parseError(r)) + } + default: + return fmt.Errorf("unexpected message %q from server in listenerConnLoop", t) + } + } +} + +// This is the main routine for the goroutine receiving on the database +// connection. Most of the main logic is in listenerConnLoop. +func (l *ListenerConn) listenerConnMain() { + err := l.listenerConnLoop() + + // listenerConnLoop terminated; we're done, but we still have to clean up. + // Make sure nobody tries to start any new queries by making sure the err + // pointer is set. It is important that we do not overwrite its value; a + // connection could be closed by either this goroutine or one sending on + // the connection -- whoever closes the connection is assumed to have the + // more meaningful error message (as the other one will probably get + // net.errClosed), so that goroutine sets the error we expose while the + // other error is discarded. If the connection is lost while two + // goroutines are operating on the socket, it probably doesn't matter which + // error we expose so we don't try to do anything more complex. + l.connectionLock.Lock() + if l.err == nil { + l.err = err + } + l.cn.Close() + l.connectionLock.Unlock() + + // There might be a query in-flight; make sure nobody's waiting for a + // response to it, since there's not going to be one. + close(l.replyChan) + + // let the listener know we're done + close(l.notificationChan) + + // this ListenerConn is done +} + +// Listen sends a LISTEN query to the server. See ExecSimpleQuery. +func (l *ListenerConn) Listen(channel string) (bool, error) { + return l.ExecSimpleQuery("LISTEN " + QuoteIdentifier(channel)) +} + +// Unlisten sends an UNLISTEN query to the server. See ExecSimpleQuery. +func (l *ListenerConn) Unlisten(channel string) (bool, error) { + return l.ExecSimpleQuery("UNLISTEN " + QuoteIdentifier(channel)) +} + +// UnlistenAll sends an `UNLISTEN *` query to the server. See ExecSimpleQuery. +func (l *ListenerConn) UnlistenAll() (bool, error) { + return l.ExecSimpleQuery("UNLISTEN *") +} + +// Ping the remote server to make sure it's alive. Non-nil error means the +// connection has failed and should be abandoned. +func (l *ListenerConn) Ping() error { + sent, err := l.ExecSimpleQuery("") + if !sent { + return err + } + if err != nil { + // shouldn't happen + panic(err) + } + return nil +} + +// Attempt to send a query on the connection. Returns an error if sending the +// query failed, and the caller should initiate closure of this connection. +// The caller must be holding senderLock (see acquireSenderLock and +// releaseSenderLock). +func (l *ListenerConn) sendSimpleQuery(q string) (err error) { + defer errRecoverNoErrBadConn(&err) + + // must set connection state before sending the query + if !l.setState(connStateExpectResponse) { + panic("two queries running at the same time") + } + + // Can't use l.cn.writeBuf here because it uses the scratch buffer which + // might get overwritten by listenerConnLoop. + b := &writeBuf{ + buf: []byte("Q\x00\x00\x00\x00"), + pos: 1, + } + b.string(q) + l.cn.send(b) + + return nil +} + +// ExecSimpleQuery executes a "simple query" (i.e. one with no bindable +// parameters) on the connection. The possible return values are: +// 1) "executed" is true; the query was executed to completion on the +// database server. If the query failed, err will be set to the error +// returned by the database, otherwise err will be nil. +// 2) If "executed" is false, the query could not be executed on the remote +// server. err will be non-nil. +// +// After a call to ExecSimpleQuery has returned an executed=false value, the +// connection has either been closed or will be closed shortly thereafter, and +// all subsequently executed queries will return an error. +func (l *ListenerConn) ExecSimpleQuery(q string) (executed bool, err error) { + if err = l.acquireSenderLock(); err != nil { + return false, err + } + defer l.releaseSenderLock() + + err = l.sendSimpleQuery(q) + if err != nil { + // We can't know what state the protocol is in, so we need to abandon + // this connection. + l.connectionLock.Lock() + // Set the error pointer if it hasn't been set already; see + // listenerConnMain. + if l.err == nil { + l.err = err + } + l.connectionLock.Unlock() + l.cn.c.Close() + return false, err + } + + // now we just wait for a reply.. + for { + m, ok := <-l.replyChan + if !ok { + // We lost the connection to server, don't bother waiting for a + // a response. err should have been set already. + l.connectionLock.Lock() + err := l.err + l.connectionLock.Unlock() + return false, err + } + switch m.typ { + case 'Z': + // sanity check + if m.err != nil { + panic("m.err != nil") + } + // done; err might or might not be set + return true, err + + case 'E': + // sanity check + if m.err == nil { + panic("m.err == nil") + } + // server responded with an error; ReadyForQuery to follow + err = m.err + + default: + return false, fmt.Errorf("unknown response for simple query: %q", m.typ) + } + } +} + +// Close closes the connection. +func (l *ListenerConn) Close() error { + l.connectionLock.Lock() + if l.err != nil { + l.connectionLock.Unlock() + return errListenerConnClosed + } + l.err = errListenerConnClosed + l.connectionLock.Unlock() + // We can't send anything on the connection without holding senderLock. + // Simply close the net.Conn to wake up everyone operating on it. + return l.cn.c.Close() +} + +// Err returns the reason the connection was closed. It is not safe to call +// this function until l.Notify has been closed. +func (l *ListenerConn) Err() error { + return l.err +} + +var errListenerClosed = errors.New("pq: Listener has been closed") + +// ErrChannelAlreadyOpen is returned from Listen when a channel is already +// open. +var ErrChannelAlreadyOpen = errors.New("pq: channel is already open") + +// ErrChannelNotOpen is returned from Unlisten when a channel is not open. +var ErrChannelNotOpen = errors.New("pq: channel is not open") + +// ListenerEventType is an enumeration of listener event types. +type ListenerEventType int + +const ( + // ListenerEventConnected is emitted only when the database connection + // has been initially initialized. The err argument of the callback + // will always be nil. + ListenerEventConnected ListenerEventType = iota + + // ListenerEventDisconnected is emitted after a database connection has + // been lost, either because of an error or because Close has been + // called. The err argument will be set to the reason the database + // connection was lost. + ListenerEventDisconnected + + // ListenerEventReconnected is emitted after a database connection has + // been re-established after connection loss. The err argument of the + // callback will always be nil. After this event has been emitted, a + // nil pq.Notification is sent on the Listener.Notify channel. + ListenerEventReconnected + + // ListenerEventConnectionAttemptFailed is emitted after a connection + // to the database was attempted, but failed. The err argument will be + // set to an error describing why the connection attempt did not + // succeed. + ListenerEventConnectionAttemptFailed +) + +// EventCallbackType is the event callback type. See also ListenerEventType +// constants' documentation. +type EventCallbackType func(event ListenerEventType, err error) + +// Listener provides an interface for listening to notifications from a +// PostgreSQL database. For general usage information, see section +// "Notifications". +// +// Listener can safely be used from concurrently running goroutines. +type Listener struct { + // Channel for receiving notifications from the database. In some cases a + // nil value will be sent. See section "Notifications" above. + Notify chan *Notification + + name string + minReconnectInterval time.Duration + maxReconnectInterval time.Duration + dialer Dialer + eventCallback EventCallbackType + + lock sync.Mutex + isClosed bool + reconnectCond *sync.Cond + cn *ListenerConn + connNotificationChan <-chan *Notification + channels map[string]struct{} +} + +// NewListener creates a new database connection dedicated to LISTEN / NOTIFY. +// +// name should be set to a connection string to be used to establish the +// database connection (see section "Connection String Parameters" above). +// +// minReconnectInterval controls the duration to wait before trying to +// re-establish the database connection after connection loss. After each +// consecutive failure this interval is doubled, until maxReconnectInterval is +// reached. Successfully completing the connection establishment procedure +// resets the interval back to minReconnectInterval. +// +// The last parameter eventCallback can be set to a function which will be +// called by the Listener when the state of the underlying database connection +// changes. This callback will be called by the goroutine which dispatches the +// notifications over the Notify channel, so you should try to avoid doing +// potentially time-consuming operations from the callback. +func NewListener(name string, + minReconnectInterval time.Duration, + maxReconnectInterval time.Duration, + eventCallback EventCallbackType) *Listener { + return NewDialListener(defaultDialer{}, name, minReconnectInterval, maxReconnectInterval, eventCallback) +} + +// NewDialListener is like NewListener but it takes a Dialer. +func NewDialListener(d Dialer, + name string, + minReconnectInterval time.Duration, + maxReconnectInterval time.Duration, + eventCallback EventCallbackType) *Listener { + + l := &Listener{ + name: name, + minReconnectInterval: minReconnectInterval, + maxReconnectInterval: maxReconnectInterval, + dialer: d, + eventCallback: eventCallback, + + channels: make(map[string]struct{}), + + Notify: make(chan *Notification, 32), + } + l.reconnectCond = sync.NewCond(&l.lock) + + go l.listenerMain() + + return l +} + +// NotificationChannel returns the notification channel for this listener. +// This is the same channel as Notify, and will not be recreated during the +// life time of the Listener. +func (l *Listener) NotificationChannel() <-chan *Notification { + return l.Notify +} + +// Listen starts listening for notifications on a channel. Calls to this +// function will block until an acknowledgement has been received from the +// server. Note that Listener automatically re-establishes the connection +// after connection loss, so this function may block indefinitely if the +// connection can not be re-established. +// +// Listen will only fail in three conditions: +// 1) The channel is already open. The returned error will be +// ErrChannelAlreadyOpen. +// 2) The query was executed on the remote server, but PostgreSQL returned an +// error message in response to the query. The returned error will be a +// pq.Error containing the information the server supplied. +// 3) Close is called on the Listener before the request could be completed. +// +// The channel name is case-sensitive. +func (l *Listener) Listen(channel string) error { + l.lock.Lock() + defer l.lock.Unlock() + + if l.isClosed { + return errListenerClosed + } + + // The server allows you to issue a LISTEN on a channel which is already + // open, but it seems useful to be able to detect this case to spot for + // mistakes in application logic. If the application genuinely does't + // care, it can check the exported error and ignore it. + _, exists := l.channels[channel] + if exists { + return ErrChannelAlreadyOpen + } + + if l.cn != nil { + // If gotResponse is true but error is set, the query was executed on + // the remote server, but resulted in an error. This should be + // relatively rare, so it's fine if we just pass the error to our + // caller. However, if gotResponse is false, we could not complete the + // query on the remote server and our underlying connection is about + // to go away, so we only add relname to l.channels, and wait for + // resync() to take care of the rest. + gotResponse, err := l.cn.Listen(channel) + if gotResponse && err != nil { + return err + } + } + + l.channels[channel] = struct{}{} + for l.cn == nil { + l.reconnectCond.Wait() + // we let go of the mutex for a while + if l.isClosed { + return errListenerClosed + } + } + + return nil +} + +// Unlisten removes a channel from the Listener's channel list. Returns +// ErrChannelNotOpen if the Listener is not listening on the specified channel. +// Returns immediately with no error if there is no connection. Note that you +// might still get notifications for this channel even after Unlisten has +// returned. +// +// The channel name is case-sensitive. +func (l *Listener) Unlisten(channel string) error { + l.lock.Lock() + defer l.lock.Unlock() + + if l.isClosed { + return errListenerClosed + } + + // Similarly to LISTEN, this is not an error in Postgres, but it seems + // useful to distinguish from the normal conditions. + _, exists := l.channels[channel] + if !exists { + return ErrChannelNotOpen + } + + if l.cn != nil { + // Similarly to Listen (see comment in that function), the caller + // should only be bothered with an error if it came from the backend as + // a response to our query. + gotResponse, err := l.cn.Unlisten(channel) + if gotResponse && err != nil { + return err + } + } + + // Don't bother waiting for resync if there's no connection. + delete(l.channels, channel) + return nil +} + +// UnlistenAll removes all channels from the Listener's channel list. Returns +// immediately with no error if there is no connection. Note that you might +// still get notifications for any of the deleted channels even after +// UnlistenAll has returned. +func (l *Listener) UnlistenAll() error { + l.lock.Lock() + defer l.lock.Unlock() + + if l.isClosed { + return errListenerClosed + } + + if l.cn != nil { + // Similarly to Listen (see comment in that function), the caller + // should only be bothered with an error if it came from the backend as + // a response to our query. + gotResponse, err := l.cn.UnlistenAll() + if gotResponse && err != nil { + return err + } + } + + // Don't bother waiting for resync if there's no connection. + l.channels = make(map[string]struct{}) + return nil +} + +// Ping the remote server to make sure it's alive. Non-nil return value means +// that there is no active connection. +func (l *Listener) Ping() error { + l.lock.Lock() + defer l.lock.Unlock() + + if l.isClosed { + return errListenerClosed + } + if l.cn == nil { + return errors.New("no connection") + } + + return l.cn.Ping() +} + +// Clean up after losing the server connection. Returns l.cn.Err(), which +// should have the reason the connection was lost. +func (l *Listener) disconnectCleanup() error { + l.lock.Lock() + defer l.lock.Unlock() + + // sanity check; can't look at Err() until the channel has been closed + select { + case _, ok := <-l.connNotificationChan: + if ok { + panic("connNotificationChan not closed") + } + default: + panic("connNotificationChan not closed") + } + + err := l.cn.Err() + l.cn.Close() + l.cn = nil + return err +} + +// Synchronize the list of channels we want to be listening on with the server +// after the connection has been established. +func (l *Listener) resync(cn *ListenerConn, notificationChan <-chan *Notification) error { + doneChan := make(chan error) + go func(notificationChan <-chan *Notification) { + for channel := range l.channels { + // If we got a response, return that error to our caller as it's + // going to be more descriptive than cn.Err(). + gotResponse, err := cn.Listen(channel) + if gotResponse && err != nil { + doneChan <- err + return + } + + // If we couldn't reach the server, wait for notificationChan to + // close and then return the error message from the connection, as + // per ListenerConn's interface. + if err != nil { + for range notificationChan { + } + doneChan <- cn.Err() + return + } + } + doneChan <- nil + }(notificationChan) + + // Ignore notifications while synchronization is going on to avoid + // deadlocks. We have to send a nil notification over Notify anyway as + // we can't possibly know which notifications (if any) were lost while + // the connection was down, so there's no reason to try and process + // these messages at all. + for { + select { + case _, ok := <-notificationChan: + if !ok { + notificationChan = nil + } + + case err := <-doneChan: + return err + } + } +} + +// caller should NOT be holding l.lock +func (l *Listener) closed() bool { + l.lock.Lock() + defer l.lock.Unlock() + + return l.isClosed +} + +func (l *Listener) connect() error { + notificationChan := make(chan *Notification, 32) + cn, err := newDialListenerConn(l.dialer, l.name, notificationChan) + if err != nil { + return err + } + + l.lock.Lock() + defer l.lock.Unlock() + + err = l.resync(cn, notificationChan) + if err != nil { + cn.Close() + return err + } + + l.cn = cn + l.connNotificationChan = notificationChan + l.reconnectCond.Broadcast() + + return nil +} + +// Close disconnects the Listener from the database and shuts it down. +// Subsequent calls to its methods will return an error. Close returns an +// error if the connection has already been closed. +func (l *Listener) Close() error { + l.lock.Lock() + defer l.lock.Unlock() + + if l.isClosed { + return errListenerClosed + } + + if l.cn != nil { + l.cn.Close() + } + l.isClosed = true + + // Unblock calls to Listen() + l.reconnectCond.Broadcast() + + return nil +} + +func (l *Listener) emitEvent(event ListenerEventType, err error) { + if l.eventCallback != nil { + l.eventCallback(event, err) + } +} + +// Main logic here: maintain a connection to the server when possible, wait +// for notifications and emit events. +func (l *Listener) listenerConnLoop() { + var nextReconnect time.Time + + reconnectInterval := l.minReconnectInterval + for { + for { + err := l.connect() + if err == nil { + break + } + + if l.closed() { + return + } + l.emitEvent(ListenerEventConnectionAttemptFailed, err) + + time.Sleep(reconnectInterval) + reconnectInterval *= 2 + if reconnectInterval > l.maxReconnectInterval { + reconnectInterval = l.maxReconnectInterval + } + } + + if nextReconnect.IsZero() { + l.emitEvent(ListenerEventConnected, nil) + } else { + l.emitEvent(ListenerEventReconnected, nil) + l.Notify <- nil + } + + reconnectInterval = l.minReconnectInterval + nextReconnect = time.Now().Add(reconnectInterval) + + for { + notification, ok := <-l.connNotificationChan + if !ok { + // lost connection, loop again + break + } + l.Notify <- notification + } + + err := l.disconnectCleanup() + if l.closed() { + return + } + l.emitEvent(ListenerEventDisconnected, err) + + time.Sleep(time.Until(nextReconnect)) + } +} + +func (l *Listener) listenerMain() { + l.listenerConnLoop() + close(l.Notify) +} diff --git a/vendor/github.com/lib/pq/oid/doc.go b/vendor/github.com/lib/pq/oid/doc.go new file mode 100644 index 0000000..caaede2 --- /dev/null +++ b/vendor/github.com/lib/pq/oid/doc.go @@ -0,0 +1,6 @@ +// Package oid contains OID constants +// as defined by the Postgres server. +package oid + +// Oid is a Postgres Object ID. +type Oid uint32 diff --git a/vendor/github.com/lib/pq/oid/types.go b/vendor/github.com/lib/pq/oid/types.go new file mode 100644 index 0000000..ecc84c2 --- /dev/null +++ b/vendor/github.com/lib/pq/oid/types.go @@ -0,0 +1,343 @@ +// Code generated by gen.go. DO NOT EDIT. + +package oid + +const ( + T_bool Oid = 16 + T_bytea Oid = 17 + T_char Oid = 18 + T_name Oid = 19 + T_int8 Oid = 20 + T_int2 Oid = 21 + T_int2vector Oid = 22 + T_int4 Oid = 23 + T_regproc Oid = 24 + T_text Oid = 25 + T_oid Oid = 26 + T_tid Oid = 27 + T_xid Oid = 28 + T_cid Oid = 29 + T_oidvector Oid = 30 + T_pg_ddl_command Oid = 32 + T_pg_type Oid = 71 + T_pg_attribute Oid = 75 + T_pg_proc Oid = 81 + T_pg_class Oid = 83 + T_json Oid = 114 + T_xml Oid = 142 + T__xml Oid = 143 + T_pg_node_tree Oid = 194 + T__json Oid = 199 + T_smgr Oid = 210 + T_index_am_handler Oid = 325 + T_point Oid = 600 + T_lseg Oid = 601 + T_path Oid = 602 + T_box Oid = 603 + T_polygon Oid = 604 + T_line Oid = 628 + T__line Oid = 629 + T_cidr Oid = 650 + T__cidr Oid = 651 + T_float4 Oid = 700 + T_float8 Oid = 701 + T_abstime Oid = 702 + T_reltime Oid = 703 + T_tinterval Oid = 704 + T_unknown Oid = 705 + T_circle Oid = 718 + T__circle Oid = 719 + T_money Oid = 790 + T__money Oid = 791 + T_macaddr Oid = 829 + T_inet Oid = 869 + T__bool Oid = 1000 + T__bytea Oid = 1001 + T__char Oid = 1002 + T__name Oid = 1003 + T__int2 Oid = 1005 + T__int2vector Oid = 1006 + T__int4 Oid = 1007 + T__regproc Oid = 1008 + T__text Oid = 1009 + T__tid Oid = 1010 + T__xid Oid = 1011 + T__cid Oid = 1012 + T__oidvector Oid = 1013 + T__bpchar Oid = 1014 + T__varchar Oid = 1015 + T__int8 Oid = 1016 + T__point Oid = 1017 + T__lseg Oid = 1018 + T__path Oid = 1019 + T__box Oid = 1020 + T__float4 Oid = 1021 + T__float8 Oid = 1022 + T__abstime Oid = 1023 + T__reltime Oid = 1024 + T__tinterval Oid = 1025 + T__polygon Oid = 1027 + T__oid Oid = 1028 + T_aclitem Oid = 1033 + T__aclitem Oid = 1034 + T__macaddr Oid = 1040 + T__inet Oid = 1041 + T_bpchar Oid = 1042 + T_varchar Oid = 1043 + T_date Oid = 1082 + T_time Oid = 1083 + T_timestamp Oid = 1114 + T__timestamp Oid = 1115 + T__date Oid = 1182 + T__time Oid = 1183 + T_timestamptz Oid = 1184 + T__timestamptz Oid = 1185 + T_interval Oid = 1186 + T__interval Oid = 1187 + T__numeric Oid = 1231 + T_pg_database Oid = 1248 + T__cstring Oid = 1263 + T_timetz Oid = 1266 + T__timetz Oid = 1270 + T_bit Oid = 1560 + T__bit Oid = 1561 + T_varbit Oid = 1562 + T__varbit Oid = 1563 + T_numeric Oid = 1700 + T_refcursor Oid = 1790 + T__refcursor Oid = 2201 + T_regprocedure Oid = 2202 + T_regoper Oid = 2203 + T_regoperator Oid = 2204 + T_regclass Oid = 2205 + T_regtype Oid = 2206 + T__regprocedure Oid = 2207 + T__regoper Oid = 2208 + T__regoperator Oid = 2209 + T__regclass Oid = 2210 + T__regtype Oid = 2211 + T_record Oid = 2249 + T_cstring Oid = 2275 + T_any Oid = 2276 + T_anyarray Oid = 2277 + T_void Oid = 2278 + T_trigger Oid = 2279 + T_language_handler Oid = 2280 + T_internal Oid = 2281 + T_opaque Oid = 2282 + T_anyelement Oid = 2283 + T__record Oid = 2287 + T_anynonarray Oid = 2776 + T_pg_authid Oid = 2842 + T_pg_auth_members Oid = 2843 + T__txid_snapshot Oid = 2949 + T_uuid Oid = 2950 + T__uuid Oid = 2951 + T_txid_snapshot Oid = 2970 + T_fdw_handler Oid = 3115 + T_pg_lsn Oid = 3220 + T__pg_lsn Oid = 3221 + T_tsm_handler Oid = 3310 + T_anyenum Oid = 3500 + T_tsvector Oid = 3614 + T_tsquery Oid = 3615 + T_gtsvector Oid = 3642 + T__tsvector Oid = 3643 + T__gtsvector Oid = 3644 + T__tsquery Oid = 3645 + T_regconfig Oid = 3734 + T__regconfig Oid = 3735 + T_regdictionary Oid = 3769 + T__regdictionary Oid = 3770 + T_jsonb Oid = 3802 + T__jsonb Oid = 3807 + T_anyrange Oid = 3831 + T_event_trigger Oid = 3838 + T_int4range Oid = 3904 + T__int4range Oid = 3905 + T_numrange Oid = 3906 + T__numrange Oid = 3907 + T_tsrange Oid = 3908 + T__tsrange Oid = 3909 + T_tstzrange Oid = 3910 + T__tstzrange Oid = 3911 + T_daterange Oid = 3912 + T__daterange Oid = 3913 + T_int8range Oid = 3926 + T__int8range Oid = 3927 + T_pg_shseclabel Oid = 4066 + T_regnamespace Oid = 4089 + T__regnamespace Oid = 4090 + T_regrole Oid = 4096 + T__regrole Oid = 4097 +) + +var TypeName = map[Oid]string{ + T_bool: "BOOL", + T_bytea: "BYTEA", + T_char: "CHAR", + T_name: "NAME", + T_int8: "INT8", + T_int2: "INT2", + T_int2vector: "INT2VECTOR", + T_int4: "INT4", + T_regproc: "REGPROC", + T_text: "TEXT", + T_oid: "OID", + T_tid: "TID", + T_xid: "XID", + T_cid: "CID", + T_oidvector: "OIDVECTOR", + T_pg_ddl_command: "PG_DDL_COMMAND", + T_pg_type: "PG_TYPE", + T_pg_attribute: "PG_ATTRIBUTE", + T_pg_proc: "PG_PROC", + T_pg_class: "PG_CLASS", + T_json: "JSON", + T_xml: "XML", + T__xml: "_XML", + T_pg_node_tree: "PG_NODE_TREE", + T__json: "_JSON", + T_smgr: "SMGR", + T_index_am_handler: "INDEX_AM_HANDLER", + T_point: "POINT", + T_lseg: "LSEG", + T_path: "PATH", + T_box: "BOX", + T_polygon: "POLYGON", + T_line: "LINE", + T__line: "_LINE", + T_cidr: "CIDR", + T__cidr: "_CIDR", + T_float4: "FLOAT4", + T_float8: "FLOAT8", + T_abstime: "ABSTIME", + T_reltime: "RELTIME", + T_tinterval: "TINTERVAL", + T_unknown: "UNKNOWN", + T_circle: "CIRCLE", + T__circle: "_CIRCLE", + T_money: "MONEY", + T__money: "_MONEY", + T_macaddr: "MACADDR", + T_inet: "INET", + T__bool: "_BOOL", + T__bytea: "_BYTEA", + T__char: "_CHAR", + T__name: "_NAME", + T__int2: "_INT2", + T__int2vector: "_INT2VECTOR", + T__int4: "_INT4", + T__regproc: "_REGPROC", + T__text: "_TEXT", + T__tid: "_TID", + T__xid: "_XID", + T__cid: "_CID", + T__oidvector: "_OIDVECTOR", + T__bpchar: "_BPCHAR", + T__varchar: "_VARCHAR", + T__int8: "_INT8", + T__point: "_POINT", + T__lseg: "_LSEG", + T__path: "_PATH", + T__box: "_BOX", + T__float4: "_FLOAT4", + T__float8: "_FLOAT8", + T__abstime: "_ABSTIME", + T__reltime: "_RELTIME", + T__tinterval: "_TINTERVAL", + T__polygon: "_POLYGON", + T__oid: "_OID", + T_aclitem: "ACLITEM", + T__aclitem: "_ACLITEM", + T__macaddr: "_MACADDR", + T__inet: "_INET", + T_bpchar: "BPCHAR", + T_varchar: "VARCHAR", + T_date: "DATE", + T_time: "TIME", + T_timestamp: "TIMESTAMP", + T__timestamp: "_TIMESTAMP", + T__date: "_DATE", + T__time: "_TIME", + T_timestamptz: "TIMESTAMPTZ", + T__timestamptz: "_TIMESTAMPTZ", + T_interval: "INTERVAL", + T__interval: "_INTERVAL", + T__numeric: "_NUMERIC", + T_pg_database: "PG_DATABASE", + T__cstring: "_CSTRING", + T_timetz: "TIMETZ", + T__timetz: "_TIMETZ", + T_bit: "BIT", + T__bit: "_BIT", + T_varbit: "VARBIT", + T__varbit: "_VARBIT", + T_numeric: "NUMERIC", + T_refcursor: "REFCURSOR", + T__refcursor: "_REFCURSOR", + T_regprocedure: "REGPROCEDURE", + T_regoper: "REGOPER", + T_regoperator: "REGOPERATOR", + T_regclass: "REGCLASS", + T_regtype: "REGTYPE", + T__regprocedure: "_REGPROCEDURE", + T__regoper: "_REGOPER", + T__regoperator: "_REGOPERATOR", + T__regclass: "_REGCLASS", + T__regtype: "_REGTYPE", + T_record: "RECORD", + T_cstring: "CSTRING", + T_any: "ANY", + T_anyarray: "ANYARRAY", + T_void: "VOID", + T_trigger: "TRIGGER", + T_language_handler: "LANGUAGE_HANDLER", + T_internal: "INTERNAL", + T_opaque: "OPAQUE", + T_anyelement: "ANYELEMENT", + T__record: "_RECORD", + T_anynonarray: "ANYNONARRAY", + T_pg_authid: "PG_AUTHID", + T_pg_auth_members: "PG_AUTH_MEMBERS", + T__txid_snapshot: "_TXID_SNAPSHOT", + T_uuid: "UUID", + T__uuid: "_UUID", + T_txid_snapshot: "TXID_SNAPSHOT", + T_fdw_handler: "FDW_HANDLER", + T_pg_lsn: "PG_LSN", + T__pg_lsn: "_PG_LSN", + T_tsm_handler: "TSM_HANDLER", + T_anyenum: "ANYENUM", + T_tsvector: "TSVECTOR", + T_tsquery: "TSQUERY", + T_gtsvector: "GTSVECTOR", + T__tsvector: "_TSVECTOR", + T__gtsvector: "_GTSVECTOR", + T__tsquery: "_TSQUERY", + T_regconfig: "REGCONFIG", + T__regconfig: "_REGCONFIG", + T_regdictionary: "REGDICTIONARY", + T__regdictionary: "_REGDICTIONARY", + T_jsonb: "JSONB", + T__jsonb: "_JSONB", + T_anyrange: "ANYRANGE", + T_event_trigger: "EVENT_TRIGGER", + T_int4range: "INT4RANGE", + T__int4range: "_INT4RANGE", + T_numrange: "NUMRANGE", + T__numrange: "_NUMRANGE", + T_tsrange: "TSRANGE", + T__tsrange: "_TSRANGE", + T_tstzrange: "TSTZRANGE", + T__tstzrange: "_TSTZRANGE", + T_daterange: "DATERANGE", + T__daterange: "_DATERANGE", + T_int8range: "INT8RANGE", + T__int8range: "_INT8RANGE", + T_pg_shseclabel: "PG_SHSECLABEL", + T_regnamespace: "REGNAMESPACE", + T__regnamespace: "_REGNAMESPACE", + T_regrole: "REGROLE", + T__regrole: "_REGROLE", +} diff --git a/vendor/github.com/lib/pq/rows.go b/vendor/github.com/lib/pq/rows.go new file mode 100644 index 0000000..c6aa5b9 --- /dev/null +++ b/vendor/github.com/lib/pq/rows.go @@ -0,0 +1,93 @@ +package pq + +import ( + "math" + "reflect" + "time" + + "github.com/lib/pq/oid" +) + +const headerSize = 4 + +type fieldDesc struct { + // The object ID of the data type. + OID oid.Oid + // The data type size (see pg_type.typlen). + // Note that negative values denote variable-width types. + Len int + // The type modifier (see pg_attribute.atttypmod). + // The meaning of the modifier is type-specific. + Mod int +} + +func (fd fieldDesc) Type() reflect.Type { + switch fd.OID { + case oid.T_int8: + return reflect.TypeOf(int64(0)) + case oid.T_int4: + return reflect.TypeOf(int32(0)) + case oid.T_int2: + return reflect.TypeOf(int16(0)) + case oid.T_varchar, oid.T_text: + return reflect.TypeOf("") + case oid.T_bool: + return reflect.TypeOf(false) + case oid.T_date, oid.T_time, oid.T_timetz, oid.T_timestamp, oid.T_timestamptz: + return reflect.TypeOf(time.Time{}) + case oid.T_bytea: + return reflect.TypeOf([]byte(nil)) + default: + return reflect.TypeOf(new(interface{})).Elem() + } +} + +func (fd fieldDesc) Name() string { + return oid.TypeName[fd.OID] +} + +func (fd fieldDesc) Length() (length int64, ok bool) { + switch fd.OID { + case oid.T_text, oid.T_bytea: + return math.MaxInt64, true + case oid.T_varchar, oid.T_bpchar: + return int64(fd.Mod - headerSize), true + default: + return 0, false + } +} + +func (fd fieldDesc) PrecisionScale() (precision, scale int64, ok bool) { + switch fd.OID { + case oid.T_numeric, oid.T__numeric: + mod := fd.Mod - headerSize + precision = int64((mod >> 16) & 0xffff) + scale = int64(mod & 0xffff) + return precision, scale, true + default: + return 0, 0, false + } +} + +// ColumnTypeScanType returns the value type that can be used to scan types into. +func (rs *rows) ColumnTypeScanType(index int) reflect.Type { + return rs.colTyps[index].Type() +} + +// ColumnTypeDatabaseTypeName return the database system type name. +func (rs *rows) ColumnTypeDatabaseTypeName(index int) string { + return rs.colTyps[index].Name() +} + +// ColumnTypeLength returns the length of the column type if the column is a +// variable length type. If the column is not a variable length type ok +// should return false. +func (rs *rows) ColumnTypeLength(index int) (length int64, ok bool) { + return rs.colTyps[index].Length() +} + +// ColumnTypePrecisionScale should return the precision and scale for decimal +// types. If not applicable, ok should be false. +func (rs *rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) { + return rs.colTyps[index].PrecisionScale() +} diff --git a/vendor/github.com/lib/pq/scram/scram.go b/vendor/github.com/lib/pq/scram/scram.go new file mode 100644 index 0000000..477216b --- /dev/null +++ b/vendor/github.com/lib/pq/scram/scram.go @@ -0,0 +1,264 @@ +// Copyright (c) 2014 - Gustavo Niemeyer <gustavo@niemeyer.net> +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Package scram implements a SCRAM-{SHA-1,etc} client per RFC5802. +// +// http://tools.ietf.org/html/rfc5802 +// +package scram + +import ( + "bytes" + "crypto/hmac" + "crypto/rand" + "encoding/base64" + "fmt" + "hash" + "strconv" + "strings" +) + +// Client implements a SCRAM-* client (SCRAM-SHA-1, SCRAM-SHA-256, etc). +// +// A Client may be used within a SASL conversation with logic resembling: +// +// var in []byte +// var client = scram.NewClient(sha1.New, user, pass) +// for client.Step(in) { +// out := client.Out() +// // send out to server +// in := serverOut +// } +// if client.Err() != nil { +// // auth failed +// } +// +type Client struct { + newHash func() hash.Hash + + user string + pass string + step int + out bytes.Buffer + err error + + clientNonce []byte + serverNonce []byte + saltedPass []byte + authMsg bytes.Buffer +} + +// NewClient returns a new SCRAM-* client with the provided hash algorithm. +// +// For SCRAM-SHA-256, for example, use: +// +// client := scram.NewClient(sha256.New, user, pass) +// +func NewClient(newHash func() hash.Hash, user, pass string) *Client { + c := &Client{ + newHash: newHash, + user: user, + pass: pass, + } + c.out.Grow(256) + c.authMsg.Grow(256) + return c +} + +// Out returns the data to be sent to the server in the current step. +func (c *Client) Out() []byte { + if c.out.Len() == 0 { + return nil + } + return c.out.Bytes() +} + +// Err returns the error that occurred, or nil if there were no errors. +func (c *Client) Err() error { + return c.err +} + +// SetNonce sets the client nonce to the provided value. +// If not set, the nonce is generated automatically out of crypto/rand on the first step. +func (c *Client) SetNonce(nonce []byte) { + c.clientNonce = nonce +} + +var escaper = strings.NewReplacer("=", "=3D", ",", "=2C") + +// Step processes the incoming data from the server and makes the +// next round of data for the server available via Client.Out. +// Step returns false if there are no errors and more data is +// still expected. +func (c *Client) Step(in []byte) bool { + c.out.Reset() + if c.step > 2 || c.err != nil { + return false + } + c.step++ + switch c.step { + case 1: + c.err = c.step1(in) + case 2: + c.err = c.step2(in) + case 3: + c.err = c.step3(in) + } + return c.step > 2 || c.err != nil +} + +func (c *Client) step1(in []byte) error { + if len(c.clientNonce) == 0 { + const nonceLen = 16 + buf := make([]byte, nonceLen+b64.EncodedLen(nonceLen)) + if _, err := rand.Read(buf[:nonceLen]); err != nil { + return fmt.Errorf("cannot read random SCRAM-SHA-256 nonce from operating system: %v", err) + } + c.clientNonce = buf[nonceLen:] + b64.Encode(c.clientNonce, buf[:nonceLen]) + } + c.authMsg.WriteString("n=") + escaper.WriteString(&c.authMsg, c.user) + c.authMsg.WriteString(",r=") + c.authMsg.Write(c.clientNonce) + + c.out.WriteString("n,,") + c.out.Write(c.authMsg.Bytes()) + return nil +} + +var b64 = base64.StdEncoding + +func (c *Client) step2(in []byte) error { + c.authMsg.WriteByte(',') + c.authMsg.Write(in) + + fields := bytes.Split(in, []byte(",")) + if len(fields) != 3 { + return fmt.Errorf("expected 3 fields in first SCRAM-SHA-256 server message, got %d: %q", len(fields), in) + } + if !bytes.HasPrefix(fields[0], []byte("r=")) || len(fields[0]) < 2 { + return fmt.Errorf("server sent an invalid SCRAM-SHA-256 nonce: %q", fields[0]) + } + if !bytes.HasPrefix(fields[1], []byte("s=")) || len(fields[1]) < 6 { + return fmt.Errorf("server sent an invalid SCRAM-SHA-256 salt: %q", fields[1]) + } + if !bytes.HasPrefix(fields[2], []byte("i=")) || len(fields[2]) < 6 { + return fmt.Errorf("server sent an invalid SCRAM-SHA-256 iteration count: %q", fields[2]) + } + + c.serverNonce = fields[0][2:] + if !bytes.HasPrefix(c.serverNonce, c.clientNonce) { + return fmt.Errorf("server SCRAM-SHA-256 nonce is not prefixed by client nonce: got %q, want %q+\"...\"", c.serverNonce, c.clientNonce) + } + + salt := make([]byte, b64.DecodedLen(len(fields[1][2:]))) + n, err := b64.Decode(salt, fields[1][2:]) + if err != nil { + return fmt.Errorf("cannot decode SCRAM-SHA-256 salt sent by server: %q", fields[1]) + } + salt = salt[:n] + iterCount, err := strconv.Atoi(string(fields[2][2:])) + if err != nil { + return fmt.Errorf("server sent an invalid SCRAM-SHA-256 iteration count: %q", fields[2]) + } + c.saltPassword(salt, iterCount) + + c.authMsg.WriteString(",c=biws,r=") + c.authMsg.Write(c.serverNonce) + + c.out.WriteString("c=biws,r=") + c.out.Write(c.serverNonce) + c.out.WriteString(",p=") + c.out.Write(c.clientProof()) + return nil +} + +func (c *Client) step3(in []byte) error { + var isv, ise bool + var fields = bytes.Split(in, []byte(",")) + if len(fields) == 1 { + isv = bytes.HasPrefix(fields[0], []byte("v=")) + ise = bytes.HasPrefix(fields[0], []byte("e=")) + } + if ise { + return fmt.Errorf("SCRAM-SHA-256 authentication error: %s", fields[0][2:]) + } else if !isv { + return fmt.Errorf("unsupported SCRAM-SHA-256 final message from server: %q", in) + } + if !bytes.Equal(c.serverSignature(), fields[0][2:]) { + return fmt.Errorf("cannot authenticate SCRAM-SHA-256 server signature: %q", fields[0][2:]) + } + return nil +} + +func (c *Client) saltPassword(salt []byte, iterCount int) { + mac := hmac.New(c.newHash, []byte(c.pass)) + mac.Write(salt) + mac.Write([]byte{0, 0, 0, 1}) + ui := mac.Sum(nil) + hi := make([]byte, len(ui)) + copy(hi, ui) + for i := 1; i < iterCount; i++ { + mac.Reset() + mac.Write(ui) + mac.Sum(ui[:0]) + for j, b := range ui { + hi[j] ^= b + } + } + c.saltedPass = hi +} + +func (c *Client) clientProof() []byte { + mac := hmac.New(c.newHash, c.saltedPass) + mac.Write([]byte("Client Key")) + clientKey := mac.Sum(nil) + hash := c.newHash() + hash.Write(clientKey) + storedKey := hash.Sum(nil) + mac = hmac.New(c.newHash, storedKey) + mac.Write(c.authMsg.Bytes()) + clientProof := mac.Sum(nil) + for i, b := range clientKey { + clientProof[i] ^= b + } + clientProof64 := make([]byte, b64.EncodedLen(len(clientProof))) + b64.Encode(clientProof64, clientProof) + return clientProof64 +} + +func (c *Client) serverSignature() []byte { + mac := hmac.New(c.newHash, c.saltedPass) + mac.Write([]byte("Server Key")) + serverKey := mac.Sum(nil) + + mac = hmac.New(c.newHash, serverKey) + mac.Write(c.authMsg.Bytes()) + serverSignature := mac.Sum(nil) + + encoded := make([]byte, b64.EncodedLen(len(serverSignature))) + b64.Encode(encoded, serverSignature) + return encoded +} diff --git a/vendor/github.com/lib/pq/ssl.go b/vendor/github.com/lib/pq/ssl.go new file mode 100644 index 0000000..36b61ba --- /dev/null +++ b/vendor/github.com/lib/pq/ssl.go @@ -0,0 +1,204 @@ +package pq + +import ( + "crypto/tls" + "crypto/x509" + "io/ioutil" + "net" + "os" + "os/user" + "path/filepath" + "strings" +) + +// ssl generates a function to upgrade a net.Conn based on the "sslmode" and +// related settings. The function is nil when no upgrade should take place. +func ssl(o values) (func(net.Conn) (net.Conn, error), error) { + verifyCaOnly := false + tlsConf := tls.Config{} + switch mode := o["sslmode"]; mode { + // "require" is the default. + case "", "require": + // We must skip TLS's own verification since it requires full + // verification since Go 1.3. + tlsConf.InsecureSkipVerify = true + + // From http://www.postgresql.org/docs/current/static/libpq-ssl.html: + // + // Note: For backwards compatibility with earlier versions of + // PostgreSQL, if a root CA file exists, the behavior of + // sslmode=require will be the same as that of verify-ca, meaning the + // server certificate is validated against the CA. Relying on this + // behavior is discouraged, and applications that need certificate + // validation should always use verify-ca or verify-full. + if sslrootcert, ok := o["sslrootcert"]; ok { + if _, err := os.Stat(sslrootcert); err == nil { + verifyCaOnly = true + } else { + delete(o, "sslrootcert") + } + } + case "verify-ca": + // We must skip TLS's own verification since it requires full + // verification since Go 1.3. + tlsConf.InsecureSkipVerify = true + verifyCaOnly = true + case "verify-full": + tlsConf.ServerName = o["host"] + case "disable": + return nil, nil + default: + return nil, fmterrorf(`unsupported sslmode %q; only "require" (default), "verify-full", "verify-ca", and "disable" supported`, mode) + } + + // Set Server Name Indication (SNI), if enabled by connection parameters. + // By default SNI is on, any value which is not starting with "1" disables + // SNI -- that is the same check vanilla libpq uses. + if sslsni := o["sslsni"]; sslsni == "" || strings.HasPrefix(sslsni, "1") { + // RFC 6066 asks to not set SNI if the host is a literal IP address (IPv4 + // or IPv6). This check is coded already crypto.tls.hostnameInSNI, so + // just always set ServerName here and let crypto/tls do the filtering. + tlsConf.ServerName = o["host"] + } + + err := sslClientCertificates(&tlsConf, o) + if err != nil { + return nil, err + } + err = sslCertificateAuthority(&tlsConf, o) + if err != nil { + return nil, err + } + + // Accept renegotiation requests initiated by the backend. + // + // Renegotiation was deprecated then removed from PostgreSQL 9.5, but + // the default configuration of older versions has it enabled. Redshift + // also initiates renegotiations and cannot be reconfigured. + tlsConf.Renegotiation = tls.RenegotiateFreelyAsClient + + return func(conn net.Conn) (net.Conn, error) { + client := tls.Client(conn, &tlsConf) + if verifyCaOnly { + err := sslVerifyCertificateAuthority(client, &tlsConf) + if err != nil { + return nil, err + } + } + return client, nil + }, nil +} + +// sslClientCertificates adds the certificate specified in the "sslcert" and +// "sslkey" settings, or if they aren't set, from the .postgresql directory +// in the user's home directory. The configured files must exist and have +// the correct permissions. +func sslClientCertificates(tlsConf *tls.Config, o values) error { + sslinline := o["sslinline"] + if sslinline == "true" { + cert, err := tls.X509KeyPair([]byte(o["sslcert"]), []byte(o["sslkey"])) + if err != nil { + return err + } + tlsConf.Certificates = []tls.Certificate{cert} + return nil + } + + // user.Current() might fail when cross-compiling. We have to ignore the + // error and continue without home directory defaults, since we wouldn't + // know from where to load them. + user, _ := user.Current() + + // In libpq, the client certificate is only loaded if the setting is not blank. + // + // https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1036-L1037 + sslcert := o["sslcert"] + if len(sslcert) == 0 && user != nil { + sslcert = filepath.Join(user.HomeDir, ".postgresql", "postgresql.crt") + } + // https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1045 + if len(sslcert) == 0 { + return nil + } + // https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1050:L1054 + if _, err := os.Stat(sslcert); os.IsNotExist(err) { + return nil + } else if err != nil { + return err + } + + // In libpq, the ssl key is only loaded if the setting is not blank. + // + // https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1123-L1222 + sslkey := o["sslkey"] + if len(sslkey) == 0 && user != nil { + sslkey = filepath.Join(user.HomeDir, ".postgresql", "postgresql.key") + } + + if len(sslkey) > 0 { + if err := sslKeyPermissions(sslkey); err != nil { + return err + } + } + + cert, err := tls.LoadX509KeyPair(sslcert, sslkey) + if err != nil { + return err + } + + tlsConf.Certificates = []tls.Certificate{cert} + return nil +} + +// sslCertificateAuthority adds the RootCA specified in the "sslrootcert" setting. +func sslCertificateAuthority(tlsConf *tls.Config, o values) error { + // In libpq, the root certificate is only loaded if the setting is not blank. + // + // https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L950-L951 + if sslrootcert := o["sslrootcert"]; len(sslrootcert) > 0 { + tlsConf.RootCAs = x509.NewCertPool() + + sslinline := o["sslinline"] + + var cert []byte + if sslinline == "true" { + cert = []byte(sslrootcert) + } else { + var err error + cert, err = ioutil.ReadFile(sslrootcert) + if err != nil { + return err + } + } + + if !tlsConf.RootCAs.AppendCertsFromPEM(cert) { + return fmterrorf("couldn't parse pem in sslrootcert") + } + } + + return nil +} + +// sslVerifyCertificateAuthority carries out a TLS handshake to the server and +// verifies the presented certificate against the CA, i.e. the one specified in +// sslrootcert or the system CA if sslrootcert was not specified. +func sslVerifyCertificateAuthority(client *tls.Conn, tlsConf *tls.Config) error { + err := client.Handshake() + if err != nil { + return err + } + certs := client.ConnectionState().PeerCertificates + opts := x509.VerifyOptions{ + DNSName: client.ConnectionState().ServerName, + Intermediates: x509.NewCertPool(), + Roots: tlsConf.RootCAs, + } + for i, cert := range certs { + if i == 0 { + continue + } + opts.Intermediates.AddCert(cert) + } + _, err = certs[0].Verify(opts) + return err +} diff --git a/vendor/github.com/lib/pq/ssl_permissions.go b/vendor/github.com/lib/pq/ssl_permissions.go new file mode 100644 index 0000000..d587f10 --- /dev/null +++ b/vendor/github.com/lib/pq/ssl_permissions.go @@ -0,0 +1,93 @@ +//go:build !windows +// +build !windows + +package pq + +import ( + "errors" + "os" + "syscall" +) + +const ( + rootUserID = uint32(0) + + // The maximum permissions that a private key file owned by a regular user + // is allowed to have. This translates to u=rw. + maxUserOwnedKeyPermissions os.FileMode = 0600 + + // The maximum permissions that a private key file owned by root is allowed + // to have. This translates to u=rw,g=r. + maxRootOwnedKeyPermissions os.FileMode = 0640 +) + +var ( + errSSLKeyHasUnacceptableUserPermissions = errors.New("permissions for files not owned by root should be u=rw (0600) or less") + errSSLKeyHasUnacceptableRootPermissions = errors.New("permissions for root owned files should be u=rw,g=r (0640) or less") +) + +// sslKeyPermissions checks the permissions on user-supplied ssl key files. +// The key file should have very little access. +// +// libpq does not check key file permissions on Windows. +func sslKeyPermissions(sslkey string) error { + info, err := os.Stat(sslkey) + if err != nil { + return err + } + + err = hasCorrectPermissions(info) + + // return ErrSSLKeyHasWorldPermissions for backwards compatability with + // existing code. + if err == errSSLKeyHasUnacceptableUserPermissions || err == errSSLKeyHasUnacceptableRootPermissions { + err = ErrSSLKeyHasWorldPermissions + } + return err +} + +// hasCorrectPermissions checks the file info (and the unix-specific stat_t +// output) to verify that the permissions on the file are correct. +// +// If the file is owned by the same user the process is running as, +// the file should only have 0600 (u=rw). If the file is owned by root, +// and the group matches the group that the process is running in, the +// permissions cannot be more than 0640 (u=rw,g=r). The file should +// never have world permissions. +// +// Returns an error when the permission check fails. +func hasCorrectPermissions(info os.FileInfo) error { + // if file's permission matches 0600, allow access. + userPermissionMask := (os.FileMode(0777) ^ maxUserOwnedKeyPermissions) + + // regardless of if we're running as root or not, 0600 is acceptable, + // so we return if we match the regular user permission mask. + if info.Mode().Perm()&userPermissionMask == 0 { + return nil + } + + // We need to pull the Unix file information to get the file's owner. + // If we can't access it, there's some sort of operating system level error + // and we should fail rather than attempting to use faulty information. + sysInfo := info.Sys() + if sysInfo == nil { + return ErrSSLKeyUnknownOwnership + } + + unixStat, ok := sysInfo.(*syscall.Stat_t) + if !ok { + return ErrSSLKeyUnknownOwnership + } + + // if the file is owned by root, we allow 0640 (u=rw,g=r) to match what + // Postgres does. + if unixStat.Uid == rootUserID { + rootPermissionMask := (os.FileMode(0777) ^ maxRootOwnedKeyPermissions) + if info.Mode().Perm()&rootPermissionMask != 0 { + return errSSLKeyHasUnacceptableRootPermissions + } + return nil + } + + return errSSLKeyHasUnacceptableUserPermissions +} diff --git a/vendor/github.com/lib/pq/ssl_windows.go b/vendor/github.com/lib/pq/ssl_windows.go new file mode 100644 index 0000000..73663c8 --- /dev/null +++ b/vendor/github.com/lib/pq/ssl_windows.go @@ -0,0 +1,10 @@ +//go:build windows +// +build windows + +package pq + +// sslKeyPermissions checks the permissions on user-supplied ssl key files. +// The key file should have very little access. +// +// libpq does not check key file permissions on Windows. +func sslKeyPermissions(string) error { return nil } diff --git a/vendor/github.com/lib/pq/url.go b/vendor/github.com/lib/pq/url.go new file mode 100644 index 0000000..aec6e95 --- /dev/null +++ b/vendor/github.com/lib/pq/url.go @@ -0,0 +1,76 @@ +package pq + +import ( + "fmt" + "net" + nurl "net/url" + "sort" + "strings" +) + +// ParseURL no longer needs to be used by clients of this library since supplying a URL as a +// connection string to sql.Open() is now supported: +// +// sql.Open("postgres", "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full") +// +// It remains exported here for backwards-compatibility. +// +// ParseURL converts a url to a connection string for driver.Open. +// Example: +// +// "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full" +// +// converts to: +// +// "user=bob password=secret host=1.2.3.4 port=5432 dbname=mydb sslmode=verify-full" +// +// A minimal example: +// +// "postgres://" +// +// This will be blank, causing driver.Open to use all of the defaults +func ParseURL(url string) (string, error) { + u, err := nurl.Parse(url) + if err != nil { + return "", err + } + + if u.Scheme != "postgres" && u.Scheme != "postgresql" { + return "", fmt.Errorf("invalid connection protocol: %s", u.Scheme) + } + + var kvs []string + escaper := strings.NewReplacer(`'`, `\'`, `\`, `\\`) + accrue := func(k, v string) { + if v != "" { + kvs = append(kvs, k+"='"+escaper.Replace(v)+"'") + } + } + + if u.User != nil { + v := u.User.Username() + accrue("user", v) + + v, _ = u.User.Password() + accrue("password", v) + } + + if host, port, err := net.SplitHostPort(u.Host); err != nil { + accrue("host", u.Host) + } else { + accrue("host", host) + accrue("port", port) + } + + if u.Path != "" { + accrue("dbname", u.Path[1:]) + } + + q := u.Query() + for k := range q { + accrue(k, q.Get(k)) + } + + sort.Strings(kvs) // Makes testing easier (not a performance concern) + return strings.Join(kvs, " "), nil +} diff --git a/vendor/github.com/lib/pq/user_other.go b/vendor/github.com/lib/pq/user_other.go new file mode 100644 index 0000000..3dae8f5 --- /dev/null +++ b/vendor/github.com/lib/pq/user_other.go @@ -0,0 +1,10 @@ +// Package pq is a pure Go Postgres driver for the database/sql package. + +//go:build js || android || hurd || zos +// +build js android hurd zos + +package pq + +func userCurrent() (string, error) { + return "", ErrCouldNotDetectUsername +} diff --git a/vendor/github.com/lib/pq/user_posix.go b/vendor/github.com/lib/pq/user_posix.go new file mode 100644 index 0000000..5f2d439 --- /dev/null +++ b/vendor/github.com/lib/pq/user_posix.go @@ -0,0 +1,25 @@ +// Package pq is a pure Go Postgres driver for the database/sql package. + +//go:build aix || darwin || dragonfly || freebsd || (linux && !android) || nacl || netbsd || openbsd || plan9 || solaris || rumprun || illumos +// +build aix darwin dragonfly freebsd linux,!android nacl netbsd openbsd plan9 solaris rumprun illumos + +package pq + +import ( + "os" + "os/user" +) + +func userCurrent() (string, error) { + u, err := user.Current() + if err == nil { + return u.Username, nil + } + + name := os.Getenv("USER") + if name != "" { + return name, nil + } + + return "", ErrCouldNotDetectUsername +} diff --git a/vendor/github.com/lib/pq/user_windows.go b/vendor/github.com/lib/pq/user_windows.go new file mode 100644 index 0000000..2b69126 --- /dev/null +++ b/vendor/github.com/lib/pq/user_windows.go @@ -0,0 +1,27 @@ +// Package pq is a pure Go Postgres driver for the database/sql package. +package pq + +import ( + "path/filepath" + "syscall" +) + +// Perform Windows user name lookup identically to libpq. +// +// The PostgreSQL code makes use of the legacy Win32 function +// GetUserName, and that function has not been imported into stock Go. +// GetUserNameEx is available though, the difference being that a +// wider range of names are available. To get the output to be the +// same as GetUserName, only the base (or last) component of the +// result is returned. +func userCurrent() (string, error) { + pw_name := make([]uint16, 128) + pwname_size := uint32(len(pw_name)) - 1 + err := syscall.GetUserNameEx(syscall.NameSamCompatible, &pw_name[0], &pwname_size) + if err != nil { + return "", ErrCouldNotDetectUsername + } + s := syscall.UTF16ToString(pw_name) + u := filepath.Base(s) + return u, nil +} diff --git a/vendor/github.com/lib/pq/uuid.go b/vendor/github.com/lib/pq/uuid.go new file mode 100644 index 0000000..9a1b9e0 --- /dev/null +++ b/vendor/github.com/lib/pq/uuid.go @@ -0,0 +1,23 @@ +package pq + +import ( + "encoding/hex" + "fmt" +) + +// decodeUUIDBinary interprets the binary format of a uuid, returning it in text format. +func decodeUUIDBinary(src []byte) ([]byte, error) { + if len(src) != 16 { + return nil, fmt.Errorf("pq: unable to decode uuid; bad length: %d", len(src)) + } + + dst := make([]byte, 36) + dst[8], dst[13], dst[18], dst[23] = '-', '-', '-', '-' + hex.Encode(dst[0:], src[0:4]) + hex.Encode(dst[9:], src[4:6]) + hex.Encode(dst[14:], src[6:8]) + hex.Encode(dst[19:], src[8:10]) + hex.Encode(dst[24:], src[10:16]) + + return dst, nil +} diff --git a/vendor/github.com/playwright-community/playwright-go/.gitattributes b/vendor/github.com/playwright-community/playwright-go/.gitattributes deleted file mode 100644 index c976050..0000000 --- a/vendor/github.com/playwright-community/playwright-go/.gitattributes +++ /dev/null @@ -1,3 +0,0 @@ -# text files must be lf for golden file tests to work -* text=auto eol=lf - diff --git a/vendor/github.com/playwright-community/playwright-go/.gitignore b/vendor/github.com/playwright-community/playwright-go/.gitignore deleted file mode 100644 index 83e2355..0000000 --- a/vendor/github.com/playwright-community/playwright-go/.gitignore +++ /dev/null @@ -1,34 +0,0 @@ -# Created by https://www.toptal.com/developers/gitignore/api/go -# Edit at https://www.toptal.com/developers/gitignore?templates=go - -### Go ### -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -# vendor/ - -### Go Patch ### -/vendor/ -/Godeps/ - -# End of https://www.toptal.com/developers/gitignore/api/go -covprofile -.idea/ -.DS_Store - -api.json -_site/ -.jekyll-cache/ - -.vscode/settings.json
\ No newline at end of file diff --git a/vendor/github.com/playwright-community/playwright-go/.gitmodules b/vendor/github.com/playwright-community/playwright-go/.gitmodules deleted file mode 100644 index 9ab899d..0000000 --- a/vendor/github.com/playwright-community/playwright-go/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "playwright"] - path = playwright - url = https://github.com/microsoft/playwright diff --git a/vendor/github.com/playwright-community/playwright-go/.golangci.yaml b/vendor/github.com/playwright-community/playwright-go/.golangci.yaml deleted file mode 100644 index 1557a3f..0000000 --- a/vendor/github.com/playwright-community/playwright-go/.golangci.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -linters: - enable-all: false - disable-all: false - enable: - - gofumpt
\ No newline at end of file diff --git a/vendor/github.com/playwright-community/playwright-go/.nojekyll b/vendor/github.com/playwright-community/playwright-go/.nojekyll deleted file mode 100644 index e69de29..0000000 --- a/vendor/github.com/playwright-community/playwright-go/.nojekyll +++ /dev/null diff --git a/vendor/github.com/playwright-community/playwright-go/404.html b/vendor/github.com/playwright-community/playwright-go/404.html deleted file mode 100644 index 086a5c9..0000000 --- a/vendor/github.com/playwright-community/playwright-go/404.html +++ /dev/null @@ -1,25 +0,0 @@ ---- -permalink: /404.html -layout: default ---- - -<style type="text/css" media="screen"> - .container { - margin: 10px auto; - max-width: 600px; - text-align: center; - } - h1 { - margin: 30px 0; - font-size: 4em; - line-height: 1; - letter-spacing: -1px; - } -</style> - -<div class="container"> - <h1>404</h1> - - <p><strong>Page not found :(</strong></p> - <p>The requested page could not be found.</p> -</div> diff --git a/vendor/github.com/playwright-community/playwright-go/CONTRIBUTING.md b/vendor/github.com/playwright-community/playwright-go/CONTRIBUTING.md deleted file mode 100644 index 3b11995..0000000 --- a/vendor/github.com/playwright-community/playwright-go/CONTRIBUTING.md +++ /dev/null @@ -1,39 +0,0 @@ -# Contributing - -## Code style -The Go code is linted with [golangci-lint](https://golangci-lint.run/) and formatted with [gofumpt](https://github.com/mvdan/gofumpt). Please configure your editor to run the tools while developing and make sure to run the tools before committing any code. - -## Tests - -### Test coverage - -For every Pull Request on GitHub and on the main branch the coverage data will get sent over to [Coveralls](https://coveralls.io/github/playwright-community/playwright-go), this is helpful for finding functions that aren't covered by tests. - -### Running tests - -You can use the `BROWSER` environment variable to use a different browser than Chromium for the tests and use the `HEADLESS` environment variable which is useful for debugging. - -``` -BROWSER=chromium HEADLESS=1 go test -v --race ./... -``` - -### Roll - -1. Find out to which upstream version you want to roll, and change the value of `playwrightCliVersion` in the **run.go** to the new version. -1. Download current version of Playwright driver `go run scripts/install-browsers/main.go` -1. Apply patch `bash scripts/apply-patch.sh` -1. Fix merge conflicts if any, otherwise ignore this step. Once you are happy you can commit the changes `cd playwright; git commit -am "apply patch" && cd ..` -1. Regenerate a new patch `bash scripts/update-patch.sh` -1. Generate go code `go generate ./...` - -To adapt to the new version of Playwright's protocol and feature updates, you may need to modify the patch. Refer to the following steps: - -1. Apply patch `bash scripts/apply-patch.sh` -1. `cd playwright` -1. Revert the patch`git reset HEAD~1` -1. Modify the files under `docs/src/api`, etc. as needed. Available references: - - Protocol `packages/protocol/src/protocol.yml` - - [Playwright python](https://github.com/microsoft/playwright-python) -1. Commit the changes `git commit -am "apply patch"` -1. Regenerate a new patch `bash scripts/update-patch.sh` -1. Generate go code `go generate ./...`. diff --git a/vendor/github.com/playwright-community/playwright-go/Dockerfile.example b/vendor/github.com/playwright-community/playwright-go/Dockerfile.example deleted file mode 100644 index 3077cf3..0000000 --- a/vendor/github.com/playwright-community/playwright-go/Dockerfile.example +++ /dev/null @@ -1,25 +0,0 @@ -# Stage 1: Modules caching -FROM golang:1.22 as modules -COPY go.mod go.sum /modules/ -WORKDIR /modules -RUN go mod download - -# Stage 2: Build -FROM golang:1.22 as builder -COPY --from=modules /go/pkg /go/pkg -COPY . /workdir -WORKDIR /workdir -# Install playwright cli with right version for later use -RUN PWGO_VER=$(grep -oE "playwright-go v\S+" /workdir/go.mod | sed 's/playwright-go //g') \ - && go install github.com/playwright-community/playwright-go/cmd/playwright@${PWGO_VER} -# Build your app -RUN GOOS=linux GOARCH=amd64 go build -o /bin/myapp - -# Stage 3: Final -FROM ubuntu:noble -COPY --from=builder /go/bin/playwright /bin/myapp / -RUN apt-get update && apt-get install -y ca-certificates tzdata \ - # Install dependencies and all browsers (or specify one) - && /playwright install --with-deps \ - && rm -rf /var/lib/apt/lists/* -CMD ["/myapp"]
\ No newline at end of file diff --git a/vendor/github.com/playwright-community/playwright-go/LICENSE b/vendor/github.com/playwright-community/playwright-go/LICENSE deleted file mode 100644 index d4f29b3..0000000 --- a/vendor/github.com/playwright-community/playwright-go/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 Max Schmitt - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/github.com/playwright-community/playwright-go/README.md b/vendor/github.com/playwright-community/playwright-go/README.md deleted file mode 100644 index a9e3dd7..0000000 --- a/vendor/github.com/playwright-community/playwright-go/README.md +++ /dev/null @@ -1,148 +0,0 @@ -# 🎭 [Playwright](https://github.com/microsoft/playwright#readme) for <img src="https://user-images.githubusercontent.com/17984549/91302719-343a1d80-e7a7-11ea-8d6a-9448ef598420.png" height="35" /> - -## Looking for maintainers and see [here](https://github.com/playwright-community/playwright-go/issues/122). Thanks! - -[](https://pkg.go.dev/github.com/playwright-community/playwright-go) -[](http://opensource.org/licenses/MIT) -[](https://goreportcard.com/report/github.com/playwright-community/playwright-go)  -[](https://aka.ms/playwright-slack) [](https://coveralls.io/github/playwright-community/playwright-go?branch=main) <!-- GEN:chromium-version-badge -->[](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> <!-- GEN:webkit-version-badge -->[](https://webkit.org/)<!-- GEN:stop --> - -[API reference](https://playwright.dev/docs/api/class-playwright) | [Example recipes](https://github.com/playwright-community/playwright-go/tree/main/examples) - -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**. - -| | Linux | macOS | Windows | -| :--- | :---: | :---: | :---: | -| Chromium <!-- GEN:chromium-version -->136.0.7103.25<!-- GEN:stop --> | ✅ | ✅ | ✅ | -| WebKit <!-- GEN:webkit-version -->18.4<!-- GEN:stop --> | ✅ | ✅ | ✅ | -| Firefox <!-- GEN:firefox-version -->137.0<!-- GEN:stop --> | ✅ | ✅ | ✅ | - -Headless execution is supported for all the browsers on all platforms. - -## Installation - -```txt -go get -u github.com/playwright-community/playwright-go -``` - -Install the browsers and OS dependencies: - -```bash -go run github.com/playwright-community/playwright-go/cmd/playwright@latest install --with-deps -# Or -go install github.com/playwright-community/playwright-go/cmd/playwright@latest -playwright install --with-deps -``` - -Alternatively you can do it inside your program via which downloads the driver and browsers: - -```go -err := playwright.Install() -``` - -## Capabilities - -Playwright is built to automate the broad and growing set of web browser capabilities used by Single Page Apps and Progressive Web Apps. - -* Scenarios that span multiple page, domains and iframes -* Auto-wait for elements to be ready before executing actions (like click, fill) -* Intercept network activity for stubbing and mocking network requests -* Emulate mobile devices, geolocation, permissions -* Support for web components via shadow-piercing selectors -* Native input events for mouse and keyboard -* Upload and download files - -## Example - -The following example crawls the current top voted items from [Hacker News](https://news.ycombinator.com). - -```go - -package main - -import ( - "fmt" - "log" - - "github.com/playwright-community/playwright-go" -) - -func main() { - pw, err := playwright.Run() - if err != nil { - log.Fatalf("could not start playwright: %v", err) - } - browser, err := pw.Chromium.Launch() - if err != nil { - log.Fatalf("could not launch browser: %v", err) - } - page, err := browser.NewPage() - if err != nil { - log.Fatalf("could not create page: %v", err) - } - if _, err = page.Goto("https://news.ycombinator.com"); err != nil { - log.Fatalf("could not goto: %v", err) - } - entries, err := page.Locator(".athing").All() - if err != nil { - log.Fatalf("could not get entries: %v", err) - } - for i, entry := range entries { - title, err := entry.Locator("td.title > span > a").TextContent() - if err != nil { - log.Fatalf("could not get text content: %v", err) - } - fmt.Printf("%d: %s\n", i+1, title) - } - if err = browser.Close(); err != nil { - log.Fatalf("could not close browser: %v", err) - } - if err = pw.Stop(); err != nil { - log.Fatalf("could not stop Playwright: %v", err) - } -} -``` - -## Docker -Refer to the [Dockerfile.example](./Dockerfile.example) to build your own docker image. - -## More examples - -* Refer to [helper_test.go](./tests/helper_test.go) for End-To-End testing -* [Downloading files](./examples/download/main.go) -* [End-To-End testing a website](./examples/end-to-end-testing/main.go) -* [Executing JavaScript in the browser](./examples/javascript/main.go) -* [Emulate mobile and geolocation](./examples/mobile-and-geolocation/main.go) -* [Parallel scraping using a WaitGroup](./examples/parallel-scraping/main.go) -* [Rendering a PDF of a website](./examples/pdf/main.go) -* [Scraping HackerNews](./examples/scraping/main.go) -* [Take a screenshot](./examples/screenshot/main.go) -* [Record a video](./examples/video/main.go) -* [Monitor network activity](./examples/network-monitoring/main.go) - -## How does it work? - -Playwright is a Node.js library which uses: - -* Chrome DevTools Protocol to communicate with Chromium -* Patched Firefox to communicate with Firefox -* Patched WebKit to communicate with WebKit - -These patches are based on the original sources of the browsers and don't modify the browser behaviour so the browsers are basically the same (see [here](https://github.com/microsoft/playwright/tree/main/browser_patches)) as you see them in the wild. The support for different programming languages is based on exposing a RPC server in the Node.js land which can be used to allow other languages to use Playwright without implementing all the custom logic: - -* [Playwright for Python](https://github.com/microsoft/playwright-python) -* [Playwright for .NET](https://github.com/microsoft/playwright-sharp) -* [Playwright for Java](https://github.com/microsoft/playwright-java) -* [Playwright for Go](https://github.com/playwright-community/playwright-go) - -The bridge between Node.js and the other languages is basically a Node.js runtime combined with Playwright which gets shipped for each of these languages (around 50MB) and then communicates over stdio to send the relevant commands. This will also download the pre-compiled browsers. - -## Is Playwright for Go ready? - -We are ready for your feedback, but we are still covering Playwright Go with the tests. - -## Resources - -* [Playwright for Go Documentation](https://pkg.go.dev/github.com/playwright-community/playwright-go) -* [Playwright Documentation](https://playwright.dev/docs/api/class-playwright) -* [Example recipes](https://github.com/playwright-community/playwright-go/tree/main/examples) diff --git a/vendor/github.com/playwright-community/playwright-go/_config.yml b/vendor/github.com/playwright-community/playwright-go/_config.yml deleted file mode 100644 index 15ec3b2..0000000 --- a/vendor/github.com/playwright-community/playwright-go/_config.yml +++ /dev/null @@ -1,21 +0,0 @@ -title: Playwright for Go -email: max@schmitt.mx -description: >- # this means to ignore newlines until "baseurl:" - Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API. - Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast. -baseurl: "/playwright-go" -url: "https://playwright-community.github.io/" -twitter_username: maxibanki -github_username: playwright-community -remote_theme: pages-themes/cayman@v0.2.0 -plugins: - - jekyll-remote-theme - - jekyll-optional-front-matter - - jekyll-readme-index -exclude: - - playwright/ -defaults: - - scope: - path: "" # an empty string here means all files in the project - values: - layout: "default" diff --git a/vendor/github.com/playwright-community/playwright-go/apiresponse_assertions.go b/vendor/github.com/playwright-community/playwright-go/apiresponse_assertions.go deleted file mode 100644 index 187618e..0000000 --- a/vendor/github.com/playwright-community/playwright-go/apiresponse_assertions.go +++ /dev/null @@ -1,75 +0,0 @@ -package playwright - -import ( - "errors" - "fmt" - "regexp" - "strings" -) - -type apiResponseAssertionsImpl struct { - actual APIResponse - isNot bool -} - -func newAPIResponseAssertions(actual APIResponse, isNot bool) *apiResponseAssertionsImpl { - return &apiResponseAssertionsImpl{ - actual: actual, - isNot: isNot, - } -} - -func (ar *apiResponseAssertionsImpl) Not() APIResponseAssertions { - return newAPIResponseAssertions(ar.actual, true) -} - -func (ar *apiResponseAssertionsImpl) ToBeOK() error { - if ar.isNot != ar.actual.Ok() { - return nil - } - message := fmt.Sprintf(`Response status expected to be within [200..299] range, was %v`, ar.actual.Status()) - if ar.isNot { - message = strings.ReplaceAll(message, "expected to", "expected not to") - } - logList, err := ar.actual.(*apiResponseImpl).fetchLog() - if err != nil { - return err - } - log := strings.Join(logList, "\n") - if log != "" { - message += "\nCall log:\n" + log - } - - isTextEncoding := false - contentType, ok := ar.actual.Headers()["content-type"] - if ok { - isTextEncoding = isTexualMimeType(contentType) - } - if isTextEncoding { - text, err := ar.actual.Text() - if err == nil { - message += fmt.Sprintf(`\n Response Text:\n %s`, subString(text, 0, 1000)) - } - } - return errors.New(message) -} - -func isTexualMimeType(mimeType string) bool { - re := regexp.MustCompile(`^(text\/.*?|application\/(json|(x-)?javascript|xml.*?|ecmascript|graphql|x-www-form-urlencoded)|image\/svg(\+xml)?|application\/.*?(\+json|\+xml))(;\s*charset=.*)?$`) - return re.MatchString(mimeType) -} - -func subString(s string, start, length int) string { - if start < 0 { - start = 0 - } - if length < 0 { - length = 0 - } - rs := []rune(s) - end := start + length - if end > len(rs) { - end = len(rs) - } - return string(rs[start:end]) -} diff --git a/vendor/github.com/playwright-community/playwright-go/artifact.go b/vendor/github.com/playwright-community/playwright-go/artifact.go deleted file mode 100644 index c76b892..0000000 --- a/vendor/github.com/playwright-community/playwright-go/artifact.go +++ /dev/null @@ -1,70 +0,0 @@ -package playwright - -import ( - "errors" - "fmt" -) - -type artifactImpl struct { - channelOwner -} - -func (a *artifactImpl) AbsolutePath() string { - return a.initializer["absolutePath"].(string) -} - -func (a *artifactImpl) PathAfterFinished() (string, error) { - if a.connection.isRemote { - return "", errors.New("Path is not available when connecting remotely. Use SaveAs() to save a local copy") - } - path, err := a.channel.Send("pathAfterFinished") - return path.(string), err -} - -func (a *artifactImpl) SaveAs(path string) error { - if !a.connection.isRemote { - _, err := a.channel.Send("saveAs", map[string]interface{}{ - "path": path, - }) - return err - } - streamChannel, err := a.channel.Send("saveAsStream") - if err != nil { - return err - } - stream := fromChannel(streamChannel).(*streamImpl) - return stream.SaveAs(path) -} - -func (a *artifactImpl) Failure() error { - reason, err := a.channel.Send("failure") - if reason == nil { - return err - } - return fmt.Errorf("%w: %v", ErrPlaywright, reason) -} - -func (a *artifactImpl) Delete() error { - _, err := a.channel.Send("delete") - return err -} - -func (a *artifactImpl) Cancel() error { - _, err := a.channel.Send("cancel") - return err -} - -func (a *artifactImpl) ReadIntoBuffer() ([]byte, error) { - streamChannel, err := a.channel.Send("stream") - if err != nil { - return nil, err - } - stream := fromChannel(streamChannel) - return stream.(*streamImpl).ReadAll() -} - -func newArtifact(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *artifactImpl { - artifact := &artifactImpl{} - artifact.createChannelOwner(artifact, parent, objectType, guid, initializer) - return artifact -} diff --git a/vendor/github.com/playwright-community/playwright-go/assertions.go b/vendor/github.com/playwright-community/playwright-go/assertions.go deleted file mode 100644 index 5e0e710..0000000 --- a/vendor/github.com/playwright-community/playwright-go/assertions.go +++ /dev/null @@ -1,146 +0,0 @@ -package playwright - -import ( - "errors" - "fmt" - "reflect" - "regexp" - "strings" -) - -const assertionsDefaultTimeout = 5000 // 5s - -type playwrightAssertionsImpl struct { - defaultTimeout *float64 -} - -// NewPlaywrightAssertions creates a new instance of PlaywrightAssertions -// - timeout: default value is 5000 (ms) -func NewPlaywrightAssertions(timeout ...float64) PlaywrightAssertions { - if len(timeout) > 0 { - return &playwrightAssertionsImpl{Float(timeout[0])} - } - return &playwrightAssertionsImpl{Float(assertionsDefaultTimeout)} -} - -func (pa *playwrightAssertionsImpl) APIResponse(response APIResponse) APIResponseAssertions { - return newAPIResponseAssertions(response, false) -} - -func (pa *playwrightAssertionsImpl) Locator(locator Locator) LocatorAssertions { - return newLocatorAssertions(locator, false, pa.defaultTimeout) -} - -func (pa *playwrightAssertionsImpl) Page(page Page) PageAssertions { - return newPageAssertions(page, false, pa.defaultTimeout) -} - -type expectedTextValue struct { - Str *string `json:"string,omitempty"` - RegexSource *string `json:"regexSource,omitempty"` - RegexFlags *string `json:"regexFlags,omitempty"` - MatchSubstring *bool `json:"matchSubstring,omitempty"` - IgnoreCase *bool `json:"ignoreCase,omitempty"` - NormalizeWhiteSpace *bool `json:"normalizeWhiteSpace,omitempty"` -} - -type frameExpectOptions struct { - ExpressionArg interface{} `json:"expressionArg,omitempty"` - ExpectedText []expectedTextValue `json:"expectedText,omitempty"` - ExpectedNumber *float64 `json:"expectedNumber,omitempty"` - ExpectedValue interface{} `json:"expectedValue,omitempty"` - UseInnerText *bool `json:"useInnerText,omitempty"` - IsNot bool `json:"isNot"` - Timeout *float64 `json:"timeout"` -} - -type frameExpectResult struct { - Matches bool `json:"matches"` - Received interface{} `json:"received,omitempty"` - TimedOut *bool `json:"timedOut,omitempty"` - Log []string `json:"log,omitempty"` -} - -type assertionsBase struct { - actualLocator Locator - isNot bool - defaultTimeout *float64 -} - -func (b *assertionsBase) expect( - expression string, - options frameExpectOptions, - expected interface{}, - message string, -) error { - options.IsNot = b.isNot - if options.Timeout == nil { - options.Timeout = b.defaultTimeout - } - if options.IsNot { - message = strings.ReplaceAll(message, "expected to", "expected not to") - } - result, err := b.actualLocator.(*locatorImpl).expect(expression, options) - if err != nil { - return err - } - - if result.Matches == b.isNot { - actual := result.Received - log := strings.Join(result.Log, "\n") - if log != "" { - log = "\nCall log:\n" + log - } - if expected != nil { - return fmt.Errorf("%s '%v'\nActual value: %v %s", message, expected, actual, log) - } - return fmt.Errorf("%s\nActual value: %v %s", message, actual, log) - } - - return nil -} - -func toExpectedTextValues( - items []interface{}, - matchSubstring bool, - normalizeWhiteSpace bool, - ignoreCase *bool, -) ([]expectedTextValue, error) { - var out []expectedTextValue - for _, item := range items { - switch item := item.(type) { - case string: - out = append(out, expectedTextValue{ - Str: String(item), - MatchSubstring: Bool(matchSubstring), - NormalizeWhiteSpace: Bool(normalizeWhiteSpace), - IgnoreCase: ignoreCase, - }) - case *regexp.Regexp: - pattern, flags := convertRegexp(item) - out = append(out, expectedTextValue{ - RegexSource: String(pattern), - RegexFlags: String(flags), - MatchSubstring: Bool(matchSubstring), - NormalizeWhiteSpace: Bool(normalizeWhiteSpace), - IgnoreCase: ignoreCase, - }) - default: - return nil, errors.New("value must be a string or regexp") - } - } - return out, nil -} - -func convertToInterfaceList(v interface{}) []interface{} { - rv := reflect.ValueOf(v) - if rv.Kind() != reflect.Slice { - return []interface{}{v} - } - - list := make([]interface{}, rv.Len()) - for i := 0; i < rv.Len(); i++ { - list[i] = rv.Index(i).Interface() - } - return list -} diff --git a/vendor/github.com/playwright-community/playwright-go/binding_call.go b/vendor/github.com/playwright-community/playwright-go/binding_call.go deleted file mode 100644 index 8468992..0000000 --- a/vendor/github.com/playwright-community/playwright-go/binding_call.go +++ /dev/null @@ -1,87 +0,0 @@ -package playwright - -import ( - "fmt" - "strings" - - "github.com/go-stack/stack" -) - -type BindingCall interface { - Call(f BindingCallFunction) -} - -type bindingCallImpl struct { - channelOwner -} - -// BindingSource is the value passed to a binding call execution -type BindingSource struct { - Context BrowserContext - Page Page - Frame Frame -} - -// ExposedFunction represents the func signature of an exposed function -type ExposedFunction = func(args ...interface{}) interface{} - -// BindingCallFunction represents the func signature of an exposed binding call func -type BindingCallFunction func(source *BindingSource, args ...interface{}) interface{} - -func (b *bindingCallImpl) Call(f BindingCallFunction) { - defer func() { - if r := recover(); r != nil { - if _, err := b.channel.Send("reject", map[string]interface{}{ - "error": serializeError(r.(error)), - }); err != nil { - logger.Error("could not reject BindingCall", "error", err) - } - } - }() - - frame := fromChannel(b.initializer["frame"]).(*frameImpl) - source := &BindingSource{ - Context: frame.Page().Context(), - Page: frame.Page(), - Frame: frame, - } - var result interface{} - if handle, ok := b.initializer["handle"]; ok { - result = f(source, fromChannel(handle)) - } else { - initializerArgs := b.initializer["args"].([]interface{}) - funcArgs := []interface{}{} - for i := 0; i < len(initializerArgs); i++ { - funcArgs = append(funcArgs, parseResult(initializerArgs[i])) - } - result = f(source, funcArgs...) - } - _, err := b.channel.Send("resolve", map[string]interface{}{ - "result": serializeArgument(result), - }) - if err != nil { - logger.Error("could not resolve BindingCall", "error", err) - } -} - -func serializeError(err error) map[string]interface{} { - st := stack.Trace().TrimRuntime() - if len(st) == 0 { // https://github.com/go-stack/stack/issues/27 - st = stack.Trace() - } - return map[string]interface{}{ - "error": &Error{ - Name: "Playwright for Go Error", - Message: err.Error(), - Stack: strings.ReplaceAll(strings.TrimFunc(fmt.Sprintf("%+v", st), func(r rune) bool { - return r == '[' || r == ']' - }), " ", "\n"), - }, - } -} - -func newBindingCall(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *bindingCallImpl { - bt := &bindingCallImpl{} - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - return bt -} diff --git a/vendor/github.com/playwright-community/playwright-go/browser.go b/vendor/github.com/playwright-community/playwright-go/browser.go deleted file mode 100644 index c87540a..0000000 --- a/vendor/github.com/playwright-community/playwright-go/browser.go +++ /dev/null @@ -1,274 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "encoding/json" - "errors" - "fmt" - "os" - "path/filepath" -) - -type browserImpl struct { - channelOwner - isConnected bool - shouldCloseConnectionOnClose bool - contexts []BrowserContext - browserType BrowserType - chromiumTracingPath *string - closeReason *string -} - -func (b *browserImpl) BrowserType() BrowserType { - return b.browserType -} - -func (b *browserImpl) IsConnected() bool { - b.RLock() - defer b.RUnlock() - return b.isConnected -} - -func (b *browserImpl) NewContext(options ...BrowserNewContextOptions) (BrowserContext, error) { - overrides := map[string]interface{}{} - option := BrowserNewContextOptions{} - if len(options) == 1 { - option = options[0] - } - if option.AcceptDownloads != nil { - if *option.AcceptDownloads { - overrides["acceptDownloads"] = "accept" - } else { - overrides["acceptDownloads"] = "deny" - } - options[0].AcceptDownloads = nil - } - if option.ExtraHttpHeaders != nil { - overrides["extraHTTPHeaders"] = serializeMapToNameAndValue(options[0].ExtraHttpHeaders) - options[0].ExtraHttpHeaders = nil - } - if option.ClientCertificates != nil { - certs, err := transformClientCertificate(option.ClientCertificates) - if err != nil { - return nil, err - } - overrides["clientCertificates"] = certs - options[0].ClientCertificates = nil - } - if option.StorageStatePath != nil { - var storageState *OptionalStorageState - storageString, err := os.ReadFile(*options[0].StorageStatePath) - if err != nil { - return nil, fmt.Errorf("could not read storage state file: %w", err) - } - err = json.Unmarshal(storageString, &storageState) - if err != nil { - return nil, fmt.Errorf("could not parse storage state file: %w", err) - } - options[0].StorageState = storageState - options[0].StorageStatePath = nil - } - if option.NoViewport != nil && *options[0].NoViewport { - overrides["noDefaultViewport"] = true - options[0].NoViewport = nil - } - if option.RecordHarPath != nil { - overrides["recordHar"] = prepareRecordHarOptions(recordHarInputOptions{ - Path: *options[0].RecordHarPath, - URL: options[0].RecordHarURLFilter, - Mode: options[0].RecordHarMode, - Content: options[0].RecordHarContent, - OmitContent: options[0].RecordHarOmitContent, - }) - options[0].RecordHarPath = nil - options[0].RecordHarURLFilter = nil - options[0].RecordHarMode = nil - options[0].RecordHarContent = nil - options[0].RecordHarOmitContent = nil - } - channel, err := b.channel.Send("newContext", options, overrides) - if err != nil { - return nil, err - } - context := fromChannel(channel).(*browserContextImpl) - context.browser = b - b.browserType.(*browserTypeImpl).didCreateContext(context, &option, nil) - return context, nil -} - -func (b *browserImpl) NewPage(options ...BrowserNewPageOptions) (Page, error) { - opts := make([]BrowserNewContextOptions, 0) - if len(options) == 1 { - opts = append(opts, BrowserNewContextOptions(options[0])) - } - context, err := b.NewContext(opts...) - if err != nil { - return nil, err - } - page, err := context.NewPage() - if err != nil { - return nil, err - } - page.(*pageImpl).ownedContext = context - context.(*browserContextImpl).ownedPage = page - return page, nil -} - -func (b *browserImpl) NewBrowserCDPSession() (CDPSession, error) { - channel, err := b.channel.Send("newBrowserCDPSession") - if err != nil { - return nil, err - } - - cdpSession := fromChannel(channel).(*cdpSessionImpl) - - return cdpSession, nil -} - -func (b *browserImpl) Contexts() []BrowserContext { - b.Lock() - defer b.Unlock() - return b.contexts -} - -func (b *browserImpl) Close(options ...BrowserCloseOptions) (err error) { - if len(options) == 1 { - b.closeReason = options[0].Reason - } - - if b.shouldCloseConnectionOnClose { - err = b.connection.Stop() - } else if b.closeReason != nil { - _, err = b.channel.Send("close", map[string]interface{}{ - "reason": b.closeReason, - }) - } else { - _, err = b.channel.Send("close") - } - if err != nil && !errors.Is(err, ErrTargetClosed) { - return fmt.Errorf("close browser failed: %w", err) - } - return nil -} - -func (b *browserImpl) Version() string { - return b.initializer["version"].(string) -} - -func (b *browserImpl) StartTracing(options ...BrowserStartTracingOptions) error { - overrides := map[string]interface{}{} - option := BrowserStartTracingOptions{} - if len(options) == 1 { - option = options[0] - } - if option.Page != nil { - overrides["page"] = option.Page.(*pageImpl).channel - option.Page = nil - } - if option.Path != nil { - b.chromiumTracingPath = option.Path - option.Path = nil - } - _, err := b.channel.Send("startTracing", option, overrides) - return err -} - -func (b *browserImpl) StopTracing() ([]byte, error) { - channel, err := b.channel.Send("stopTracing") - if err != nil { - return nil, err - } - artifact := fromChannel(channel).(*artifactImpl) - binary, err := artifact.ReadIntoBuffer() - if err != nil { - return nil, err - } - err = artifact.Delete() - if err != nil { - return binary, err - } - if b.chromiumTracingPath != nil { - err := os.MkdirAll(filepath.Dir(*b.chromiumTracingPath), 0o777) - if err != nil { - return binary, err - } - err = os.WriteFile(*b.chromiumTracingPath, binary, 0o644) - if err != nil { - return binary, err - } - } - return binary, nil -} - -func (b *browserImpl) onClose() { - b.Lock() - if b.isConnected { - b.isConnected = false - b.Unlock() - b.Emit("disconnected", b) - return - } - b.Unlock() -} - -func (b *browserImpl) OnDisconnected(fn func(Browser)) { - b.On("disconnected", fn) -} - -func newBrowser(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *browserImpl { - b := &browserImpl{ - isConnected: true, - contexts: make([]BrowserContext, 0), - } - b.createChannelOwner(b, parent, objectType, guid, initializer) - // convert parent to *browserTypeImpl - b.browserType = newBrowserType(parent.parent, parent.objectType, parent.guid, parent.initializer) - b.channel.On("close", b.onClose) - return b -} - -func transformClientCertificate(clientCertificates []ClientCertificate) ([]map[string]interface{}, error) { - results := make([]map[string]interface{}, 0) - - for _, cert := range clientCertificates { - data := map[string]interface{}{ - "origin": cert.Origin, - "passphrase": cert.Passphrase, - } - if len(cert.Cert) > 0 { - data["cert"] = base64.StdEncoding.EncodeToString(cert.Cert) - } else if cert.CertPath != nil { - content, err := os.ReadFile(*cert.CertPath) - if err != nil { - return nil, err - } - data["cert"] = base64.StdEncoding.EncodeToString(content) - } - - if len(cert.Key) > 0 { - data["key"] = base64.StdEncoding.EncodeToString(cert.Key) - } else if cert.KeyPath != nil { - content, err := os.ReadFile(*cert.KeyPath) - if err != nil { - return nil, err - } - data["key"] = base64.StdEncoding.EncodeToString(content) - } - - if len(cert.Pfx) > 0 { - data["pfx"] = base64.StdEncoding.EncodeToString(cert.Pfx) - } else if cert.PfxPath != nil { - content, err := os.ReadFile(*cert.PfxPath) - if err != nil { - return nil, err - } - data["pfx"] = base64.StdEncoding.EncodeToString(content) - } - - results = append(results, data) - } - if len(results) == 0 { - return nil, nil - } - return results, nil -} diff --git a/vendor/github.com/playwright-community/playwright-go/browser_context.go b/vendor/github.com/playwright-community/playwright-go/browser_context.go deleted file mode 100644 index 1d420d3..0000000 --- a/vendor/github.com/playwright-community/playwright-go/browser_context.go +++ /dev/null @@ -1,914 +0,0 @@ -package playwright - -import ( - "encoding/json" - "errors" - "fmt" - "os" - "regexp" - "slices" - "strings" - "sync" - - "github.com/playwright-community/playwright-go/internal/safe" -) - -type browserContextImpl struct { - channelOwner - timeoutSettings *timeoutSettings - closeWasCalled bool - options *BrowserNewContextOptions - pages []Page - routes []*routeHandlerEntry - webSocketRoutes []*webSocketRouteHandler - ownedPage Page - browser *browserImpl - serviceWorkers []Worker - backgroundPages []Page - bindings *safe.SyncMap[string, BindingCallFunction] - tracing *tracingImpl - request *apiRequestContextImpl - harRecorders map[string]harRecordingMetadata - closed chan struct{} - closeReason *string - harRouters []*harRouter - clock Clock -} - -func (b *browserContextImpl) Clock() Clock { - return b.clock -} - -func (b *browserContextImpl) SetDefaultNavigationTimeout(timeout float64) { - b.setDefaultNavigationTimeoutImpl(&timeout) -} - -func (b *browserContextImpl) setDefaultNavigationTimeoutImpl(timeout *float64) { - b.timeoutSettings.SetDefaultNavigationTimeout(timeout) - b.channel.SendNoReplyInternal("setDefaultNavigationTimeoutNoReply", map[string]interface{}{ - "timeout": timeout, - }) -} - -func (b *browserContextImpl) SetDefaultTimeout(timeout float64) { - b.setDefaultTimeoutImpl(&timeout) -} - -func (b *browserContextImpl) setDefaultTimeoutImpl(timeout *float64) { - b.timeoutSettings.SetDefaultTimeout(timeout) - b.channel.SendNoReplyInternal("setDefaultTimeoutNoReply", map[string]interface{}{ - "timeout": timeout, - }) -} - -func (b *browserContextImpl) Pages() []Page { - b.Lock() - defer b.Unlock() - return b.pages -} - -func (b *browserContextImpl) Browser() Browser { - return b.browser -} - -func (b *browserContextImpl) Tracing() Tracing { - return b.tracing -} - -func (b *browserContextImpl) NewCDPSession(page interface{}) (CDPSession, error) { - params := map[string]interface{}{} - - if p, ok := page.(*pageImpl); ok { - params["page"] = p.channel - } else if f, ok := page.(*frameImpl); ok { - params["frame"] = f.channel - } else { - return nil, fmt.Errorf("not page or frame: %v", page) - } - - channel, err := b.channel.Send("newCDPSession", params) - if err != nil { - return nil, err - } - - cdpSession := fromChannel(channel).(*cdpSessionImpl) - - return cdpSession, nil -} - -func (b *browserContextImpl) NewPage() (Page, error) { - if b.ownedPage != nil { - return nil, errors.New("Please use browser.NewContext()") - } - channel, err := b.channel.Send("newPage") - if err != nil { - return nil, err - } - return fromChannel(channel).(*pageImpl), nil -} - -func (b *browserContextImpl) Cookies(urls ...string) ([]Cookie, error) { - result, err := b.channel.Send("cookies", map[string]interface{}{ - "urls": urls, - }) - if err != nil { - return nil, err - } - cookies := make([]Cookie, len(result.([]interface{}))) - for i, item := range result.([]interface{}) { - cookie := &Cookie{} - remapMapToStruct(item, cookie) - cookies[i] = *cookie - } - return cookies, nil -} - -func (b *browserContextImpl) AddCookies(cookies []OptionalCookie) error { - _, err := b.channel.Send("addCookies", map[string]interface{}{ - "cookies": cookies, - }) - return err -} - -func (b *browserContextImpl) ClearCookies(options ...BrowserContextClearCookiesOptions) error { - params := map[string]interface{}{} - if len(options) == 1 { - if options[0].Domain != nil { - switch t := options[0].Domain.(type) { - case string: - params["domain"] = t - case *string: - params["domain"] = t - case *regexp.Regexp: - pattern, flag := convertRegexp(t) - params["domainRegexSource"] = pattern - params["domainRegexFlags"] = flag - default: - return errors.New("invalid type for domain, expected string or *regexp.Regexp") - } - } - if options[0].Name != nil { - switch t := options[0].Name.(type) { - case string: - params["name"] = t - case *string: - params["name"] = t - case *regexp.Regexp: - pattern, flag := convertRegexp(t) - params["nameRegexSource"] = pattern - params["nameRegexFlags"] = flag - default: - return errors.New("invalid type for name, expected string or *regexp.Regexp") - } - } - if options[0].Path != nil { - switch t := options[0].Path.(type) { - case string: - params["path"] = t - case *string: - params["path"] = t - case *regexp.Regexp: - pattern, flag := convertRegexp(t) - params["pathRegexSource"] = pattern - params["pathRegexFlags"] = flag - default: - return errors.New("invalid type for path, expected string or *regexp.Regexp") - } - } - } - _, err := b.channel.Send("clearCookies", params) - return err -} - -func (b *browserContextImpl) GrantPermissions(permissions []string, options ...BrowserContextGrantPermissionsOptions) error { - _, err := b.channel.Send("grantPermissions", map[string]interface{}{ - "permissions": permissions, - }, options) - return err -} - -func (b *browserContextImpl) ClearPermissions() error { - _, err := b.channel.Send("clearPermissions") - return err -} - -func (b *browserContextImpl) SetGeolocation(geolocation *Geolocation) error { - _, err := b.channel.Send("setGeolocation", map[string]interface{}{ - "geolocation": geolocation, - }) - return err -} - -func (b *browserContextImpl) ResetGeolocation() error { - _, err := b.channel.Send("setGeolocation", map[string]interface{}{}) - return err -} - -func (b *browserContextImpl) SetExtraHTTPHeaders(headers map[string]string) error { - _, err := b.channel.Send("setExtraHTTPHeaders", map[string]interface{}{ - "headers": serializeMapToNameAndValue(headers), - }) - return err -} - -func (b *browserContextImpl) SetOffline(offline bool) error { - _, err := b.channel.Send("setOffline", map[string]interface{}{ - "offline": offline, - }) - return err -} - -func (b *browserContextImpl) AddInitScript(script Script) error { - var source string - if script.Content != nil { - source = *script.Content - } - if script.Path != nil { - content, err := os.ReadFile(*script.Path) - if err != nil { - return err - } - source = string(content) - } - _, err := b.channel.Send("addInitScript", map[string]interface{}{ - "source": source, - }) - return err -} - -func (b *browserContextImpl) ExposeBinding(name string, binding BindingCallFunction, handle ...bool) error { - needsHandle := false - if len(handle) == 1 { - needsHandle = handle[0] - } - for _, page := range b.Pages() { - if _, ok := page.(*pageImpl).bindings.Load(name); ok { - return fmt.Errorf("Function '%s' has been already registered in one of the pages", name) - } - } - if _, ok := b.bindings.Load(name); ok { - return fmt.Errorf("Function '%s' has been already registered", name) - } - _, err := b.channel.Send("exposeBinding", map[string]interface{}{ - "name": name, - "needsHandle": needsHandle, - }) - if err != nil { - return err - } - b.bindings.Store(name, binding) - return err -} - -func (b *browserContextImpl) ExposeFunction(name string, binding ExposedFunction) error { - return b.ExposeBinding(name, func(source *BindingSource, args ...interface{}) interface{} { - return binding(args...) - }) -} - -func (b *browserContextImpl) Route(url interface{}, handler routeHandler, times ...int) error { - b.Lock() - defer b.Unlock() - b.routes = slices.Insert(b.routes, 0, newRouteHandlerEntry(newURLMatcher(url, b.options.BaseURL), handler, times...)) - return b.updateInterceptionPatterns() -} - -func (b *browserContextImpl) Unroute(url interface{}, handlers ...routeHandler) error { - removed, remaining, err := unroute(b.routes, url, handlers...) - if err != nil { - return err - } - return b.unrouteInternal(removed, remaining, UnrouteBehaviorDefault) -} - -func (b *browserContextImpl) unrouteInternal(removed []*routeHandlerEntry, remaining []*routeHandlerEntry, behavior *UnrouteBehavior) error { - b.Lock() - defer b.Unlock() - b.routes = remaining - if err := b.updateInterceptionPatterns(); err != nil { - return err - } - if behavior == nil || behavior == UnrouteBehaviorDefault { - return nil - } - wg := &sync.WaitGroup{} - for _, entry := range removed { - wg.Add(1) - go func(entry *routeHandlerEntry) { - defer wg.Done() - entry.Stop(string(*behavior)) - }(entry) - } - wg.Wait() - return nil -} - -func (b *browserContextImpl) UnrouteAll(options ...BrowserContextUnrouteAllOptions) error { - var behavior *UnrouteBehavior - if len(options) == 1 { - behavior = options[0].Behavior - } - defer b.disposeHarRouters() - return b.unrouteInternal(b.routes, []*routeHandlerEntry{}, behavior) -} - -func (b *browserContextImpl) disposeHarRouters() { - for _, router := range b.harRouters { - router.dispose() - } - b.harRouters = make([]*harRouter, 0) -} - -func (b *browserContextImpl) Request() APIRequestContext { - return b.request -} - -func (b *browserContextImpl) RouteFromHAR(har string, options ...BrowserContextRouteFromHAROptions) error { - opt := BrowserContextRouteFromHAROptions{} - if len(options) == 1 { - opt = options[0] - } - if opt.Update != nil && *opt.Update { - var updateContent *HarContentPolicy - switch opt.UpdateContent { - case RouteFromHarUpdateContentPolicyAttach: - updateContent = HarContentPolicyAttach - case RouteFromHarUpdateContentPolicyEmbed: - updateContent = HarContentPolicyEmbed - } - return b.recordIntoHar(har, browserContextRecordIntoHarOptions{ - URL: opt.URL, - UpdateContent: updateContent, - UpdateMode: opt.UpdateMode, - }) - } - notFound := opt.NotFound - if notFound == nil { - notFound = HarNotFoundAbort - } - router := newHarRouter(b.connection.localUtils, har, *notFound, opt.URL) - b.harRouters = append(b.harRouters, router) - return router.addContextRoute(b) -} - -func (b *browserContextImpl) WaitForEvent(event string, options ...BrowserContextWaitForEventOptions) (interface{}, error) { - return b.waiterForEvent(event, options...).Wait() -} - -func (b *browserContextImpl) waiterForEvent(event string, options ...BrowserContextWaitForEventOptions) *waiter { - timeout := b.timeoutSettings.Timeout() - var predicate interface{} = nil - if len(options) == 1 { - if options[0].Timeout != nil { - timeout = *options[0].Timeout - } - predicate = options[0].Predicate - } - waiter := newWaiter().WithTimeout(timeout) - waiter.RejectOnEvent(b, "close", ErrTargetClosed) - return waiter.WaitForEvent(b, event, predicate) -} - -func (b *browserContextImpl) ExpectConsoleMessage(cb func() error, options ...BrowserContextExpectConsoleMessageOptions) (ConsoleMessage, error) { - var w *waiter - if len(options) == 1 { - w = b.waiterForEvent("console", BrowserContextWaitForEventOptions{ - Predicate: options[0].Predicate, - Timeout: options[0].Timeout, - }) - } else { - w = b.waiterForEvent("console") - } - ret, err := w.RunAndWait(cb) - if err != nil { - return nil, err - } - return ret.(ConsoleMessage), nil -} - -func (b *browserContextImpl) ExpectEvent(event string, cb func() error, options ...BrowserContextExpectEventOptions) (interface{}, error) { - if len(options) == 1 { - return b.waiterForEvent(event, BrowserContextWaitForEventOptions(options[0])).RunAndWait(cb) - } - return b.waiterForEvent(event).RunAndWait(cb) -} - -func (b *browserContextImpl) ExpectPage(cb func() error, options ...BrowserContextExpectPageOptions) (Page, error) { - var w *waiter - if len(options) == 1 { - w = b.waiterForEvent("page", BrowserContextWaitForEventOptions{ - Predicate: options[0].Predicate, - Timeout: options[0].Timeout, - }) - } else { - w = b.waiterForEvent("page") - } - ret, err := w.RunAndWait(cb) - if err != nil { - return nil, err - } - return ret.(Page), nil -} - -func (b *browserContextImpl) Close(options ...BrowserContextCloseOptions) error { - if b.closeWasCalled { - return nil - } - if len(options) == 1 { - b.closeReason = options[0].Reason - } - b.closeWasCalled = true - - _, err := b.channel.connection.WrapAPICall(func() (interface{}, error) { - return nil, b.request.Dispose(APIRequestContextDisposeOptions{ - Reason: b.closeReason, - }) - }, true) - if err != nil { - return err - } - - innerClose := func() (interface{}, error) { - for harId, harMetaData := range b.harRecorders { - overrides := map[string]interface{}{} - if harId != "" { - overrides["harId"] = harId - } - response, err := b.channel.Send("harExport", overrides) - if err != nil { - return nil, err - } - artifact := fromChannel(response).(*artifactImpl) - // Server side will compress artifact if content is attach or if file is .zip. - needCompressed := strings.HasSuffix(strings.ToLower(harMetaData.Path), ".zip") - if !needCompressed && harMetaData.Content == HarContentPolicyAttach { - tmpPath := harMetaData.Path + ".tmp" - if err := artifact.SaveAs(tmpPath); err != nil { - return nil, err - } - err = b.connection.localUtils.HarUnzip(tmpPath, harMetaData.Path) - if err != nil { - return nil, err - } - } else { - if err := artifact.SaveAs(harMetaData.Path); err != nil { - return nil, err - } - } - if err := artifact.Delete(); err != nil { - return nil, err - } - } - return nil, nil - } - - _, err = b.channel.connection.WrapAPICall(innerClose, true) - if err != nil { - return err - } - - _, err = b.channel.Send("close", map[string]interface{}{ - "reason": b.closeReason, - }) - if err != nil { - return err - } - <-b.closed - return err -} - -type browserContextRecordIntoHarOptions struct { - Page Page - URL interface{} - UpdateContent *HarContentPolicy - UpdateMode *HarMode -} - -func (b *browserContextImpl) recordIntoHar(har string, options ...browserContextRecordIntoHarOptions) error { - overrides := map[string]interface{}{} - harOptions := recordHarInputOptions{ - Path: har, - Content: HarContentPolicyAttach, - Mode: HarModeMinimal, - } - if len(options) == 1 { - if options[0].UpdateContent != nil { - harOptions.Content = options[0].UpdateContent - } - if options[0].UpdateMode != nil { - harOptions.Mode = options[0].UpdateMode - } - harOptions.URL = options[0].URL - overrides["options"] = prepareRecordHarOptions(harOptions) - if options[0].Page != nil { - overrides["page"] = options[0].Page.(*pageImpl).channel - } - } - harId, err := b.channel.Send("harStart", overrides) - if err != nil { - return err - } - b.harRecorders[harId.(string)] = harRecordingMetadata{ - Path: har, - Content: harOptions.Content, - } - return nil -} - -func (b *browserContextImpl) StorageState(paths ...string) (*StorageState, error) { - result, err := b.channel.SendReturnAsDict("storageState") - if err != nil { - return nil, err - } - if len(paths) == 1 { - file, err := os.Create(paths[0]) - if err != nil { - return nil, err - } - if err := json.NewEncoder(file).Encode(result); err != nil { - return nil, err - } - if err := file.Close(); err != nil { - return nil, err - } - } - var storageState StorageState - remapMapToStruct(result, &storageState) - return &storageState, nil -} - -func (b *browserContextImpl) onBinding(binding *bindingCallImpl) { - function, ok := b.bindings.Load(binding.initializer["name"].(string)) - if !ok || function == nil { - return - } - go binding.Call(function) -} - -func (b *browserContextImpl) onClose() { - if b.browser != nil { - contexts := make([]BrowserContext, 0) - b.browser.Lock() - for _, context := range b.browser.contexts { - if context != b { - contexts = append(contexts, context) - } - } - b.browser.contexts = contexts - b.browser.Unlock() - } - b.disposeHarRouters() - b.Emit("close", b) -} - -func (b *browserContextImpl) onPage(page Page) { - b.Lock() - b.pages = append(b.pages, page) - b.Unlock() - b.Emit("page", page) - opener, _ := page.Opener() - if opener != nil && !opener.IsClosed() { - opener.Emit("popup", page) - } -} - -func (b *browserContextImpl) onRoute(route *routeImpl) { - b.Lock() - route.context = b - page := route.Request().(*requestImpl).safePage() - routes := make([]*routeHandlerEntry, len(b.routes)) - copy(routes, b.routes) - b.Unlock() - - checkInterceptionIfNeeded := func() { - b.Lock() - defer b.Unlock() - if len(b.routes) == 0 { - _, err := b.connection.WrapAPICall(func() (interface{}, error) { - err := b.updateInterceptionPatterns() - return nil, err - }, true) - if err != nil { - logger.Error("could not update interception patterns", "error", err) - } - } - } - - url := route.Request().URL() - for _, handlerEntry := range routes { - // If the page or the context was closed we stall all requests right away. - if (page != nil && page.closeWasCalled) || b.closeWasCalled { - return - } - if !handlerEntry.Matches(url) { - continue - } - if !slices.ContainsFunc(b.routes, func(entry *routeHandlerEntry) bool { - return entry == handlerEntry - }) { - continue - } - if handlerEntry.WillExceed() { - b.routes = slices.DeleteFunc(b.routes, func(rhe *routeHandlerEntry) bool { - return rhe == handlerEntry - }) - } - handled := handlerEntry.Handle(route) - checkInterceptionIfNeeded() - yes := <-handled - if yes { - return - } - } - // If the page is closed or unrouteAll() was called without waiting and interception disabled, - // the method will throw an error - silence it. - _ = route.internalContinue(true) -} - -func (b *browserContextImpl) updateInterceptionPatterns() error { - patterns := prepareInterceptionPatterns(b.routes) - _, err := b.channel.Send("setNetworkInterceptionPatterns", map[string]interface{}{ - "patterns": patterns, - }) - return err -} - -func (b *browserContextImpl) pause() <-chan error { - ret := make(chan error, 1) - go func() { - _, err := b.channel.Send("pause") - ret <- err - }() - return ret -} - -func (b *browserContextImpl) onBackgroundPage(ev map[string]interface{}) { - b.Lock() - p := fromChannel(ev["page"]).(*pageImpl) - p.browserContext = b - b.backgroundPages = append(b.backgroundPages, p) - b.Unlock() - b.Emit("backgroundpage", p) -} - -func (b *browserContextImpl) onServiceWorker(worker *workerImpl) { - worker.context = b - b.serviceWorkers = append(b.serviceWorkers, worker) - b.Emit("serviceworker", worker) -} - -func (b *browserContextImpl) setOptions(options *BrowserNewContextOptions, tracesDir *string) { - if options == nil { - options = &BrowserNewContextOptions{} - } - b.options = options - if b.options != nil && b.options.RecordHarPath != nil { - b.harRecorders[""] = harRecordingMetadata{ - Path: *b.options.RecordHarPath, - Content: b.options.RecordHarContent, - } - } - if tracesDir != nil { - b.tracing.tracesDir = *tracesDir - } -} - -func (b *browserContextImpl) BackgroundPages() []Page { - b.Lock() - defer b.Unlock() - return b.backgroundPages -} - -func (b *browserContextImpl) ServiceWorkers() []Worker { - b.Lock() - defer b.Unlock() - return b.serviceWorkers -} - -func (b *browserContextImpl) OnBackgroundPage(fn func(Page)) { - b.On("backgroundpage", fn) -} - -func (b *browserContextImpl) OnClose(fn func(BrowserContext)) { - b.On("close", fn) -} - -func (b *browserContextImpl) OnConsole(fn func(ConsoleMessage)) { - b.On("console", fn) -} - -func (b *browserContextImpl) OnDialog(fn func(Dialog)) { - b.On("dialog", fn) -} - -func (b *browserContextImpl) OnPage(fn func(Page)) { - b.On("page", fn) -} - -func (b *browserContextImpl) OnRequest(fn func(Request)) { - b.On("request", fn) -} - -func (b *browserContextImpl) OnRequestFailed(fn func(Request)) { - b.On("requestfailed", fn) -} - -func (b *browserContextImpl) OnRequestFinished(fn func(Request)) { - b.On("requestfinished", fn) -} - -func (b *browserContextImpl) OnResponse(fn func(Response)) { - b.On("response", fn) -} - -func (b *browserContextImpl) OnWebError(fn func(WebError)) { - b.On("weberror", fn) -} - -func (b *browserContextImpl) RouteWebSocket(url interface{}, handler func(WebSocketRoute)) error { - b.Lock() - defer b.Unlock() - b.webSocketRoutes = slices.Insert(b.webSocketRoutes, 0, newWebSocketRouteHandler(newURLMatcher(url, b.options.BaseURL), handler)) - - return b.updateWebSocketInterceptionPatterns() -} - -func (b *browserContextImpl) onWebSocketRoute(wr WebSocketRoute) { - b.Lock() - index := slices.IndexFunc(b.webSocketRoutes, func(r *webSocketRouteHandler) bool { - return r.Matches(wr.URL()) - }) - if index == -1 { - b.Unlock() - _, err := wr.ConnectToServer() - if err != nil { - logger.Error("could not connect to WebSocket server", "error", err) - } - return - } - handler := b.webSocketRoutes[index] - b.Unlock() - handler.Handle(wr) -} - -func (b *browserContextImpl) updateWebSocketInterceptionPatterns() error { - patterns := prepareWebSocketRouteHandlerInterceptionPatterns(b.webSocketRoutes) - _, err := b.channel.Send("setWebSocketInterceptionPatterns", map[string]interface{}{ - "patterns": patterns, - }) - return err -} - -func (b *browserContextImpl) effectiveCloseReason() *string { - b.Lock() - defer b.Unlock() - if b.closeReason != nil { - return b.closeReason - } - if b.browser != nil { - return b.browser.closeReason - } - return nil -} - -func newBrowserContext(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *browserContextImpl { - bt := &browserContextImpl{ - timeoutSettings: newTimeoutSettings(nil), - pages: make([]Page, 0), - backgroundPages: make([]Page, 0), - routes: make([]*routeHandlerEntry, 0), - bindings: safe.NewSyncMap[string, BindingCallFunction](), - harRecorders: make(map[string]harRecordingMetadata), - closed: make(chan struct{}, 1), - harRouters: make([]*harRouter, 0), - } - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - if parent.objectType == "Browser" { - bt.browser = fromChannel(parent.channel).(*browserImpl) - bt.browser.contexts = append(bt.browser.contexts, bt) - } - bt.tracing = fromChannel(initializer["tracing"]).(*tracingImpl) - bt.request = fromChannel(initializer["requestContext"]).(*apiRequestContextImpl) - bt.clock = newClock(bt) - bt.channel.On("bindingCall", func(params map[string]interface{}) { - bt.onBinding(fromChannel(params["binding"]).(*bindingCallImpl)) - }) - - bt.channel.On("close", bt.onClose) - bt.channel.On("page", func(payload map[string]interface{}) { - bt.onPage(fromChannel(payload["page"]).(*pageImpl)) - }) - bt.channel.On("route", func(params map[string]interface{}) { - bt.channel.CreateTask(func() { - bt.onRoute(fromChannel(params["route"]).(*routeImpl)) - }) - }) - bt.channel.On("webSocketRoute", func(params map[string]interface{}) { - bt.channel.CreateTask(func() { - bt.onWebSocketRoute(fromChannel(params["webSocketRoute"]).(*webSocketRouteImpl)) - }) - }) - bt.channel.On("backgroundPage", bt.onBackgroundPage) - bt.channel.On("serviceWorker", func(params map[string]interface{}) { - bt.onServiceWorker(fromChannel(params["worker"]).(*workerImpl)) - }) - bt.channel.On("console", func(ev map[string]interface{}) { - message := newConsoleMessage(ev) - bt.Emit("console", message) - if message.page != nil { - message.page.Emit("console", message) - } - }) - bt.channel.On("dialog", func(params map[string]interface{}) { - dialog := fromChannel(params["dialog"]).(*dialogImpl) - go func() { - hasListeners := bt.Emit("dialog", dialog) - page := dialog.page - if page != nil { - if page.Emit("dialog", dialog) { - hasListeners = true - } - } - if !hasListeners { - // Although we do similar handling on the server side, we still need this logic - // on the client side due to a possible race condition between two async calls: - // a) removing "dialog" listener subscription (client->server) - // b) actual "dialog" event (server->client) - if dialog.Type() == "beforeunload" { - _ = dialog.Accept() - } else { - _ = dialog.Dismiss() - } - } - }() - }) - bt.channel.On( - "pageError", func(ev map[string]interface{}) { - pwErr := &Error{} - remapMapToStruct(ev["error"].(map[string]interface{})["error"], pwErr) - err := parseError(*pwErr) - page := fromNullableChannel(ev["page"]) - if page != nil { - bt.Emit("weberror", newWebError(page.(*pageImpl), err)) - page.(*pageImpl).Emit("pageerror", err) - } else { - bt.Emit("weberror", newWebError(nil, err)) - } - }, - ) - bt.channel.On("request", func(ev map[string]interface{}) { - request := fromChannel(ev["request"]).(*requestImpl) - page := fromNullableChannel(ev["page"]) - bt.Emit("request", request) - if page != nil { - page.(*pageImpl).Emit("request", request) - } - }) - bt.channel.On("requestFailed", func(ev map[string]interface{}) { - request := fromChannel(ev["request"]).(*requestImpl) - failureText := ev["failureText"] - if failureText != nil { - request.failureText = failureText.(string) - } - page := fromNullableChannel(ev["page"]) - request.setResponseEndTiming(ev["responseEndTiming"].(float64)) - bt.Emit("requestfailed", request) - if page != nil { - page.(*pageImpl).Emit("requestfailed", request) - } - }) - - bt.channel.On("requestFinished", func(ev map[string]interface{}) { - request := fromChannel(ev["request"]).(*requestImpl) - response := fromNullableChannel(ev["response"]) - page := fromNullableChannel(ev["page"]) - request.setResponseEndTiming(ev["responseEndTiming"].(float64)) - bt.Emit("requestfinished", request) - if page != nil { - page.(*pageImpl).Emit("requestfinished", request) - } - if response != nil { - close(response.(*responseImpl).finished) - } - }) - bt.channel.On("response", func(ev map[string]interface{}) { - response := fromChannel(ev["response"]).(*responseImpl) - page := fromNullableChannel(ev["page"]) - bt.Emit("response", response) - if page != nil { - page.(*pageImpl).Emit("response", response) - } - }) - bt.Once("close", func() { - bt.closed <- struct{}{} - }) - bt.setEventSubscriptionMapping(map[string]string{ - "console": "console", - "dialog": "dialog", - "request": "request", - "response": "response", - "requestfinished": "requestFinished", - "responsefailed": "responseFailed", - }) - return bt -} diff --git a/vendor/github.com/playwright-community/playwright-go/browser_type.go b/vendor/github.com/playwright-community/playwright-go/browser_type.go deleted file mode 100644 index 41a8b18..0000000 --- a/vendor/github.com/playwright-community/playwright-go/browser_type.go +++ /dev/null @@ -1,181 +0,0 @@ -package playwright - -import ( - "fmt" -) - -type browserTypeImpl struct { - channelOwner - playwright *Playwright -} - -func (b *browserTypeImpl) Name() string { - return b.initializer["name"].(string) -} - -func (b *browserTypeImpl) ExecutablePath() string { - return b.initializer["executablePath"].(string) -} - -func (b *browserTypeImpl) Launch(options ...BrowserTypeLaunchOptions) (Browser, error) { - overrides := map[string]interface{}{} - if len(options) == 1 && options[0].Env != nil { - overrides["env"] = serializeMapToNameAndValue(options[0].Env) - options[0].Env = nil - } - channel, err := b.channel.Send("launch", options, overrides) - if err != nil { - return nil, err - } - browser := fromChannel(channel).(*browserImpl) - b.didLaunchBrowser(browser) - return browser, nil -} - -func (b *browserTypeImpl) LaunchPersistentContext(userDataDir string, options ...BrowserTypeLaunchPersistentContextOptions) (BrowserContext, error) { - overrides := map[string]interface{}{ - "userDataDir": userDataDir, - } - option := &BrowserNewContextOptions{} - var tracesDir *string = nil - if len(options) == 1 { - tracesDir = options[0].TracesDir - err := assignStructFields(option, options[0], true) - if err != nil { - return nil, fmt.Errorf("can not convert options: %w", err) - } - if options[0].AcceptDownloads != nil { - if *options[0].AcceptDownloads { - overrides["acceptDownloads"] = "accept" - } else { - overrides["acceptDownloads"] = "deny" - } - options[0].AcceptDownloads = nil - } - if options[0].ClientCertificates != nil { - certs, err := transformClientCertificate(options[0].ClientCertificates) - if err != nil { - return nil, err - } - overrides["clientCertificates"] = certs - options[0].ClientCertificates = nil - } - if options[0].ExtraHttpHeaders != nil { - overrides["extraHTTPHeaders"] = serializeMapToNameAndValue(options[0].ExtraHttpHeaders) - options[0].ExtraHttpHeaders = nil - } - if options[0].Env != nil { - overrides["env"] = serializeMapToNameAndValue(options[0].Env) - options[0].Env = nil - } - if options[0].NoViewport != nil && *options[0].NoViewport { - overrides["noDefaultViewport"] = true - options[0].NoViewport = nil - } - if options[0].RecordHarPath != nil { - overrides["recordHar"] = prepareRecordHarOptions(recordHarInputOptions{ - Path: *options[0].RecordHarPath, - URL: options[0].RecordHarURLFilter, - Mode: options[0].RecordHarMode, - Content: options[0].RecordHarContent, - OmitContent: options[0].RecordHarOmitContent, - }) - options[0].RecordHarPath = nil - options[0].RecordHarURLFilter = nil - options[0].RecordHarMode = nil - options[0].RecordHarContent = nil - options[0].RecordHarOmitContent = nil - } - } - channel, err := b.channel.Send("launchPersistentContext", options, overrides) - if err != nil { - return nil, err - } - context := fromChannel(channel).(*browserContextImpl) - b.didCreateContext(context, option, tracesDir) - return context, nil -} - -func (b *browserTypeImpl) Connect(wsEndpoint string, options ...BrowserTypeConnectOptions) (Browser, error) { - overrides := map[string]interface{}{ - "wsEndpoint": wsEndpoint, - "headers": map[string]string{ - "x-playwright-browser": b.Name(), - }, - } - if len(options) == 1 { - if options[0].Headers != nil { - for k, v := range options[0].Headers { - overrides["headers"].(map[string]string)[k] = v - } - options[0].Headers = nil - } - } - localUtils := b.connection.LocalUtils() - pipe, err := localUtils.channel.SendReturnAsDict("connect", options, overrides) - if err != nil { - return nil, err - } - jsonPipe := fromChannel(pipe["pipe"]).(*jsonPipe) - connection := newConnection(jsonPipe, localUtils) - - playwright, err := connection.Start() - if err != nil { - return nil, err - } - playwright.setSelectors(b.playwright.Selectors) - browser := fromChannel(playwright.initializer["preLaunchedBrowser"]).(*browserImpl) - browser.shouldCloseConnectionOnClose = true - pipeClosed := func() { - for _, context := range browser.Contexts() { - pages := context.Pages() - for _, page := range pages { - page.(*pageImpl).onClose() - } - context.(*browserContextImpl).onClose() - } - browser.onClose() - connection.cleanup() - } - jsonPipe.On("closed", pipeClosed) - - b.didLaunchBrowser(browser) - return browser, nil -} - -func (b *browserTypeImpl) ConnectOverCDP(endpointURL string, options ...BrowserTypeConnectOverCDPOptions) (Browser, error) { - overrides := map[string]interface{}{ - "endpointURL": endpointURL, - } - if len(options) == 1 { - if options[0].Headers != nil { - overrides["headers"] = serializeMapToNameAndValue(options[0].Headers) - options[0].Headers = nil - } - } - response, err := b.channel.SendReturnAsDict("connectOverCDP", options, overrides) - if err != nil { - return nil, err - } - browser := fromChannel(response["browser"]).(*browserImpl) - b.didLaunchBrowser(browser) - if defaultContext, ok := response["defaultContext"]; ok { - context := fromChannel(defaultContext).(*browserContextImpl) - b.didCreateContext(context, nil, nil) - } - return browser, nil -} - -func (b *browserTypeImpl) didCreateContext(context *browserContextImpl, contextOptions *BrowserNewContextOptions, tracesDir *string) { - context.setOptions(contextOptions, tracesDir) -} - -func (b *browserTypeImpl) didLaunchBrowser(browser *browserImpl) { - browser.browserType = b -} - -func newBrowserType(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *browserTypeImpl { - bt := &browserTypeImpl{} - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - return bt -} diff --git a/vendor/github.com/playwright-community/playwright-go/cdp_session.go b/vendor/github.com/playwright-community/playwright-go/cdp_session.go deleted file mode 100644 index e9bba82..0000000 --- a/vendor/github.com/playwright-community/playwright-go/cdp_session.go +++ /dev/null @@ -1,38 +0,0 @@ -package playwright - -type cdpSessionImpl struct { - channelOwner -} - -func (c *cdpSessionImpl) Detach() error { - _, err := c.channel.Send("detach") - return err -} - -func (c *cdpSessionImpl) Send(method string, params map[string]interface{}) (interface{}, error) { - result, err := c.channel.Send("send", map[string]interface{}{ - "method": method, - "params": params, - }) - if err != nil { - return nil, err - } - - return result, err -} - -func (c *cdpSessionImpl) onEvent(params map[string]interface{}) { - c.Emit(params["method"].(string), params["params"]) -} - -func newCDPSession(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *cdpSessionImpl { - bt := &cdpSessionImpl{} - - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - - bt.channel.On("event", func(params map[string]interface{}) { - bt.onEvent(params) - }) - - return bt -} diff --git a/vendor/github.com/playwright-community/playwright-go/channel.go b/vendor/github.com/playwright-community/playwright-go/channel.go deleted file mode 100644 index b0bded4..0000000 --- a/vendor/github.com/playwright-community/playwright-go/channel.go +++ /dev/null @@ -1,92 +0,0 @@ -package playwright - -import ( - "encoding/json" - "fmt" -) - -type channel struct { - eventEmitter - guid string - connection *connection - owner *channelOwner // to avoid type conversion - object interface{} // retain type info (for fromChannel needed) -} - -func (c *channel) MarshalJSON() ([]byte, error) { - return json.Marshal(map[string]string{ - "guid": c.guid, - }) -} - -// for catch errors of route handlers etc. -func (c *channel) CreateTask(fn func()) { - go func() { - defer func() { - if e := recover(); e != nil { - err, ok := e.(error) - if ok { - c.connection.err.Set(err) - } else { - c.connection.err.Set(fmt.Errorf("%v", e)) - } - } - }() - fn() - }() -} - -func (c *channel) Send(method string, options ...interface{}) (interface{}, error) { - return c.connection.WrapAPICall(func() (interface{}, error) { - return c.innerSend(method, options...).GetResultValue() - }, c.owner.isInternalType) -} - -func (c *channel) SendReturnAsDict(method string, options ...interface{}) (map[string]interface{}, error) { - ret, err := c.connection.WrapAPICall(func() (interface{}, error) { - return c.innerSend(method, options...).GetResult() - }, c.owner.isInternalType) - return ret.(map[string]interface{}), err -} - -func (c *channel) innerSend(method string, options ...interface{}) *protocolCallback { - if err := c.connection.err.Get(); err != nil { - c.connection.err.Set(nil) - pc := newProtocolCallback(false, c.connection.abort) - pc.SetError(err) - return pc - } - params := transformOptions(options...) - return c.connection.sendMessageToServer(c.owner, method, params, false) -} - -// SendNoReply ignores return value and errors -// almost equivalent to `send(...).catch(() => {})` -func (c *channel) SendNoReply(method string, options ...interface{}) { - c.innerSendNoReply(method, c.owner.isInternalType, options...) -} - -func (c *channel) SendNoReplyInternal(method string, options ...interface{}) { - c.innerSendNoReply(method, true, options...) -} - -func (c *channel) innerSendNoReply(method string, isInternal bool, options ...interface{}) { - params := transformOptions(options...) - _, err := c.connection.WrapAPICall(func() (interface{}, error) { - return c.connection.sendMessageToServer(c.owner, method, params, true).GetResult() - }, isInternal) - if err != nil { - // ignore error actively, log only for debug - logger.Error("SendNoReply failed", "error", err) - } -} - -func newChannel(owner *channelOwner, object interface{}) *channel { - channel := &channel{ - connection: owner.connection, - guid: owner.guid, - owner: owner, - object: object, - } - return channel -} diff --git a/vendor/github.com/playwright-community/playwright-go/channel_owner.go b/vendor/github.com/playwright-community/playwright-go/channel_owner.go deleted file mode 100644 index 5159eb2..0000000 --- a/vendor/github.com/playwright-community/playwright-go/channel_owner.go +++ /dev/null @@ -1,122 +0,0 @@ -package playwright - -import ( - "sync" -) - -type channelOwner struct { - sync.RWMutex - eventEmitter - objectType string - guid string - channel *channel - objects map[string]*channelOwner - eventToSubscriptionMapping map[string]string - connection *connection - initializer map[string]interface{} - parent *channelOwner - wasCollected bool - isInternalType bool -} - -func (c *channelOwner) dispose(reason ...string) { - // Clean up from parent and connection. - if c.parent != nil { - delete(c.parent.objects, c.guid) - } - c.connection.objects.Delete(c.guid) - if len(reason) > 0 { - c.wasCollected = reason[0] == "gc" - } - - // Dispose all children. - for _, object := range c.objects { - object.dispose(reason...) - } - c.objects = make(map[string]*channelOwner) -} - -func (c *channelOwner) adopt(child *channelOwner) { - delete(child.parent.objects, child.guid) - c.objects[child.guid] = child - child.parent = c -} - -func (c *channelOwner) setEventSubscriptionMapping(mapping map[string]string) { - c.eventToSubscriptionMapping = mapping -} - -func (c *channelOwner) updateSubscription(event string, enabled bool) { - protocolEvent, ok := c.eventToSubscriptionMapping[event] - if ok { - c.channel.SendNoReplyInternal("updateSubscription", map[string]interface{}{ - "event": protocolEvent, - "enabled": enabled, - }) - } -} - -func (c *channelOwner) Once(name string, handler interface{}) { - c.addEvent(name, handler, true) -} - -func (c *channelOwner) On(name string, handler interface{}) { - c.addEvent(name, handler, false) -} - -func (c *channelOwner) addEvent(name string, handler interface{}, once bool) { - if c.ListenerCount(name) == 0 { - c.updateSubscription(name, true) - } - c.eventEmitter.addEvent(name, handler, once) -} - -func (c *channelOwner) RemoveListener(name string, handler interface{}) { - c.eventEmitter.RemoveListener(name, handler) - if c.ListenerCount(name) == 0 { - c.updateSubscription(name, false) - } -} - -func (c *channelOwner) createChannelOwner(self interface{}, parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) { - c.objectType = objectType - c.guid = guid - c.wasCollected = false - c.parent = parent - c.objects = make(map[string]*channelOwner) - c.initializer = initializer - if c.parent != nil { - c.connection = parent.connection - c.parent.objects[guid] = c - } - if c.connection != nil { - c.connection.objects.Store(guid, c) - } - c.channel = newChannel(c, self) - c.eventToSubscriptionMapping = map[string]string{} -} - -func (c *channelOwner) markAsInternalType() { - c.isInternalType = true -} - -type rootChannelOwner struct { - channelOwner -} - -func (r *rootChannelOwner) initialize() (*Playwright, error) { - ret, err := r.channel.SendReturnAsDict("initialize", map[string]interface{}{ - "sdkLanguage": "javascript", - }) - if err != nil { - return nil, err - } - return fromChannel(ret["playwright"]).(*Playwright), nil -} - -func newRootChannelOwner(connection *connection) *rootChannelOwner { - c := &rootChannelOwner{} - c.connection = connection - c.createChannelOwner(c, nil, "Root", "", make(map[string]interface{})) - return c -} diff --git a/vendor/github.com/playwright-community/playwright-go/clock.go b/vendor/github.com/playwright-community/playwright-go/clock.go deleted file mode 100644 index 8bab037..0000000 --- a/vendor/github.com/playwright-community/playwright-go/clock.go +++ /dev/null @@ -1,111 +0,0 @@ -package playwright - -import ( - "errors" - "time" -) - -type clockImpl struct { - browserCtx *browserContextImpl -} - -func newClock(bCtx *browserContextImpl) Clock { - return &clockImpl{ - browserCtx: bCtx, - } -} - -func (c *clockImpl) FastForward(ticks interface{}) error { - params, err := parseTicks(ticks) - if err != nil { - return err - } - - _, err = c.browserCtx.channel.Send("clockFastForward", params) - return err -} - -func (c *clockImpl) Install(options ...ClockInstallOptions) (err error) { - params := map[string]any{} - if len(options) == 1 { - if options[0].Time != nil { - params, err = parseTime(options[0].Time) - if err != nil { - return err - } - } - } - - _, err = c.browserCtx.channel.Send("clockInstall", params) - - return err -} - -func (c *clockImpl) PauseAt(time interface{}) error { - params, err := parseTime(time) - if err != nil { - return err - } - - _, err = c.browserCtx.channel.Send("clockPauseAt", params) - return err -} - -func (c *clockImpl) Resume() error { - _, err := c.browserCtx.channel.Send("clockResume") - return err -} - -func (c *clockImpl) RunFor(ticks interface{}) error { - params, err := parseTicks(ticks) - if err != nil { - return err - } - - _, err = c.browserCtx.channel.Send("clockRunFor", params) - return err -} - -func (c *clockImpl) SetFixedTime(time interface{}) error { - params, err := parseTime(time) - if err != nil { - return err - } - - _, err = c.browserCtx.channel.Send("clockSetFixedTime", params) - return err -} - -func (c *clockImpl) SetSystemTime(time interface{}) error { - params, err := parseTime(time) - if err != nil { - return err - } - - _, err = c.browserCtx.channel.Send("clockSetSystemTime", params) - return err -} - -func parseTime(t interface{}) (map[string]any, error) { - switch v := t.(type) { - case int, int64: - return map[string]any{"timeNumber": v}, nil - case string: - return map[string]any{"timeString": v}, nil - case time.Time: - return map[string]any{"timeNumber": v.UnixMilli()}, nil - default: - return nil, errors.New("time should be one of: int, int64, string, time.Time") - } -} - -func parseTicks(ticks interface{}) (map[string]any, error) { - switch v := ticks.(type) { - case int, int64: - return map[string]any{"ticksNumber": v}, nil - case string: - return map[string]any{"ticksString": v}, nil - default: - return nil, errors.New("ticks should be one of: int, int64, string") - } -} diff --git a/vendor/github.com/playwright-community/playwright-go/cmd/playwright/main.go b/vendor/github.com/playwright-community/playwright-go/cmd/playwright/main.go deleted file mode 100644 index 95e7d85..0000000 --- a/vendor/github.com/playwright-community/playwright-go/cmd/playwright/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "log" - "os" - - "github.com/playwright-community/playwright-go" -) - -func main() { - driver, err := playwright.NewDriver(&playwright.RunOptions{}) - if err != nil { - log.Fatalf("could not start driver: %v", err) - } - if err = driver.DownloadDriver(); err != nil { - log.Fatalf("could not download driver: %v", err) - } - cmd := driver.Command(os.Args[1:]...) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - if err := cmd.Run(); err != nil { - log.Fatalf("could not run driver: %v", err) - } - os.Exit(cmd.ProcessState.ExitCode()) -} diff --git a/vendor/github.com/playwright-community/playwright-go/connection.go b/vendor/github.com/playwright-community/playwright-go/connection.go deleted file mode 100644 index ba1e365..0000000 --- a/vendor/github.com/playwright-community/playwright-go/connection.go +++ /dev/null @@ -1,401 +0,0 @@ -package playwright - -import ( - "errors" - "fmt" - "reflect" - "regexp" - "strconv" - "strings" - "sync" - "sync/atomic" - "time" - - "github.com/go-stack/stack" - "github.com/playwright-community/playwright-go/internal/safe" -) - -var ( - pkgSourcePathPattern = regexp.MustCompile(`.+[\\/]playwright-go[\\/][^\\/]+\.go`) - apiNameTransform = regexp.MustCompile(`(?U)\(\*(.+)(Impl)?\)`) -) - -type connection struct { - transport transport - apiZone sync.Map - objects *safe.SyncMap[string, *channelOwner] - lastID atomic.Uint32 - rootObject *rootChannelOwner - callbacks *safe.SyncMap[uint32, *protocolCallback] - afterClose func() - onClose func() error - isRemote bool - localUtils *localUtilsImpl - tracingCount atomic.Int32 - abort chan struct{} - abortOnce sync.Once - err *safeValue[error] // for event listener error - closedError *safeValue[error] -} - -func (c *connection) Start() (*Playwright, error) { - go func() { - for { - msg, err := c.transport.Poll() - if err != nil { - _ = c.transport.Close() - c.cleanup(err) - return - } - c.Dispatch(msg) - } - }() - - c.onClose = func() error { - if err := c.transport.Close(); err != nil { - return err - } - return nil - } - - return c.rootObject.initialize() -} - -func (c *connection) Stop() error { - if err := c.onClose(); err != nil { - return err - } - c.cleanup() - return nil -} - -func (c *connection) cleanup(cause ...error) { - if len(cause) > 0 { - c.closedError.Set(fmt.Errorf("%w: %w", ErrTargetClosed, cause[0])) - } else { - c.closedError.Set(ErrTargetClosed) - } - if c.afterClose != nil { - c.afterClose() - } - c.abortOnce.Do(func() { - select { - case <-c.abort: - default: - close(c.abort) - } - }) -} - -func (c *connection) Dispatch(msg *message) { - if c.closedError.Get() != nil { - return - } - method := msg.Method - if msg.ID != 0 { - cb, _ := c.callbacks.LoadAndDelete(uint32(msg.ID)) - if cb.noReply { - return - } - if msg.Error != nil { - cb.SetError(parseError(msg.Error.Error)) - } else { - cb.SetResult(c.replaceGuidsWithChannels(msg.Result).(map[string]interface{})) - } - return - } - object, _ := c.objects.Load(msg.GUID) - if method == "__create__" { - c.createRemoteObject( - object, msg.Params["type"].(string), msg.Params["guid"].(string), msg.Params["initializer"], - ) - return - } - if object == nil { - return - } - if method == "__adopt__" { - child, ok := c.objects.Load(msg.Params["guid"].(string)) - if !ok { - return - } - object.adopt(child) - return - } - if method == "__dispose__" { - reason, ok := msg.Params["reason"] - if ok { - object.dispose(reason.(string)) - } else { - object.dispose() - } - return - } - if object.objectType == "JsonPipe" { - object.channel.Emit(method, msg.Params) - } else { - object.channel.Emit(method, c.replaceGuidsWithChannels(msg.Params)) - } -} - -func (c *connection) LocalUtils() *localUtilsImpl { - return c.localUtils -} - -func (c *connection) createRemoteObject(parent *channelOwner, objectType string, guid string, initializer interface{}) interface{} { - initializer = c.replaceGuidsWithChannels(initializer) - result := createObjectFactory(parent, objectType, guid, initializer.(map[string]interface{})) - return result -} - -func (c *connection) WrapAPICall(cb func() (interface{}, error), isInternal bool) (interface{}, error) { - if _, ok := c.apiZone.Load("apiZone"); ok { - return cb() - } - c.apiZone.Store("apiZone", serializeCallStack(isInternal)) - return cb() -} - -func (c *connection) replaceGuidsWithChannels(payload interface{}) interface{} { - if payload == nil { - return nil - } - v := reflect.ValueOf(payload) - if v.Kind() == reflect.Slice { - listV := payload.([]interface{}) - for i := 0; i < len(listV); i++ { - listV[i] = c.replaceGuidsWithChannels(listV[i]) - } - return listV - } - if v.Kind() == reflect.Map { - mapV := payload.(map[string]interface{}) - if guid, hasGUID := mapV["guid"]; hasGUID { - if channelOwner, ok := c.objects.Load(guid.(string)); ok { - return channelOwner.channel - } - } - for key := range mapV { - mapV[key] = c.replaceGuidsWithChannels(mapV[key]) - } - return mapV - } - return payload -} - -func (c *connection) sendMessageToServer(object *channelOwner, method string, params interface{}, noReply bool) (cb *protocolCallback) { - cb = newProtocolCallback(noReply, c.abort) - - if err := c.closedError.Get(); err != nil { - cb.SetError(err) - return - } - if object.wasCollected { - cb.SetError(errors.New("The object has been collected to prevent unbounded heap growth.")) - return - } - - id := c.lastID.Add(1) - c.callbacks.Store(id, cb) - var ( - metadata = make(map[string]interface{}, 0) - stack = make([]map[string]interface{}, 0) - ) - apiZone, ok := c.apiZone.LoadAndDelete("apiZone") - if ok { - for k, v := range apiZone.(parsedStackTrace).metadata { - metadata[k] = v - } - stack = append(stack, apiZone.(parsedStackTrace).frames...) - } - metadata["wallTime"] = time.Now().UnixMilli() - message := map[string]interface{}{ - "id": id, - "guid": object.guid, - "method": method, - "params": params, // channel.MarshalJSON will replace channel with guid - "metadata": metadata, - } - if c.tracingCount.Load() > 0 && len(stack) > 0 && object.guid != "localUtils" { - c.LocalUtils().AddStackToTracingNoReply(id, stack) - } - - if err := c.transport.Send(message); err != nil { - cb.SetError(fmt.Errorf("could not send message: %w", err)) - return - } - - return -} - -func (c *connection) setInTracing(isTracing bool) { - if isTracing { - c.tracingCount.Add(1) - } else { - c.tracingCount.Add(-1) - } -} - -type parsedStackTrace struct { - frames []map[string]interface{} - metadata map[string]interface{} -} - -func serializeCallStack(isInternal bool) parsedStackTrace { - st := stack.Trace().TrimRuntime() - if len(st) == 0 { // https://github.com/go-stack/stack/issues/27 - st = stack.Trace() - } - - lastInternalIndex := 0 - for i, s := range st { - if pkgSourcePathPattern.MatchString(s.Frame().File) { - lastInternalIndex = i - } - } - apiName := "" - if !isInternal { - apiName = fmt.Sprintf("%n", st[lastInternalIndex]) - } - st = st.TrimBelow(st[lastInternalIndex]) - - callStack := make([]map[string]interface{}, 0) - for i, s := range st { - if i == 0 { - continue - } - callStack = append(callStack, map[string]interface{}{ - "file": s.Frame().File, - "line": s.Frame().Line, - "column": 0, - "function": s.Frame().Function, - }) - } - metadata := make(map[string]interface{}) - if len(st) > 1 { - metadata["location"] = serializeCallLocation(st[1]) - } - apiName = apiNameTransform.ReplaceAllString(apiName, "$1") - if len(apiName) > 1 { - apiName = strings.ToUpper(apiName[:1]) + apiName[1:] - } - metadata["apiName"] = apiName - metadata["isInternal"] = isInternal - return parsedStackTrace{ - metadata: metadata, - frames: callStack, - } -} - -func serializeCallLocation(caller stack.Call) map[string]interface{} { - line, _ := strconv.Atoi(fmt.Sprintf("%d", caller)) - return map[string]interface{}{ - "file": fmt.Sprintf("%s", caller), - "line": line, - } -} - -func newConnection(transport transport, localUtils ...*localUtilsImpl) *connection { - connection := &connection{ - abort: make(chan struct{}, 1), - callbacks: safe.NewSyncMap[uint32, *protocolCallback](), - objects: safe.NewSyncMap[string, *channelOwner](), - transport: transport, - isRemote: false, - err: &safeValue[error]{}, - closedError: &safeValue[error]{}, - } - if len(localUtils) > 0 { - connection.localUtils = localUtils[0] - connection.isRemote = true - } - connection.rootObject = newRootChannelOwner(connection) - return connection -} - -func fromChannel(v interface{}) interface{} { - return v.(*channel).object -} - -func fromNullableChannel(v interface{}) interface{} { - if v == nil { - return nil - } - return fromChannel(v) -} - -type protocolCallback struct { - done chan struct{} - noReply bool - abort <-chan struct{} - once sync.Once - value map[string]interface{} - err error -} - -func (pc *protocolCallback) setResultOnce(result map[string]interface{}, err error) { - pc.once.Do(func() { - pc.value = result - pc.err = err - close(pc.done) - }) -} - -func (pc *protocolCallback) waitResult() { - if pc.noReply { - return - } - select { - case <-pc.done: // wait for result - return - case <-pc.abort: - select { - case <-pc.done: - return - default: - pc.err = errors.New("Connection closed") - return - } - } -} - -func (pc *protocolCallback) SetError(err error) { - pc.setResultOnce(nil, err) -} - -func (pc *protocolCallback) SetResult(result map[string]interface{}) { - pc.setResultOnce(result, nil) -} - -func (pc *protocolCallback) GetResult() (map[string]interface{}, error) { - pc.waitResult() - return pc.value, pc.err -} - -// GetResultValue returns value if the map has only one element -func (pc *protocolCallback) GetResultValue() (interface{}, error) { - pc.waitResult() - if len(pc.value) == 0 { // empty map treated as nil - return nil, pc.err - } - if len(pc.value) == 1 { - for key := range pc.value { - return pc.value[key], pc.err - } - } - - return pc.value, pc.err -} - -func newProtocolCallback(noReply bool, abort <-chan struct{}) *protocolCallback { - if noReply { - return &protocolCallback{ - noReply: true, - abort: abort, - } - } - return &protocolCallback{ - done: make(chan struct{}, 1), - abort: abort, - } -} diff --git a/vendor/github.com/playwright-community/playwright-go/console_message.go b/vendor/github.com/playwright-community/playwright-go/console_message.go deleted file mode 100644 index 4baf3f1..0000000 --- a/vendor/github.com/playwright-community/playwright-go/console_message.go +++ /dev/null @@ -1,47 +0,0 @@ -package playwright - -type consoleMessageImpl struct { - event map[string]interface{} - page Page -} - -func (c *consoleMessageImpl) Type() string { - return c.event["type"].(string) -} - -func (c *consoleMessageImpl) Text() string { - return c.event["text"].(string) -} - -func (c *consoleMessageImpl) String() string { - return c.Text() -} - -func (c *consoleMessageImpl) Args() []JSHandle { - args := c.event["args"].([]interface{}) - out := []JSHandle{} - for idx := range args { - out = append(out, fromChannel(args[idx]).(*jsHandleImpl)) - } - return out -} - -func (c *consoleMessageImpl) Location() *ConsoleMessageLocation { - location := &ConsoleMessageLocation{} - remapMapToStruct(c.event["location"], location) - return location -} - -func (c *consoleMessageImpl) Page() Page { - return c.page -} - -func newConsoleMessage(event map[string]interface{}) *consoleMessageImpl { - bt := &consoleMessageImpl{} - bt.event = event - page := fromNullableChannel(event["page"]) - if page != nil { - bt.page = page.(*pageImpl) - } - return bt -} diff --git a/vendor/github.com/playwright-community/playwright-go/dialog.go b/vendor/github.com/playwright-community/playwright-go/dialog.go deleted file mode 100644 index 8d13234..0000000 --- a/vendor/github.com/playwright-community/playwright-go/dialog.go +++ /dev/null @@ -1,48 +0,0 @@ -package playwright - -type dialogImpl struct { - channelOwner - page Page -} - -func (d *dialogImpl) Type() string { - return d.initializer["type"].(string) -} - -func (d *dialogImpl) Message() string { - return d.initializer["message"].(string) -} - -func (d *dialogImpl) DefaultValue() string { - return d.initializer["defaultValue"].(string) -} - -func (d *dialogImpl) Accept(promptTextInput ...string) error { - var promptText *string - if len(promptTextInput) == 1 { - promptText = &promptTextInput[0] - } - _, err := d.channel.Send("accept", map[string]interface{}{ - "promptText": promptText, - }) - return err -} - -func (d *dialogImpl) Dismiss() error { - _, err := d.channel.Send("dismiss") - return err -} - -func (d *dialogImpl) Page() Page { - return d.page -} - -func newDialog(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *dialogImpl { - bt := &dialogImpl{} - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - page := fromNullableChannel(initializer["page"]) - if page != nil { - bt.page = page.(*pageImpl) - } - return bt -} diff --git a/vendor/github.com/playwright-community/playwright-go/download.go b/vendor/github.com/playwright-community/playwright-go/download.go deleted file mode 100644 index b9d2024..0000000 --- a/vendor/github.com/playwright-community/playwright-go/download.go +++ /dev/null @@ -1,56 +0,0 @@ -package playwright - -type downloadImpl struct { - page *pageImpl - url string - suggestedFilename string - artifact *artifactImpl -} - -func (d *downloadImpl) String() string { - return d.SuggestedFilename() -} - -func (d *downloadImpl) Page() Page { - return d.page -} - -func (d *downloadImpl) URL() string { - return d.url -} - -func (d *downloadImpl) SuggestedFilename() string { - return d.suggestedFilename -} - -func (d *downloadImpl) Delete() error { - err := d.artifact.Delete() - return err -} - -func (d *downloadImpl) Failure() error { - return d.artifact.Failure() -} - -func (d *downloadImpl) Path() (string, error) { - path, err := d.artifact.PathAfterFinished() - return path, err -} - -func (d *downloadImpl) SaveAs(path string) error { - err := d.artifact.SaveAs(path) - return err -} - -func (d *downloadImpl) Cancel() error { - return d.artifact.Cancel() -} - -func newDownload(page *pageImpl, url string, suggestedFilename string, artifact *artifactImpl) *downloadImpl { - return &downloadImpl{ - page: page, - url: url, - suggestedFilename: suggestedFilename, - artifact: artifact, - } -} diff --git a/vendor/github.com/playwright-community/playwright-go/element_handle.go b/vendor/github.com/playwright-community/playwright-go/element_handle.go deleted file mode 100644 index 62c41ba..0000000 --- a/vendor/github.com/playwright-community/playwright-go/element_handle.go +++ /dev/null @@ -1,403 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "errors" - "fmt" - "os" -) - -type elementHandleImpl struct { - jsHandleImpl -} - -func (e *elementHandleImpl) AsElement() ElementHandle { - return e -} - -func (e *elementHandleImpl) OwnerFrame() (Frame, error) { - channel, err := e.channel.Send("ownerFrame") - if err != nil { - return nil, err - } - channelOwner := fromNullableChannel(channel) - if channelOwner == nil { - return nil, nil - } - return channelOwner.(*frameImpl), nil -} - -func (e *elementHandleImpl) ContentFrame() (Frame, error) { - channel, err := e.channel.Send("contentFrame") - if err != nil { - return nil, err - } - channelOwner := fromNullableChannel(channel) - if channelOwner == nil { - return nil, nil - } - return channelOwner.(*frameImpl), nil -} - -func (e *elementHandleImpl) GetAttribute(name string) (string, error) { - attribute, err := e.channel.Send("getAttribute", map[string]interface{}{ - "name": name, - }) - if attribute == nil { - return "", err - } - return attribute.(string), err -} - -func (e *elementHandleImpl) TextContent() (string, error) { - textContent, err := e.channel.Send("textContent") - if textContent == nil { - return "", err - } - return textContent.(string), err -} - -func (e *elementHandleImpl) InnerText() (string, error) { - innerText, err := e.channel.Send("innerText") - if innerText == nil { - return "", err - } - return innerText.(string), err -} - -func (e *elementHandleImpl) InnerHTML() (string, error) { - innerHTML, err := e.channel.Send("innerHTML") - if innerHTML == nil { - return "", err - } - return innerHTML.(string), err -} - -func (e *elementHandleImpl) DispatchEvent(typ string, initObjects ...interface{}) error { - var initObject interface{} - if len(initObjects) == 1 { - initObject = initObjects[0] - } - _, err := e.channel.Send("dispatchEvent", map[string]interface{}{ - "type": typ, - "eventInit": serializeArgument(initObject), - }) - return err -} - -func (e *elementHandleImpl) Hover(options ...ElementHandleHoverOptions) error { - _, err := e.channel.Send("hover", options) - return err -} - -func (e *elementHandleImpl) Click(options ...ElementHandleClickOptions) error { - _, err := e.channel.Send("click", options) - return err -} - -func (e *elementHandleImpl) Dblclick(options ...ElementHandleDblclickOptions) error { - _, err := e.channel.Send("dblclick", options) - return err -} - -func (e *elementHandleImpl) QuerySelector(selector string) (ElementHandle, error) { - channel, err := e.channel.Send("querySelector", map[string]interface{}{ - "selector": selector, - }) - if err != nil { - return nil, err - } - if channel == nil { - return nil, nil - } - return fromChannel(channel).(*elementHandleImpl), nil -} - -func (e *elementHandleImpl) QuerySelectorAll(selector string) ([]ElementHandle, error) { - channels, err := e.channel.Send("querySelectorAll", map[string]interface{}{ - "selector": selector, - }) - if err != nil { - return nil, err - } - elements := make([]ElementHandle, 0) - for _, channel := range channels.([]interface{}) { - elements = append(elements, fromChannel(channel).(*elementHandleImpl)) - } - return elements, nil -} - -func (e *elementHandleImpl) EvalOnSelector(selector string, expression string, options ...interface{}) (interface{}, error) { - var arg interface{} - if len(options) == 1 { - arg = options[0] - } - result, err := e.channel.Send("evalOnSelector", map[string]interface{}{ - "selector": selector, - "expression": expression, - "arg": serializeArgument(arg), - }) - if err != nil { - return nil, err - } - return parseResult(result), nil -} - -func (e *elementHandleImpl) EvalOnSelectorAll(selector string, expression string, options ...interface{}) (interface{}, error) { - var arg interface{} - if len(options) == 1 { - arg = options[0] - } - result, err := e.channel.Send("evalOnSelectorAll", map[string]interface{}{ - "selector": selector, - "expression": expression, - "arg": serializeArgument(arg), - }) - if err != nil { - return nil, err - } - return parseResult(result), nil -} - -func (e *elementHandleImpl) ScrollIntoViewIfNeeded(options ...ElementHandleScrollIntoViewIfNeededOptions) error { - _, err := e.channel.Send("scrollIntoViewIfNeeded", options) - if err != nil { - return err - } - return err -} - -func (e *elementHandleImpl) SetInputFiles(files interface{}, options ...ElementHandleSetInputFilesOptions) error { - frame, err := e.OwnerFrame() - if err != nil { - return err - } - if frame == nil { - return errors.New("Cannot set input files to detached element") - } - - params, err := convertInputFiles(files, frame.(*frameImpl).page.browserContext) - if err != nil { - return err - } - _, err = e.channel.Send("setInputFiles", params, options) - return err -} - -func (e *elementHandleImpl) BoundingBox() (*Rect, error) { - boundingBox, err := e.channel.Send("boundingBox") - if err != nil { - return nil, err - } - - if boundingBox == nil { - return nil, nil - } - - out := &Rect{} - remapMapToStruct(boundingBox, out) - return out, nil -} - -func (e *elementHandleImpl) Check(options ...ElementHandleCheckOptions) error { - _, err := e.channel.Send("check", options) - return err -} - -func (e *elementHandleImpl) Uncheck(options ...ElementHandleUncheckOptions) error { - _, err := e.channel.Send("uncheck", options) - return err -} - -func (e *elementHandleImpl) Press(key string, options ...ElementHandlePressOptions) error { - _, err := e.channel.Send("press", map[string]interface{}{ - "key": key, - }, options) - return err -} - -func (e *elementHandleImpl) Fill(value string, options ...ElementHandleFillOptions) error { - _, err := e.channel.Send("fill", map[string]interface{}{ - "value": value, - }, options) - return err -} - -func (e *elementHandleImpl) Type(value string, options ...ElementHandleTypeOptions) error { - _, err := e.channel.Send("type", map[string]interface{}{ - "text": value, - }, options) - return err -} - -func (e *elementHandleImpl) Focus() error { - _, err := e.channel.Send("focus") - return err -} - -func (e *elementHandleImpl) SelectText(options ...ElementHandleSelectTextOptions) error { - _, err := e.channel.Send("selectText", options) - return err -} - -func (e *elementHandleImpl) Screenshot(options ...ElementHandleScreenshotOptions) ([]byte, error) { - var path *string - overrides := map[string]interface{}{} - if len(options) == 1 { - path = options[0].Path - options[0].Path = nil - if options[0].Mask != nil { - masks := make([]map[string]interface{}, 0) - for _, m := range options[0].Mask { - if m.Err() != nil { // ErrLocatorNotSameFrame - return nil, m.Err() - } - l, ok := m.(*locatorImpl) - if ok { - masks = append(masks, map[string]interface{}{ - "selector": l.selector, - "frame": l.frame.channel, - }) - } - } - overrides["mask"] = masks - options[0].Mask = nil - } - } - data, err := e.channel.Send("screenshot", options, overrides) - if err != nil { - return nil, err - } - image, err := base64.StdEncoding.DecodeString(data.(string)) - if err != nil { - return nil, fmt.Errorf("could not decode base64 :%w", err) - } - if path != nil { - if err := os.WriteFile(*path, image, 0o644); err != nil { - return nil, err - } - } - return image, nil -} - -func (e *elementHandleImpl) Tap(options ...ElementHandleTapOptions) error { - _, err := e.channel.Send("tap", options) - return err -} - -func (e *elementHandleImpl) SelectOption(values SelectOptionValues, options ...ElementHandleSelectOptionOptions) ([]string, error) { - opts := convertSelectOptionSet(values) - selected, err := e.channel.Send("selectOption", opts, options) - if err != nil { - return nil, err - } - - return transformToStringList(selected), nil -} - -func (e *elementHandleImpl) IsChecked() (bool, error) { - checked, err := e.channel.Send("isChecked") - if err != nil { - return false, err - } - return checked.(bool), nil -} - -func (e *elementHandleImpl) IsDisabled() (bool, error) { - disabled, err := e.channel.Send("isDisabled") - if err != nil { - return false, err - } - return disabled.(bool), nil -} - -func (e *elementHandleImpl) IsEditable() (bool, error) { - editable, err := e.channel.Send("isEditable") - if err != nil { - return false, err - } - return editable.(bool), nil -} - -func (e *elementHandleImpl) IsEnabled() (bool, error) { - enabled, err := e.channel.Send("isEnabled") - if err != nil { - return false, err - } - return enabled.(bool), nil -} - -func (e *elementHandleImpl) IsHidden() (bool, error) { - hidden, err := e.channel.Send("isHidden") - if err != nil { - return false, err - } - return hidden.(bool), nil -} - -func (e *elementHandleImpl) IsVisible() (bool, error) { - visible, err := e.channel.Send("isVisible") - if err != nil { - return false, err - } - return visible.(bool), nil -} - -func (e *elementHandleImpl) WaitForElementState(state ElementState, options ...ElementHandleWaitForElementStateOptions) error { - _, err := e.channel.Send("waitForElementState", map[string]interface{}{ - "state": state, - }, options) - if err != nil { - return err - } - return nil -} - -func (e *elementHandleImpl) WaitForSelector(selector string, options ...ElementHandleWaitForSelectorOptions) (ElementHandle, error) { - ch, err := e.channel.Send("waitForSelector", map[string]interface{}{ - "selector": selector, - }, options) - if err != nil { - return nil, err - } - - channelOwner := fromNullableChannel(ch) - if channelOwner == nil { - return nil, nil - } - return channelOwner.(*elementHandleImpl), nil -} - -func (e *elementHandleImpl) InputValue(options ...ElementHandleInputValueOptions) (string, error) { - result, err := e.channel.Send("inputValue", options) - if result == nil { - return "", err - } - return result.(string), err -} - -func (e *elementHandleImpl) SetChecked(checked bool, options ...ElementHandleSetCheckedOptions) error { - if checked { - _, err := e.channel.Send("check", options) - return err - } else { - _, err := e.channel.Send("uncheck", options) - return err - } -} - -func newElementHandle(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *elementHandleImpl { - bt := &elementHandleImpl{} - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - return bt -} - -func transformToStringList(in interface{}) []string { - s := in.([]interface{}) - - var out []string - for _, v := range s { - out = append(out, v.(string)) - } - return out -} diff --git a/vendor/github.com/playwright-community/playwright-go/errors.go b/vendor/github.com/playwright-community/playwright-go/errors.go deleted file mode 100644 index 36f7396..0000000 --- a/vendor/github.com/playwright-community/playwright-go/errors.go +++ /dev/null @@ -1,58 +0,0 @@ -package playwright - -import ( - "errors" - "fmt" -) - -var ( - // ErrPlaywright wraps all Playwright errors. - // - Use errors.Is to check if the error is a Playwright error. - // - Use errors.As to cast an error to [Error] if you want to access "Stack". - ErrPlaywright = errors.New("playwright") - // ErrTargetClosed usually wraps a reason. - ErrTargetClosed = errors.New("target closed") - // ErrTimeout wraps timeout errors. It can be either Playwright TimeoutError or client timeout. - ErrTimeout = errors.New("timeout") -) - -// Error represents a Playwright error -type Error struct { - Name string `json:"name"` - Message string `json:"message"` - Stack string `json:"stack"` -} - -func (e *Error) Error() string { - return e.Message -} - -func (e *Error) Is(target error) bool { - err, ok := target.(*Error) - if !ok { - return false - } - if err.Name != e.Name { - return false - } - if e.Name != "Error" { - return true // same name and not normal error - } - return e.Message == err.Message -} - -func parseError(err Error) error { - if err.Name == "TimeoutError" { - return fmt.Errorf("%w: %w: %w", ErrPlaywright, ErrTimeout, &err) - } else if err.Name == "TargetClosedError" { - return fmt.Errorf("%w: %w: %w", ErrPlaywright, ErrTargetClosed, &err) - } - return fmt.Errorf("%w: %w", ErrPlaywright, &err) -} - -func targetClosedError(reason *string) error { - if reason == nil { - return ErrTargetClosed - } - return fmt.Errorf("%w: %s", ErrTargetClosed, *reason) -} diff --git a/vendor/github.com/playwright-community/playwright-go/event_emitter.go b/vendor/github.com/playwright-community/playwright-go/event_emitter.go deleted file mode 100644 index d4d62ef..0000000 --- a/vendor/github.com/playwright-community/playwright-go/event_emitter.go +++ /dev/null @@ -1,163 +0,0 @@ -package playwright - -import ( - "math" - "reflect" - "slices" - "sync" -) - -type EventEmitter interface { - Emit(name string, payload ...interface{}) bool - ListenerCount(name string) int - On(name string, handler interface{}) - Once(name string, handler interface{}) - RemoveListener(name string, handler interface{}) - RemoveListeners(name string) -} - -type ( - eventEmitter struct { - eventsMutex sync.Mutex - events map[string]*eventRegister - hasInit bool - } - eventRegister struct { - sync.Mutex - listeners []listener - } - listener struct { - handler interface{} - once bool - } -) - -func NewEventEmitter() EventEmitter { - return &eventEmitter{} -} - -func (e *eventEmitter) Emit(name string, payload ...interface{}) (hasListener bool) { - e.eventsMutex.Lock() - e.init() - - evt, ok := e.events[name] - if !ok { - e.eventsMutex.Unlock() - return - } - e.eventsMutex.Unlock() - return evt.callHandlers(payload...) > 0 -} - -func (e *eventEmitter) Once(name string, handler interface{}) { - e.addEvent(name, handler, true) -} - -func (e *eventEmitter) On(name string, handler interface{}) { - e.addEvent(name, handler, false) -} - -func (e *eventEmitter) RemoveListener(name string, handler interface{}) { - e.eventsMutex.Lock() - defer e.eventsMutex.Unlock() - e.init() - - if evt, ok := e.events[name]; ok { - evt.Lock() - defer evt.Unlock() - evt.removeHandler(handler) - } -} - -func (e *eventEmitter) RemoveListeners(name string) { - e.eventsMutex.Lock() - defer e.eventsMutex.Unlock() - e.init() - delete(e.events, name) -} - -// ListenerCount count the listeners by name, count all if name is empty -func (e *eventEmitter) ListenerCount(name string) int { - e.eventsMutex.Lock() - defer e.eventsMutex.Unlock() - e.init() - - if name != "" { - evt, ok := e.events[name] - if !ok { - return 0 - } - return evt.count() - } - - count := 0 - for key := range e.events { - count += e.events[key].count() - } - - return count -} - -func (e *eventEmitter) addEvent(name string, handler interface{}, once bool) { - e.eventsMutex.Lock() - defer e.eventsMutex.Unlock() - e.init() - - if _, ok := e.events[name]; !ok { - e.events[name] = &eventRegister{ - listeners: make([]listener, 0), - } - } - e.events[name].addHandler(handler, once) -} - -func (e *eventEmitter) init() { - if !e.hasInit { - e.events = make(map[string]*eventRegister, 0) - e.hasInit = true - } -} - -func (er *eventRegister) addHandler(handler interface{}, once bool) { - er.Lock() - defer er.Unlock() - er.listeners = append(er.listeners, listener{handler: handler, once: once}) -} - -func (er *eventRegister) count() int { - er.Lock() - defer er.Unlock() - return len(er.listeners) -} - -func (er *eventRegister) removeHandler(handler interface{}) { - handlerPtr := reflect.ValueOf(handler).Pointer() - - er.listeners = slices.DeleteFunc(er.listeners, func(l listener) bool { - return reflect.ValueOf(l.handler).Pointer() == handlerPtr - }) -} - -func (er *eventRegister) callHandlers(payloads ...interface{}) int { - payloadV := make([]reflect.Value, 0) - - for _, p := range payloads { - payloadV = append(payloadV, reflect.ValueOf(p)) - } - - handle := func(l listener) { - handlerV := reflect.ValueOf(l.handler) - handlerV.Call(payloadV[:int(math.Min(float64(handlerV.Type().NumIn()), float64(len(payloadV))))]) - } - - er.Lock() - defer er.Unlock() - count := len(er.listeners) - for _, l := range er.listeners { - if l.once { - defer er.removeHandler(l.handler) - } - handle(l) - } - return count -} diff --git a/vendor/github.com/playwright-community/playwright-go/fetch.go b/vendor/github.com/playwright-community/playwright-go/fetch.go deleted file mode 100644 index fc7f79f..0000000 --- a/vendor/github.com/playwright-community/playwright-go/fetch.go +++ /dev/null @@ -1,451 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "encoding/json" - "errors" - "fmt" - "os" - "strings" -) - -type apiRequestImpl struct { - *Playwright -} - -func (r *apiRequestImpl) NewContext(options ...APIRequestNewContextOptions) (APIRequestContext, error) { - overrides := map[string]interface{}{} - if len(options) == 1 { - if options[0].ClientCertificates != nil { - certs, err := transformClientCertificate(options[0].ClientCertificates) - if err != nil { - return nil, err - } - overrides["clientCertificates"] = certs - options[0].ClientCertificates = nil - } - if options[0].ExtraHttpHeaders != nil { - overrides["extraHTTPHeaders"] = serializeMapToNameAndValue(options[0].ExtraHttpHeaders) - options[0].ExtraHttpHeaders = nil - } - if options[0].StorageStatePath != nil { - var storageState *StorageState - storageString, err := os.ReadFile(*options[0].StorageStatePath) - if err != nil { - return nil, fmt.Errorf("could not read storage state file: %w", err) - } - err = json.Unmarshal(storageString, &storageState) - if err != nil { - return nil, fmt.Errorf("could not parse storage state file: %w", err) - } - options[0].StorageState = storageState - options[0].StorageStatePath = nil - } - } - - channel, err := r.channel.Send("newRequest", options, overrides) - if err != nil { - return nil, err - } - return fromChannel(channel).(*apiRequestContextImpl), nil -} - -func newApiRequestImpl(pw *Playwright) *apiRequestImpl { - return &apiRequestImpl{pw} -} - -type apiRequestContextImpl struct { - channelOwner - tracing *tracingImpl - closeReason *string -} - -func (r *apiRequestContextImpl) Dispose(options ...APIRequestContextDisposeOptions) error { - if len(options) == 1 { - r.closeReason = options[0].Reason - } - _, err := r.channel.Send("dispose", map[string]interface{}{ - "reason": r.closeReason, - }) - if errors.Is(err, ErrTargetClosed) { - return nil - } - return err -} - -func (r *apiRequestContextImpl) Delete(url string, options ...APIRequestContextDeleteOptions) (APIResponse, error) { - opts := APIRequestContextFetchOptions{ - Method: String("DELETE"), - } - if len(options) == 1 { - err := assignStructFields(&opts, options[0], false) - if err != nil { - return nil, err - } - } - - return r.Fetch(url, opts) -} - -func (r *apiRequestContextImpl) Fetch(urlOrRequest interface{}, options ...APIRequestContextFetchOptions) (APIResponse, error) { - switch v := urlOrRequest.(type) { - case string: - return r.innerFetch(v, nil, options...) - case Request: - return r.innerFetch("", v, options...) - default: - return nil, fmt.Errorf("urlOrRequest has unsupported type: %T", urlOrRequest) - } -} - -func (r *apiRequestContextImpl) innerFetch(url string, request Request, options ...APIRequestContextFetchOptions) (APIResponse, error) { - if r.closeReason != nil { - return nil, fmt.Errorf("%w: %s", ErrTargetClosed, *r.closeReason) - } - overrides := map[string]interface{}{} - if url != "" { - overrides["url"] = url - } else if request != nil { - overrides["url"] = request.URL() - } - - if len(options) == 1 { - if options[0].MaxRedirects != nil && *options[0].MaxRedirects < 0 { - return nil, errors.New("maxRedirects must be non-negative") - } - if options[0].MaxRetries != nil && *options[0].MaxRetries < 0 { - return nil, errors.New("maxRetries must be non-negative") - } - // only one of them can be specified - if countNonNil(options[0].Data, options[0].Form, options[0].Multipart) > 1 { - return nil, errors.New("only one of 'data', 'form' or 'multipart' can be specified") - } - if options[0].Method == nil { - if request != nil { - options[0].Method = String(request.Method()) - } else { - options[0].Method = String("GET") - } - } - if options[0].Headers == nil { - if request != nil { - overrides["headers"] = serializeMapToNameAndValue(request.Headers()) - } - } else { - overrides["headers"] = serializeMapToNameAndValue(options[0].Headers) - options[0].Headers = nil - } - if options[0].Data != nil { - switch v := options[0].Data.(type) { - case string: - headersArray, ok := overrides["headers"].([]map[string]string) - if ok && isJsonContentType(headersArray) { - if json.Valid([]byte(v)) { - overrides["jsonData"] = v - } else { - data, err := json.Marshal(v) - if err != nil { - return nil, fmt.Errorf("could not marshal data: %w", err) - } - overrides["jsonData"] = string(data) - } - } else { - overrides["postData"] = base64.StdEncoding.EncodeToString([]byte(v)) - } - case []byte: - overrides["postData"] = base64.StdEncoding.EncodeToString(v) - case interface{}: - data, err := json.Marshal(v) - if err != nil { - return nil, fmt.Errorf("could not marshal data: %w", err) - } - overrides["jsonData"] = string(data) - default: - return nil, errors.New("data must be a string, []byte, or interface{} that can marshal to json") - } - options[0].Data = nil - } else if options[0].Form != nil { - form, ok := options[0].Form.(map[string]interface{}) - if !ok { - return nil, errors.New("form must be a map") - } - overrides["formData"] = serializeMapToNameValue(form) - options[0].Form = nil - } else if options[0].Multipart != nil { - _, ok := options[0].Multipart.(map[string]interface{}) - if !ok { - return nil, errors.New("multipart must be a map") - } - multipartData := []map[string]interface{}{} - for name, value := range options[0].Multipart.(map[string]interface{}) { - switch v := value.(type) { - case InputFile: - multipartData = append(multipartData, map[string]interface{}{ - "name": name, - "file": map[string]string{ - "name": v.Name, - "mimeType": v.MimeType, - "buffer": base64.StdEncoding.EncodeToString(v.Buffer), - }, - }) - default: - multipartData = append(multipartData, map[string]interface{}{ - "name": name, - "value": String(fmt.Sprintf("%v", v)), - }) - } - } - overrides["multipartData"] = multipartData - options[0].Multipart = nil - } else if request != nil { - postDataBuf, err := request.PostDataBuffer() - if err == nil { - overrides["postData"] = base64.StdEncoding.EncodeToString(postDataBuf) - } - } - if options[0].Params != nil { - overrides["params"] = serializeMapToNameValue(options[0].Params) - options[0].Params = nil - } - } - - response, err := r.channel.Send("fetch", options, overrides) - if err != nil { - return nil, err - } - - return newAPIResponse(r, response.(map[string]interface{})), nil -} - -func (r *apiRequestContextImpl) Get(url string, options ...APIRequestContextGetOptions) (APIResponse, error) { - opts := APIRequestContextFetchOptions{ - Method: String("GET"), - } - if len(options) == 1 { - err := assignStructFields(&opts, options[0], false) - if err != nil { - return nil, err - } - } - - return r.Fetch(url, opts) -} - -func (r *apiRequestContextImpl) Head(url string, options ...APIRequestContextHeadOptions) (APIResponse, error) { - opts := APIRequestContextFetchOptions{ - Method: String("HEAD"), - } - if len(options) == 1 { - err := assignStructFields(&opts, options[0], false) - if err != nil { - return nil, err - } - } - - return r.Fetch(url, opts) -} - -func (r *apiRequestContextImpl) Patch(url string, options ...APIRequestContextPatchOptions) (APIResponse, error) { - opts := APIRequestContextFetchOptions{ - Method: String("PATCH"), - } - if len(options) == 1 { - err := assignStructFields(&opts, options[0], false) - if err != nil { - return nil, err - } - } - - return r.Fetch(url, opts) -} - -func (r *apiRequestContextImpl) Put(url string, options ...APIRequestContextPutOptions) (APIResponse, error) { - opts := APIRequestContextFetchOptions{ - Method: String("PUT"), - } - if len(options) == 1 { - err := assignStructFields(&opts, options[0], false) - if err != nil { - return nil, err - } - } - - return r.Fetch(url, opts) -} - -func (r *apiRequestContextImpl) Post(url string, options ...APIRequestContextPostOptions) (APIResponse, error) { - opts := APIRequestContextFetchOptions{ - Method: String("POST"), - } - if len(options) == 1 { - err := assignStructFields(&opts, options[0], false) - if err != nil { - return nil, err - } - } - - return r.Fetch(url, opts) -} - -func (r *apiRequestContextImpl) StorageState(path ...string) (*StorageState, error) { - result, err := r.channel.SendReturnAsDict("storageState") - if err != nil { - return nil, err - } - if len(path) == 1 { - file, err := os.Create(path[0]) - if err != nil { - return nil, err - } - if err := json.NewEncoder(file).Encode(result); err != nil { - return nil, err - } - if err := file.Close(); err != nil { - return nil, err - } - } - var storageState StorageState - remapMapToStruct(result, &storageState) - return &storageState, nil -} - -func newAPIRequestContext(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *apiRequestContextImpl { - rc := &apiRequestContextImpl{} - rc.createChannelOwner(rc, parent, objectType, guid, initializer) - rc.tracing = fromChannel(initializer["tracing"]).(*tracingImpl) - return rc -} - -type apiResponseImpl struct { - request *apiRequestContextImpl - initializer map[string]interface{} - headers *rawHeaders -} - -func (r *apiResponseImpl) Body() ([]byte, error) { - result, err := r.request.channel.SendReturnAsDict("fetchResponseBody", []map[string]interface{}{ - { - "fetchUid": r.fetchUid(), - }, - }) - if err != nil { - if errors.Is(err, ErrTargetClosed) { - return nil, errors.New("response has been disposed") - } - return nil, err - } - body := result["binary"] - if body == nil { - return nil, errors.New("response has been disposed") - } - return base64.StdEncoding.DecodeString(body.(string)) -} - -func (r *apiResponseImpl) Dispose() error { - _, err := r.request.channel.Send("disposeAPIResponse", []map[string]interface{}{ - { - "fetchUid": r.fetchUid(), - }, - }) - return err -} - -func (r *apiResponseImpl) Headers() map[string]string { - return r.headers.Headers() -} - -func (r *apiResponseImpl) HeadersArray() []NameValue { - return r.headers.HeadersArray() -} - -func (r *apiResponseImpl) JSON(v interface{}) error { - body, err := r.Body() - if err != nil { - return err - } - return json.Unmarshal(body, &v) -} - -func (r *apiResponseImpl) Ok() bool { - return r.Status() == 0 || (r.Status() >= 200 && r.Status() <= 299) -} - -func (r *apiResponseImpl) Status() int { - return int(r.initializer["status"].(float64)) -} - -func (r *apiResponseImpl) StatusText() string { - return r.initializer["statusText"].(string) -} - -func (r *apiResponseImpl) Text() (string, error) { - body, err := r.Body() - if err != nil { - return "", err - } - return string(body), nil -} - -func (r *apiResponseImpl) URL() string { - return r.initializer["url"].(string) -} - -func (r *apiResponseImpl) fetchUid() string { - return r.initializer["fetchUid"].(string) -} - -func (r *apiResponseImpl) fetchLog() ([]string, error) { - ret, err := r.request.channel.Send("fetchLog", map[string]interface{}{ - "fetchUid": r.fetchUid(), - }) - if err != nil { - return nil, err - } - result := make([]string, len(ret.([]interface{}))) - for i, v := range ret.([]interface{}) { - result[i] = v.(string) - } - return result, nil -} - -func newAPIResponse(context *apiRequestContextImpl, initializer map[string]interface{}) *apiResponseImpl { - return &apiResponseImpl{ - request: context, - initializer: initializer, - headers: newRawHeaders(initializer["headers"]), - } -} - -func countNonNil(args ...interface{}) int { - count := 0 - for _, v := range args { - if v != nil { - count++ - } - } - return count -} - -func isJsonContentType(headers []map[string]string) bool { - if len(headers) > 0 { - for _, v := range headers { - if strings.ToLower(v["name"]) == "content-type" { - if v["value"] == "application/json" { - return true - } - } - } - } - return false -} - -func serializeMapToNameValue(data map[string]interface{}) []map[string]string { - serialized := make([]map[string]string, 0, len(data)) - for k, v := range data { - serialized = append(serialized, map[string]string{ - "name": k, - "value": fmt.Sprintf("%v", v), - }) - } - return serialized -} diff --git a/vendor/github.com/playwright-community/playwright-go/file_chooser.go b/vendor/github.com/playwright-community/playwright-go/file_chooser.go deleted file mode 100644 index 119e885..0000000 --- a/vendor/github.com/playwright-community/playwright-go/file_chooser.go +++ /dev/null @@ -1,44 +0,0 @@ -package playwright - -type fileChooserImpl struct { - page Page - elementHandle ElementHandle - isMultiple bool -} - -func (f *fileChooserImpl) Page() Page { - return f.page -} - -func (f *fileChooserImpl) Element() ElementHandle { - return f.elementHandle -} - -func (f *fileChooserImpl) IsMultiple() bool { - return f.isMultiple -} - -// InputFile represents the input file for: -// - FileChooser.SetFiles() -// - ElementHandle.SetInputFiles() -// - Page.SetInputFiles() -type InputFile struct { - Name string `json:"name"` - MimeType string `json:"mimeType,omitempty"` - Buffer []byte `json:"buffer"` -} - -func (f *fileChooserImpl) SetFiles(files interface{}, options ...FileChooserSetFilesOptions) error { - if len(options) == 1 { - return f.elementHandle.SetInputFiles(files, ElementHandleSetInputFilesOptions(options[0])) - } - return f.elementHandle.SetInputFiles(files) -} - -func newFileChooser(page Page, elementHandle ElementHandle, isMultiple bool) *fileChooserImpl { - return &fileChooserImpl{ - page: page, - elementHandle: elementHandle, - isMultiple: isMultiple, - } -} diff --git a/vendor/github.com/playwright-community/playwright-go/frame.go b/vendor/github.com/playwright-community/playwright-go/frame.go deleted file mode 100644 index b571c8e..0000000 --- a/vendor/github.com/playwright-community/playwright-go/frame.go +++ /dev/null @@ -1,792 +0,0 @@ -package playwright - -import ( - "errors" - "fmt" - "os" - "time" - - mapset "github.com/deckarep/golang-set/v2" -) - -type frameImpl struct { - channelOwner - detached bool - page *pageImpl - name string - url string - parentFrame Frame - childFrames []Frame - loadStates mapset.Set[string] -} - -func newFrame(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *frameImpl { - var loadStates mapset.Set[string] - - if ls, ok := initializer["loadStates"].([]string); ok { - loadStates = mapset.NewSet[string](ls...) - } else { - loadStates = mapset.NewSet[string]() - } - f := &frameImpl{ - name: initializer["name"].(string), - url: initializer["url"].(string), - loadStates: loadStates, - childFrames: make([]Frame, 0), - } - f.createChannelOwner(f, parent, objectType, guid, initializer) - - channelOwner := fromNullableChannel(initializer["parentFrame"]) - if channelOwner != nil { - f.parentFrame = channelOwner.(*frameImpl) - f.parentFrame.(*frameImpl).childFrames = append(f.parentFrame.(*frameImpl).childFrames, f) - } - - f.channel.On("navigated", f.onFrameNavigated) - f.channel.On("loadstate", f.onLoadState) - return f -} - -func (f *frameImpl) URL() string { - f.RLock() - defer f.RUnlock() - return f.url -} - -func (f *frameImpl) Name() string { - f.RLock() - defer f.RUnlock() - return f.name -} - -func (f *frameImpl) SetContent(content string, options ...FrameSetContentOptions) error { - _, err := f.channel.Send("setContent", map[string]interface{}{ - "html": content, - }, options) - return err -} - -func (f *frameImpl) Content() (string, error) { - content, err := f.channel.Send("content") - if content == nil { - return "", err - } - return content.(string), err -} - -func (f *frameImpl) Goto(url string, options ...FrameGotoOptions) (Response, error) { - channel, err := f.channel.Send("goto", map[string]interface{}{ - "url": url, - }, options) - if err != nil { - return nil, fmt.Errorf("Frame.Goto %s: %w", url, err) - } - channelOwner := fromNullableChannel(channel) - if channelOwner == nil { - // navigation to about:blank or navigation to the same URL with a different hash - return nil, nil - } - return channelOwner.(*responseImpl), nil -} - -func (f *frameImpl) AddScriptTag(options FrameAddScriptTagOptions) (ElementHandle, error) { - if options.Path != nil { - file, err := os.ReadFile(*options.Path) - if err != nil { - return nil, err - } - options.Content = String(string(file)) - options.Path = nil - } - channel, err := f.channel.Send("addScriptTag", options) - if err != nil { - return nil, err - } - return fromChannel(channel).(*elementHandleImpl), nil -} - -func (f *frameImpl) AddStyleTag(options FrameAddStyleTagOptions) (ElementHandle, error) { - if options.Path != nil { - file, err := os.ReadFile(*options.Path) - if err != nil { - return nil, err - } - options.Content = String(string(file)) - options.Path = nil - } - channel, err := f.channel.Send("addStyleTag", options) - if err != nil { - return nil, err - } - return fromChannel(channel).(*elementHandleImpl), nil -} - -func (f *frameImpl) Page() Page { - return f.page -} - -func (f *frameImpl) WaitForLoadState(options ...FrameWaitForLoadStateOptions) error { - option := FrameWaitForLoadStateOptions{} - if len(options) == 1 { - option = options[0] - } - if option.State == nil { - option.State = LoadStateLoad - } - return f.waitForLoadStateImpl(string(*option.State), option.Timeout, nil) -} - -func (f *frameImpl) waitForLoadStateImpl(state string, timeout *float64, cb func() error) error { - if f.loadStates.ContainsOne(state) { - return nil - } - waiter, err := f.setNavigationWaiter(timeout) - if err != nil { - return err - } - waiter.WaitForEvent(f, "loadstate", func(payload interface{}) bool { - gotState := payload.(string) - return gotState == state - }) - if cb == nil { - _, err := waiter.Wait() - return err - } else { - _, err := waiter.RunAndWait(cb) - return err - } -} - -func (f *frameImpl) WaitForURL(url interface{}, options ...FrameWaitForURLOptions) error { - if f.page == nil { - return errors.New("frame is detached") - } - matcher := newURLMatcher(url, f.page.browserContext.options.BaseURL) - if matcher.Matches(f.URL()) { - state := "load" - timeout := Float(f.page.timeoutSettings.NavigationTimeout()) - if len(options) == 1 { - if options[0].WaitUntil != nil { - state = string(*options[0].WaitUntil) - } - if options[0].Timeout != nil { - timeout = options[0].Timeout - } - } - return f.waitForLoadStateImpl(state, timeout, nil) - } - navigationOptions := FrameExpectNavigationOptions{URL: url} - if len(options) > 0 { - navigationOptions.Timeout = options[0].Timeout - navigationOptions.WaitUntil = options[0].WaitUntil - } - if _, err := f.ExpectNavigation(nil, navigationOptions); err != nil { - return err - } - return nil -} - -func (f *frameImpl) ExpectNavigation(cb func() error, options ...FrameExpectNavigationOptions) (Response, error) { - if f.page == nil { - return nil, errors.New("frame is detached") - } - option := FrameExpectNavigationOptions{} - if len(options) == 1 { - option = options[0] - } - if option.WaitUntil == nil { - option.WaitUntil = WaitUntilStateLoad - } - if option.Timeout == nil { - option.Timeout = Float(f.page.timeoutSettings.NavigationTimeout()) - } - deadline := time.Now().Add(time.Duration(*option.Timeout) * time.Millisecond) - var matcher *urlMatcher - if option.URL != nil { - matcher = newURLMatcher(option.URL, f.page.browserContext.options.BaseURL) - } - predicate := func(events ...interface{}) bool { - ev := events[0].(map[string]interface{}) - err, ok := ev["error"] - if ok { - // Any failed navigation results in a rejection. - logger.Error("navigation error", "url", ev["url"].(string), "error", err) - return true - } - return matcher == nil || matcher.Matches(ev["url"].(string)) - } - waiter, err := f.setNavigationWaiter(option.Timeout) - if err != nil { - return nil, err - } - - eventData, err := waiter.WaitForEvent(f, "navigated", predicate).RunAndWait(cb) - if err != nil || eventData == nil { - return nil, err - } - - t := time.Until(deadline).Milliseconds() - if t > 0 { - err = f.waitForLoadStateImpl(string(*option.WaitUntil), Float(float64(t)), nil) - if err != nil { - return nil, err - } - } - event := eventData.(map[string]interface{}) - if event["newDocument"] != nil && event["newDocument"].(map[string]interface{})["request"] != nil { - request := fromChannel(event["newDocument"].(map[string]interface{})["request"]).(*requestImpl) - return request.Response() - } - return nil, nil -} - -func (f *frameImpl) setNavigationWaiter(timeout *float64) (*waiter, error) { - if f.page == nil { - return nil, errors.New("page does not exist") - } - waiter := newWaiter() - if timeout != nil { - waiter.WithTimeout(*timeout) - } else { - waiter.WithTimeout(f.page.timeoutSettings.NavigationTimeout()) - } - waiter.RejectOnEvent(f.page, "close", f.page.closeErrorWithReason()) - waiter.RejectOnEvent(f.page, "crash", fmt.Errorf("Navigation failed because page crashed!")) - waiter.RejectOnEvent(f.page, "framedetached", fmt.Errorf("Navigating frame was detached!"), func(payload interface{}) bool { - frame, ok := payload.(*frameImpl) - if ok && frame == f { - return true - } - return false - }) - return waiter, nil -} - -func (f *frameImpl) onFrameNavigated(ev map[string]interface{}) { - f.Lock() - f.url = ev["url"].(string) - f.name = ev["name"].(string) - f.Unlock() - f.Emit("navigated", ev) - _, ok := ev["error"] - if !ok && f.page != nil { - f.page.Emit("framenavigated", f) - } -} - -func (f *frameImpl) onLoadState(ev map[string]interface{}) { - if ev["add"] != nil { - add := ev["add"].(string) - f.loadStates.Add(add) - f.Emit("loadstate", add) - if f.parentFrame == nil && f.page != nil { - if add == "load" || add == "domcontentloaded" { - f.Page().Emit(add, f.page) - } - } - } else if ev["remove"] != nil { - remove := ev["remove"].(string) - f.loadStates.Remove(remove) - } -} - -func (f *frameImpl) QuerySelector(selector string, options ...FrameQuerySelectorOptions) (ElementHandle, error) { - params := map[string]interface{}{ - "selector": selector, - } - if len(options) == 1 { - params["strict"] = options[0].Strict - } - channel, err := f.channel.Send("querySelector", params) - if err != nil { - return nil, err - } - if channel == nil { - return nil, nil - } - return fromChannel(channel).(*elementHandleImpl), nil -} - -func (f *frameImpl) QuerySelectorAll(selector string) ([]ElementHandle, error) { - channels, err := f.channel.Send("querySelectorAll", map[string]interface{}{ - "selector": selector, - }) - if err != nil { - return nil, err - } - elements := make([]ElementHandle, 0) - for _, channel := range channels.([]interface{}) { - elements = append(elements, fromChannel(channel).(*elementHandleImpl)) - } - return elements, nil -} - -func (f *frameImpl) Evaluate(expression string, options ...interface{}) (interface{}, error) { - var arg interface{} - if len(options) == 1 { - arg = options[0] - } - result, err := f.channel.Send("evaluateExpression", map[string]interface{}{ - "expression": expression, - "arg": serializeArgument(arg), - }) - if err != nil { - return nil, err - } - return parseResult(result), nil -} - -func (f *frameImpl) EvalOnSelector(selector string, expression string, arg interface{}, options ...FrameEvalOnSelectorOptions) (interface{}, error) { - params := map[string]interface{}{ - "selector": selector, - "expression": expression, - "arg": serializeArgument(arg), - } - if len(options) == 1 && options[0].Strict != nil { - params["strict"] = *options[0].Strict - } - - result, err := f.channel.Send("evalOnSelector", params) - if err != nil { - return nil, err - } - return parseResult(result), nil -} - -func (f *frameImpl) EvalOnSelectorAll(selector string, expression string, options ...interface{}) (interface{}, error) { - var arg interface{} - if len(options) == 1 { - arg = options[0] - } - result, err := f.channel.Send("evalOnSelectorAll", map[string]interface{}{ - "selector": selector, - "expression": expression, - "arg": serializeArgument(arg), - }) - if err != nil { - return nil, err - } - return parseResult(result), nil -} - -func (f *frameImpl) EvaluateHandle(expression string, options ...interface{}) (JSHandle, error) { - var arg interface{} - if len(options) == 1 { - arg = options[0] - } - result, err := f.channel.Send("evaluateExpressionHandle", map[string]interface{}{ - "expression": expression, - "arg": serializeArgument(arg), - }) - if err != nil { - return nil, err - } - channelOwner := fromChannel(result) - if channelOwner == nil { - return nil, nil - } - return channelOwner.(JSHandle), nil -} - -func (f *frameImpl) Click(selector string, options ...FrameClickOptions) error { - _, err := f.channel.Send("click", map[string]interface{}{ - "selector": selector, - }, options) - return err -} - -func (f *frameImpl) WaitForSelector(selector string, options ...FrameWaitForSelectorOptions) (ElementHandle, error) { - channel, err := f.channel.Send("waitForSelector", map[string]interface{}{ - "selector": selector, - }, options) - if err != nil { - return nil, err - } - channelOwner := fromNullableChannel(channel) - if channelOwner == nil { - return nil, nil - } - return channelOwner.(*elementHandleImpl), nil -} - -func (f *frameImpl) DispatchEvent(selector, typ string, eventInit interface{}, options ...FrameDispatchEventOptions) error { - _, err := f.channel.Send("dispatchEvent", map[string]interface{}{ - "selector": selector, - "type": typ, - "eventInit": serializeArgument(eventInit), - }) - return err -} - -func (f *frameImpl) InnerText(selector string, options ...FrameInnerTextOptions) (string, error) { - innerText, err := f.channel.Send("innerText", map[string]interface{}{ - "selector": selector, - }, options) - if innerText == nil { - return "", err - } - return innerText.(string), err -} - -func (f *frameImpl) InnerHTML(selector string, options ...FrameInnerHTMLOptions) (string, error) { - innerHTML, err := f.channel.Send("innerHTML", map[string]interface{}{ - "selector": selector, - }, options) - if innerHTML == nil { - return "", err - } - return innerHTML.(string), err -} - -func (f *frameImpl) GetAttribute(selector string, name string, options ...FrameGetAttributeOptions) (string, error) { - attribute, err := f.channel.Send("getAttribute", map[string]interface{}{ - "selector": selector, - "name": name, - }, options) - if attribute == nil { - return "", err - } - return attribute.(string), err -} - -func (f *frameImpl) Hover(selector string, options ...FrameHoverOptions) error { - _, err := f.channel.Send("hover", map[string]interface{}{ - "selector": selector, - }, options) - return err -} - -func (f *frameImpl) SetInputFiles(selector string, files interface{}, options ...FrameSetInputFilesOptions) error { - params, err := convertInputFiles(files, f.page.browserContext) - if err != nil { - return err - } - params.Selector = &selector - _, err = f.channel.Send("setInputFiles", params, options) - return err -} - -func (f *frameImpl) Type(selector, text string, options ...FrameTypeOptions) error { - _, err := f.channel.Send("type", map[string]interface{}{ - "selector": selector, - "text": text, - }, options) - return err -} - -func (f *frameImpl) Press(selector, key string, options ...FramePressOptions) error { - _, err := f.channel.Send("press", map[string]interface{}{ - "selector": selector, - "key": key, - }, options) - return err -} - -func (f *frameImpl) Check(selector string, options ...FrameCheckOptions) error { - _, err := f.channel.Send("check", map[string]interface{}{ - "selector": selector, - }, options) - return err -} - -func (f *frameImpl) Uncheck(selector string, options ...FrameUncheckOptions) error { - _, err := f.channel.Send("uncheck", map[string]interface{}{ - "selector": selector, - }, options) - return err -} - -func (f *frameImpl) WaitForTimeout(timeout float64) { - time.Sleep(time.Duration(timeout) * time.Millisecond) -} - -func (f *frameImpl) WaitForFunction(expression string, arg interface{}, options ...FrameWaitForFunctionOptions) (JSHandle, error) { - var option FrameWaitForFunctionOptions - if len(options) == 1 { - option = options[0] - } - result, err := f.channel.Send("waitForFunction", map[string]interface{}{ - "expression": expression, - "arg": serializeArgument(arg), - "timeout": option.Timeout, - "polling": option.Polling, - }) - if err != nil { - return nil, err - } - handle := fromChannel(result) - if handle == nil { - return nil, nil - } - return handle.(*jsHandleImpl), nil -} - -func (f *frameImpl) Title() (string, error) { - title, err := f.channel.Send("title") - if title == nil { - return "", err - } - return title.(string), err -} - -func (f *frameImpl) ChildFrames() []Frame { - return f.childFrames -} - -func (f *frameImpl) Dblclick(selector string, options ...FrameDblclickOptions) error { - _, err := f.channel.Send("dblclick", map[string]interface{}{ - "selector": selector, - }, options) - return err -} - -func (f *frameImpl) Fill(selector string, value string, options ...FrameFillOptions) error { - _, err := f.channel.Send("fill", map[string]interface{}{ - "selector": selector, - "value": value, - }, options) - return err -} - -func (f *frameImpl) Focus(selector string, options ...FrameFocusOptions) error { - _, err := f.channel.Send("focus", map[string]interface{}{ - "selector": selector, - }, options) - return err -} - -func (f *frameImpl) FrameElement() (ElementHandle, error) { - channel, err := f.channel.Send("frameElement") - if err != nil { - return nil, err - } - return fromChannel(channel).(*elementHandleImpl), nil -} - -func (f *frameImpl) IsDetached() bool { - return f.detached -} - -func (f *frameImpl) ParentFrame() Frame { - return f.parentFrame -} - -func (f *frameImpl) TextContent(selector string, options ...FrameTextContentOptions) (string, error) { - textContent, err := f.channel.Send("textContent", map[string]interface{}{ - "selector": selector, - }, options) - if textContent == nil { - return "", err - } - return textContent.(string), err -} - -func (f *frameImpl) Tap(selector string, options ...FrameTapOptions) error { - _, err := f.channel.Send("tap", map[string]interface{}{ - "selector": selector, - }, options) - return err -} - -func (f *frameImpl) SelectOption(selector string, values SelectOptionValues, options ...FrameSelectOptionOptions) ([]string, error) { - opts := convertSelectOptionSet(values) - - m := make(map[string]interface{}) - m["selector"] = selector - for k, v := range opts { - m[k] = v - } - selected, err := f.channel.Send("selectOption", m, options) - if err != nil { - return nil, err - } - - return transformToStringList(selected), nil -} - -func (f *frameImpl) IsChecked(selector string, options ...FrameIsCheckedOptions) (bool, error) { - checked, err := f.channel.Send("isChecked", map[string]interface{}{ - "selector": selector, - }, options) - if err != nil { - return false, err - } - return checked.(bool), nil -} - -func (f *frameImpl) IsDisabled(selector string, options ...FrameIsDisabledOptions) (bool, error) { - disabled, err := f.channel.Send("isDisabled", map[string]interface{}{ - "selector": selector, - }, options) - if err != nil { - return false, err - } - return disabled.(bool), nil -} - -func (f *frameImpl) IsEditable(selector string, options ...FrameIsEditableOptions) (bool, error) { - editable, err := f.channel.Send("isEditable", map[string]interface{}{ - "selector": selector, - }, options) - if err != nil { - return false, err - } - return editable.(bool), nil -} - -func (f *frameImpl) IsEnabled(selector string, options ...FrameIsEnabledOptions) (bool, error) { - enabled, err := f.channel.Send("isEnabled", map[string]interface{}{ - "selector": selector, - }, options) - if err != nil { - return false, err - } - return enabled.(bool), nil -} - -func (f *frameImpl) IsHidden(selector string, options ...FrameIsHiddenOptions) (bool, error) { - hidden, err := f.channel.Send("isHidden", map[string]interface{}{ - "selector": selector, - }, options) - if err != nil { - return false, err - } - return hidden.(bool), nil -} - -func (f *frameImpl) IsVisible(selector string, options ...FrameIsVisibleOptions) (bool, error) { - visible, err := f.channel.Send("isVisible", map[string]interface{}{ - "selector": selector, - }, options) - if err != nil { - return false, err - } - return visible.(bool), nil -} - -func (f *frameImpl) InputValue(selector string, options ...FrameInputValueOptions) (string, error) { - value, err := f.channel.Send("inputValue", map[string]interface{}{ - "selector": selector, - }, options) - if value == nil { - return "", err - } - return value.(string), err -} - -func (f *frameImpl) DragAndDrop(source, target string, options ...FrameDragAndDropOptions) error { - _, err := f.channel.Send("dragAndDrop", map[string]interface{}{ - "source": source, - "target": target, - }, options) - return err -} - -func (f *frameImpl) SetChecked(selector string, checked bool, options ...FrameSetCheckedOptions) error { - if checked { - _, err := f.channel.Send("check", map[string]interface{}{ - "selector": selector, - }, options) - return err - } else { - _, err := f.channel.Send("uncheck", map[string]interface{}{ - "selector": selector, - }, options) - return err - } -} - -func (f *frameImpl) Locator(selector string, options ...FrameLocatorOptions) Locator { - var option LocatorOptions - if len(options) == 1 { - option = LocatorOptions{ - Has: options[0].Has, - HasNot: options[0].HasNot, - HasText: options[0].HasText, - HasNotText: options[0].HasNotText, - } - } - return newLocator(f, selector, option) -} - -func (f *frameImpl) GetByAltText(text interface{}, options ...FrameGetByAltTextOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return f.Locator(getByAltTextSelector(text, exact)) -} - -func (f *frameImpl) GetByLabel(text interface{}, options ...FrameGetByLabelOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return f.Locator(getByLabelSelector(text, exact)) -} - -func (f *frameImpl) GetByPlaceholder(text interface{}, options ...FrameGetByPlaceholderOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return f.Locator(getByPlaceholderSelector(text, exact)) -} - -func (f *frameImpl) GetByRole(role AriaRole, options ...FrameGetByRoleOptions) Locator { - if len(options) == 1 { - return f.Locator(getByRoleSelector(role, LocatorGetByRoleOptions(options[0]))) - } - return f.Locator(getByRoleSelector(role)) -} - -func (f *frameImpl) GetByTestId(testId interface{}) Locator { - return f.Locator(getByTestIdSelector(getTestIdAttributeName(), testId)) -} - -func (f *frameImpl) GetByText(text interface{}, options ...FrameGetByTextOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return f.Locator(getByTextSelector(text, exact)) -} - -func (f *frameImpl) GetByTitle(text interface{}, options ...FrameGetByTitleOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return f.Locator(getByTitleSelector(text, exact)) -} - -func (f *frameImpl) FrameLocator(selector string) FrameLocator { - return newFrameLocator(f, selector) -} - -func (f *frameImpl) highlight(selector string) error { - _, err := f.channel.Send("highlight", map[string]interface{}{ - "selector": selector, - }) - return err -} - -func (f *frameImpl) queryCount(selector string) (int, error) { - response, err := f.channel.Send("queryCount", map[string]interface{}{ - "selector": selector, - }) - if err != nil { - return 0, err - } - return int(response.(float64)), nil -} diff --git a/vendor/github.com/playwright-community/playwright-go/frame_locator.go b/vendor/github.com/playwright-community/playwright-go/frame_locator.go deleted file mode 100644 index d4b8fd0..0000000 --- a/vendor/github.com/playwright-community/playwright-go/frame_locator.go +++ /dev/null @@ -1,130 +0,0 @@ -package playwright - -import ( - "errors" - "fmt" - "strconv" -) - -type frameLocatorImpl struct { - frame *frameImpl - frameSelector string -} - -func newFrameLocator(frame *frameImpl, frameSelector string) *frameLocatorImpl { - return &frameLocatorImpl{frame: frame, frameSelector: frameSelector} -} - -func (fl *frameLocatorImpl) First() FrameLocator { - return newFrameLocator(fl.frame, fl.frameSelector+" >> nth=0") -} - -func (fl *frameLocatorImpl) FrameLocator(selector string) FrameLocator { - return newFrameLocator(fl.frame, fl.frameSelector+" >> internal:control=enter-frame >> "+selector) -} - -func (fl *frameLocatorImpl) GetByAltText(text interface{}, options ...FrameLocatorGetByAltTextOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return fl.Locator(getByAltTextSelector(text, exact)) -} - -func (fl *frameLocatorImpl) GetByLabel(text interface{}, options ...FrameLocatorGetByLabelOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return fl.Locator(getByLabelSelector(text, exact)) -} - -func (fl *frameLocatorImpl) GetByPlaceholder(text interface{}, options ...FrameLocatorGetByPlaceholderOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return fl.Locator(getByPlaceholderSelector(text, exact)) -} - -func (fl *frameLocatorImpl) GetByRole(role AriaRole, options ...FrameLocatorGetByRoleOptions) Locator { - if len(options) == 1 { - return fl.Locator(getByRoleSelector(role, LocatorGetByRoleOptions(options[0]))) - } - return fl.Locator(getByRoleSelector(role)) -} - -func (fl *frameLocatorImpl) GetByTestId(testId interface{}) Locator { - return fl.Locator(getByTestIdSelector(getTestIdAttributeName(), testId)) -} - -func (fl *frameLocatorImpl) GetByText(text interface{}, options ...FrameLocatorGetByTextOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return fl.Locator(getByTextSelector(text, exact)) -} - -func (fl *frameLocatorImpl) GetByTitle(text interface{}, options ...FrameLocatorGetByTitleOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return fl.Locator(getByTitleSelector(text, exact)) -} - -func (fl *frameLocatorImpl) Last() FrameLocator { - return newFrameLocator(fl.frame, fl.frameSelector+" >> nth=-1") -} - -func (fl *frameLocatorImpl) Locator(selectorOrLocator interface{}, options ...FrameLocatorLocatorOptions) Locator { - var option LocatorOptions - if len(options) == 1 { - option = LocatorOptions{ - Has: options[0].Has, - HasNot: options[0].HasNot, - HasText: options[0].HasText, - HasNotText: options[0].HasNotText, - } - } - - selector, ok := selectorOrLocator.(string) - if ok { - return newLocator(fl.frame, fl.frameSelector+" >> internal:control=enter-frame >> "+selector, option) - } - locator, ok := selectorOrLocator.(*locatorImpl) - if ok { - if fl.frame != locator.frame { - locator.err = errors.Join(locator.err, ErrLocatorNotSameFrame) - return locator - } - return newLocator(locator.frame, - fmt.Sprintf("%s >> internal:control=enter-frame >> %s", fl.frameSelector, locator.selector), - option, - ) - } - return &locatorImpl{ - frame: fl.frame, - selector: fl.frameSelector, - err: fmt.Errorf("invalid locator parameter: %v", selectorOrLocator), - } -} - -func (fl *frameLocatorImpl) Nth(index int) FrameLocator { - return newFrameLocator(fl.frame, fl.frameSelector+" >> nth="+strconv.Itoa(index)) -} - -func (fl *frameLocatorImpl) Owner() Locator { - return newLocator(fl.frame, fl.frameSelector) -} diff --git a/vendor/github.com/playwright-community/playwright-go/generated-enums.go b/vendor/github.com/playwright-community/playwright-go/generated-enums.go deleted file mode 100644 index 92c20c6..0000000 --- a/vendor/github.com/playwright-community/playwright-go/generated-enums.go +++ /dev/null @@ -1,404 +0,0 @@ -package playwright - -func getMixedState(in string) *MixedState { - v := MixedState(in) - return &v -} - -type MixedState string - -var ( - MixedStateOn *MixedState = getMixedState("On") - MixedStateOff = getMixedState("Off") - MixedStateMixed = getMixedState("Mixed") -) - -func getElementState(in string) *ElementState { - v := ElementState(in) - return &v -} - -type ElementState string - -var ( - ElementStateVisible *ElementState = getElementState("visible") - ElementStateHidden = getElementState("hidden") - ElementStateStable = getElementState("stable") - ElementStateEnabled = getElementState("enabled") - ElementStateDisabled = getElementState("disabled") - ElementStateEditable = getElementState("editable") -) - -func getAriaRole(in string) *AriaRole { - v := AriaRole(in) - return &v -} - -type AriaRole string - -var ( - AriaRoleAlert *AriaRole = getAriaRole("alert") - AriaRoleAlertdialog = getAriaRole("alertdialog") - AriaRoleApplication = getAriaRole("application") - AriaRoleArticle = getAriaRole("article") - AriaRoleBanner = getAriaRole("banner") - AriaRoleBlockquote = getAriaRole("blockquote") - AriaRoleButton = getAriaRole("button") - AriaRoleCaption = getAriaRole("caption") - AriaRoleCell = getAriaRole("cell") - AriaRoleCheckbox = getAriaRole("checkbox") - AriaRoleCode = getAriaRole("code") - AriaRoleColumnheader = getAriaRole("columnheader") - AriaRoleCombobox = getAriaRole("combobox") - AriaRoleComplementary = getAriaRole("complementary") - AriaRoleContentinfo = getAriaRole("contentinfo") - AriaRoleDefinition = getAriaRole("definition") - AriaRoleDeletion = getAriaRole("deletion") - AriaRoleDialog = getAriaRole("dialog") - AriaRoleDirectory = getAriaRole("directory") - AriaRoleDocument = getAriaRole("document") - AriaRoleEmphasis = getAriaRole("emphasis") - AriaRoleFeed = getAriaRole("feed") - AriaRoleFigure = getAriaRole("figure") - AriaRoleForm = getAriaRole("form") - AriaRoleGeneric = getAriaRole("generic") - AriaRoleGrid = getAriaRole("grid") - AriaRoleGridcell = getAriaRole("gridcell") - AriaRoleGroup = getAriaRole("group") - AriaRoleHeading = getAriaRole("heading") - AriaRoleImg = getAriaRole("img") - AriaRoleInsertion = getAriaRole("insertion") - AriaRoleLink = getAriaRole("link") - AriaRoleList = getAriaRole("list") - AriaRoleListbox = getAriaRole("listbox") - AriaRoleListitem = getAriaRole("listitem") - AriaRoleLog = getAriaRole("log") - AriaRoleMain = getAriaRole("main") - AriaRoleMarquee = getAriaRole("marquee") - AriaRoleMath = getAriaRole("math") - AriaRoleMeter = getAriaRole("meter") - AriaRoleMenu = getAriaRole("menu") - AriaRoleMenubar = getAriaRole("menubar") - AriaRoleMenuitem = getAriaRole("menuitem") - AriaRoleMenuitemcheckbox = getAriaRole("menuitemcheckbox") - AriaRoleMenuitemradio = getAriaRole("menuitemradio") - AriaRoleNavigation = getAriaRole("navigation") - AriaRoleNone = getAriaRole("none") - AriaRoleNote = getAriaRole("note") - AriaRoleOption = getAriaRole("option") - AriaRoleParagraph = getAriaRole("paragraph") - AriaRolePresentation = getAriaRole("presentation") - AriaRoleProgressbar = getAriaRole("progressbar") - AriaRoleRadio = getAriaRole("radio") - AriaRoleRadiogroup = getAriaRole("radiogroup") - AriaRoleRegion = getAriaRole("region") - AriaRoleRow = getAriaRole("row") - AriaRoleRowgroup = getAriaRole("rowgroup") - AriaRoleRowheader = getAriaRole("rowheader") - AriaRoleScrollbar = getAriaRole("scrollbar") - AriaRoleSearch = getAriaRole("search") - AriaRoleSearchbox = getAriaRole("searchbox") - AriaRoleSeparator = getAriaRole("separator") - AriaRoleSlider = getAriaRole("slider") - AriaRoleSpinbutton = getAriaRole("spinbutton") - AriaRoleStatus = getAriaRole("status") - AriaRoleStrong = getAriaRole("strong") - AriaRoleSubscript = getAriaRole("subscript") - AriaRoleSuperscript = getAriaRole("superscript") - AriaRoleSwitch = getAriaRole("switch") - AriaRoleTab = getAriaRole("tab") - AriaRoleTable = getAriaRole("table") - AriaRoleTablist = getAriaRole("tablist") - AriaRoleTabpanel = getAriaRole("tabpanel") - AriaRoleTerm = getAriaRole("term") - AriaRoleTextbox = getAriaRole("textbox") - AriaRoleTime = getAriaRole("time") - AriaRoleTimer = getAriaRole("timer") - AriaRoleToolbar = getAriaRole("toolbar") - AriaRoleTooltip = getAriaRole("tooltip") - AriaRoleTree = getAriaRole("tree") - AriaRoleTreegrid = getAriaRole("treegrid") - AriaRoleTreeitem = getAriaRole("treeitem") -) - -func getColorScheme(in string) *ColorScheme { - v := ColorScheme(in) - return &v -} - -type ColorScheme string - -var ( - ColorSchemeLight *ColorScheme = getColorScheme("light") - ColorSchemeDark = getColorScheme("dark") - ColorSchemeNoPreference = getColorScheme("no-preference") - ColorSchemeNoOverride = getColorScheme("no-override") -) - -func getForcedColors(in string) *ForcedColors { - v := ForcedColors(in) - return &v -} - -type ForcedColors string - -var ( - ForcedColorsActive *ForcedColors = getForcedColors("active") - ForcedColorsNone = getForcedColors("none") - ForcedColorsNoOverride = getForcedColors("no-override") -) - -func getHarContentPolicy(in string) *HarContentPolicy { - v := HarContentPolicy(in) - return &v -} - -type HarContentPolicy string - -var ( - HarContentPolicyOmit *HarContentPolicy = getHarContentPolicy("omit") - HarContentPolicyEmbed = getHarContentPolicy("embed") - HarContentPolicyAttach = getHarContentPolicy("attach") -) - -func getHarMode(in string) *HarMode { - v := HarMode(in) - return &v -} - -type HarMode string - -var ( - HarModeFull *HarMode = getHarMode("full") - HarModeMinimal = getHarMode("minimal") -) - -func getReducedMotion(in string) *ReducedMotion { - v := ReducedMotion(in) - return &v -} - -type ReducedMotion string - -var ( - ReducedMotionReduce *ReducedMotion = getReducedMotion("reduce") - ReducedMotionNoPreference = getReducedMotion("no-preference") - ReducedMotionNoOverride = getReducedMotion("no-override") -) - -func getServiceWorkerPolicy(in string) *ServiceWorkerPolicy { - v := ServiceWorkerPolicy(in) - return &v -} - -type ServiceWorkerPolicy string - -var ( - ServiceWorkerPolicyAllow *ServiceWorkerPolicy = getServiceWorkerPolicy("allow") - ServiceWorkerPolicyBlock = getServiceWorkerPolicy("block") -) - -func getSameSiteAttribute(in string) *SameSiteAttribute { - v := SameSiteAttribute(in) - return &v -} - -type SameSiteAttribute string - -var ( - SameSiteAttributeStrict *SameSiteAttribute = getSameSiteAttribute("Strict") - SameSiteAttributeLax = getSameSiteAttribute("Lax") - SameSiteAttributeNone = getSameSiteAttribute("None") -) - -func getHarNotFound(in string) *HarNotFound { - v := HarNotFound(in) - return &v -} - -type HarNotFound string - -var ( - HarNotFoundAbort *HarNotFound = getHarNotFound("abort") - HarNotFoundFallback = getHarNotFound("fallback") -) - -func getRouteFromHarUpdateContentPolicy(in string) *RouteFromHarUpdateContentPolicy { - v := RouteFromHarUpdateContentPolicy(in) - return &v -} - -type RouteFromHarUpdateContentPolicy string - -var ( - RouteFromHarUpdateContentPolicyEmbed *RouteFromHarUpdateContentPolicy = getRouteFromHarUpdateContentPolicy("embed") - RouteFromHarUpdateContentPolicyAttach = getRouteFromHarUpdateContentPolicy("attach") -) - -func getUnrouteBehavior(in string) *UnrouteBehavior { - v := UnrouteBehavior(in) - return &v -} - -type UnrouteBehavior string - -var ( - UnrouteBehaviorWait *UnrouteBehavior = getUnrouteBehavior("wait") - UnrouteBehaviorIgnoreErrors = getUnrouteBehavior("ignoreErrors") - UnrouteBehaviorDefault = getUnrouteBehavior("default") -) - -func getMouseButton(in string) *MouseButton { - v := MouseButton(in) - return &v -} - -type MouseButton string - -var ( - MouseButtonLeft *MouseButton = getMouseButton("left") - MouseButtonRight = getMouseButton("right") - MouseButtonMiddle = getMouseButton("middle") -) - -func getKeyboardModifier(in string) *KeyboardModifier { - v := KeyboardModifier(in) - return &v -} - -type KeyboardModifier string - -var ( - KeyboardModifierAlt *KeyboardModifier = getKeyboardModifier("Alt") - KeyboardModifierControl = getKeyboardModifier("Control") - KeyboardModifierControlOrMeta = getKeyboardModifier("ControlOrMeta") - KeyboardModifierMeta = getKeyboardModifier("Meta") - KeyboardModifierShift = getKeyboardModifier("Shift") -) - -func getScreenshotAnimations(in string) *ScreenshotAnimations { - v := ScreenshotAnimations(in) - return &v -} - -type ScreenshotAnimations string - -var ( - ScreenshotAnimationsDisabled *ScreenshotAnimations = getScreenshotAnimations("disabled") - ScreenshotAnimationsAllow = getScreenshotAnimations("allow") -) - -func getScreenshotCaret(in string) *ScreenshotCaret { - v := ScreenshotCaret(in) - return &v -} - -type ScreenshotCaret string - -var ( - ScreenshotCaretHide *ScreenshotCaret = getScreenshotCaret("hide") - ScreenshotCaretInitial = getScreenshotCaret("initial") -) - -func getScreenshotScale(in string) *ScreenshotScale { - v := ScreenshotScale(in) - return &v -} - -type ScreenshotScale string - -var ( - ScreenshotScaleCss *ScreenshotScale = getScreenshotScale("css") - ScreenshotScaleDevice = getScreenshotScale("device") -) - -func getScreenshotType(in string) *ScreenshotType { - v := ScreenshotType(in) - return &v -} - -type ScreenshotType string - -var ( - ScreenshotTypePng *ScreenshotType = getScreenshotType("png") - ScreenshotTypeJpeg = getScreenshotType("jpeg") -) - -func getWaitForSelectorState(in string) *WaitForSelectorState { - v := WaitForSelectorState(in) - return &v -} - -type WaitForSelectorState string - -var ( - WaitForSelectorStateAttached *WaitForSelectorState = getWaitForSelectorState("attached") - WaitForSelectorStateDetached = getWaitForSelectorState("detached") - WaitForSelectorStateVisible = getWaitForSelectorState("visible") - WaitForSelectorStateHidden = getWaitForSelectorState("hidden") -) - -func getWaitUntilState(in string) *WaitUntilState { - v := WaitUntilState(in) - return &v -} - -type WaitUntilState string - -var ( - WaitUntilStateLoad *WaitUntilState = getWaitUntilState("load") - WaitUntilStateDomcontentloaded = getWaitUntilState("domcontentloaded") - WaitUntilStateNetworkidle = getWaitUntilState("networkidle") - WaitUntilStateCommit = getWaitUntilState("commit") -) - -func getLoadState(in string) *LoadState { - v := LoadState(in) - return &v -} - -type LoadState string - -var ( - LoadStateLoad *LoadState = getLoadState("load") - LoadStateDomcontentloaded = getLoadState("domcontentloaded") - LoadStateNetworkidle = getLoadState("networkidle") -) - -func getContrast(in string) *Contrast { - v := Contrast(in) - return &v -} - -type Contrast string - -var ( - ContrastNoPreference *Contrast = getContrast("no-preference") - ContrastMore = getContrast("more") - ContrastNoOverride = getContrast("no-override") -) - -func getMedia(in string) *Media { - v := Media(in) - return &v -} - -type Media string - -var ( - MediaScreen *Media = getMedia("screen") - MediaPrint = getMedia("print") - MediaNoOverride = getMedia("no-override") -) - -func getHttpCredentialsSend(in string) *HttpCredentialsSend { - v := HttpCredentialsSend(in) - return &v -} - -type HttpCredentialsSend string - -var ( - HttpCredentialsSendUnauthorized *HttpCredentialsSend = getHttpCredentialsSend("unauthorized") - HttpCredentialsSendAlways = getHttpCredentialsSend("always") -) diff --git a/vendor/github.com/playwright-community/playwright-go/generated-interfaces.go b/vendor/github.com/playwright-community/playwright-go/generated-interfaces.go deleted file mode 100644 index 187dc91..0000000 --- a/vendor/github.com/playwright-community/playwright-go/generated-interfaces.go +++ /dev/null @@ -1,4658 +0,0 @@ -package playwright - -// Exposes API that can be used for the Web API testing. This class is used for creating [APIRequestContext] instance -// which in turn can be used for sending web requests. An instance of this class can be obtained via -// [Playwright.Request]. For more information see [APIRequestContext]. -type APIRequest interface { - // Creates new instances of [APIRequestContext]. - NewContext(options ...APIRequestNewContextOptions) (APIRequestContext, error) -} - -// This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, -// prepare environment or the service to your e2e test. -// Each Playwright browser context has associated with it [APIRequestContext] instance which shares cookie storage -// with the browser context and can be accessed via [BrowserContext.Request] or [Page.Request]. It is also possible to -// create a new APIRequestContext instance manually by calling [APIRequest.NewContext]. -// **Cookie management** -// [APIRequestContext] returned by [BrowserContext.Request] and [Page.Request] shares cookie storage with the -// corresponding [BrowserContext]. Each API request will have `Cookie` header populated with the values from the -// browser context. If the API response contains `Set-Cookie` header it will automatically update [BrowserContext] -// cookies and requests made from the page will pick them up. This means that if you log in using this API, your e2e -// test will be logged in and vice versa. -// If you want API requests to not interfere with the browser cookies you should create a new [APIRequestContext] by -// calling [APIRequest.NewContext]. Such `APIRequestContext` object will have its own isolated cookie storage. -type APIRequestContext interface { - // Sends HTTP(S) [DELETE] request and returns its - // response. The method will populate request cookies from the context and update context cookies from the response. - // The method will automatically follow redirects. - // - // url: Target URL. - // - // [DELETE]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE - Delete(url string, options ...APIRequestContextDeleteOptions) (APIResponse, error) - - // All responses returned by [APIRequestContext.Get] and similar methods are stored in the memory, so that you can - // later call [APIResponse.Body].This method discards all its resources, calling any method on disposed - // [APIRequestContext] will throw an exception. - Dispose(options ...APIRequestContextDisposeOptions) error - - // Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and - // update context cookies from the response. The method will automatically follow redirects. - // - // urlOrRequest: Target URL or Request to get all parameters from. - Fetch(urlOrRequest interface{}, options ...APIRequestContextFetchOptions) (APIResponse, error) - - // Sends HTTP(S) [GET] request and returns its - // response. The method will populate request cookies from the context and update context cookies from the response. - // The method will automatically follow redirects. - // - // url: Target URL. - // - // [GET]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET - Get(url string, options ...APIRequestContextGetOptions) (APIResponse, error) - - // Sends HTTP(S) [HEAD] request and returns its - // response. The method will populate request cookies from the context and update context cookies from the response. - // The method will automatically follow redirects. - // - // url: Target URL. - // - // [HEAD]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD - Head(url string, options ...APIRequestContextHeadOptions) (APIResponse, error) - - // Sends HTTP(S) [PATCH] request and returns its - // response. The method will populate request cookies from the context and update context cookies from the response. - // The method will automatically follow redirects. - // - // url: Target URL. - // - // [PATCH]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH - Patch(url string, options ...APIRequestContextPatchOptions) (APIResponse, error) - - // Sends HTTP(S) [POST] request and returns its - // response. The method will populate request cookies from the context and update context cookies from the response. - // The method will automatically follow redirects. - // - // url: Target URL. - // - // [POST]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST - Post(url string, options ...APIRequestContextPostOptions) (APIResponse, error) - - // Sends HTTP(S) [PUT] request and returns its - // response. The method will populate request cookies from the context and update context cookies from the response. - // The method will automatically follow redirects. - // - // url: Target URL. - // - // [PUT]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT - Put(url string, options ...APIRequestContextPutOptions) (APIResponse, error) - - // Returns storage state for this request context, contains current cookies and local storage snapshot if it was - // passed to the constructor. - StorageState(path ...string) (*StorageState, error) -} - -// [APIResponse] class represents responses returned by [APIRequestContext.Get] and similar methods. -type APIResponse interface { - // Returns the buffer with response body. - Body() ([]byte, error) - - // Disposes the body of this response. If not called then the body will stay in memory until the context closes. - Dispose() error - - // An object with all the response HTTP headers associated with this response. - Headers() map[string]string - - // An array with all the response HTTP headers associated with this response. Header names are not lower-cased. - // Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times. - HeadersArray() []NameValue - - // Returns the JSON representation of response body. - // This method will throw if the response body is not parsable via `JSON.parse`. - JSON(v interface{}) error - - // Contains a boolean stating whether the response was successful (status in the range 200-299) or not. - Ok() bool - - // Contains the status code of the response (e.g., 200 for a success). - Status() int - - // Contains the status text of the response (e.g. usually an "OK" for a success). - StatusText() string - - // Returns the text representation of response body. - Text() (string, error) - - // Contains the URL of the response. - URL() string -} - -// The [APIResponseAssertions] class provides assertion methods that can be used to make assertions about the -// [APIResponse] in the tests. -type APIResponseAssertions interface { - // Makes the assertion check for the opposite condition. For example, this code tests that the response status is not - // successful: - Not() APIResponseAssertions - - // Ensures the response status code is within `200..299` range. - ToBeOK() error -} - -// A Browser is created via [BrowserType.Launch]. An example of using a [Browser] to create a [Page]: -type Browser interface { - EventEmitter - // Emitted when Browser gets disconnected from the browser application. This might happen because of one of the - // following: - // - Browser application is closed or crashed. - // - The [Browser.Close] method was called. - OnDisconnected(fn func(Browser)) - - // Get the browser type (chromium, firefox or webkit) that the browser belongs to. - BrowserType() BrowserType - - // In case this browser is obtained using [BrowserType.Launch], closes the browser and all of its pages (if any were - // opened). - // In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from - // the browser server. - // **NOTE** This is similar to force-quitting the browser. To close pages gracefully and ensure you receive page close - // events, call [BrowserContext.Close] on any [BrowserContext] instances you explicitly created earlier using - // [Browser.NewContext] **before** calling [Browser.Close]. - // The [Browser] object itself is considered to be disposed and cannot be used anymore. - Close(options ...BrowserCloseOptions) error - - // Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts. - Contexts() []BrowserContext - - // Indicates that the browser is connected. - IsConnected() bool - - // **NOTE** CDP Sessions are only supported on Chromium-based browsers. - // Returns the newly created browser session. - NewBrowserCDPSession() (CDPSession, error) - - // Creates a new browser context. It won't share cookies/cache with other browser contexts. - // **NOTE** If directly using this method to create [BrowserContext]s, it is best practice to explicitly close the - // returned context via [BrowserContext.Close] when your code is done with the [BrowserContext], and before calling - // [Browser.Close]. This will ensure the `context` is closed gracefully and any artifacts—like HARs and videos—are - // fully flushed and saved. - NewContext(options ...BrowserNewContextOptions) (BrowserContext, error) - - // Creates a new page in a new browser context. Closing this page will close the context as well. - // This is a convenience API that should only be used for the single-page scenarios and short snippets. Production - // code and testing frameworks should explicitly create [Browser.NewContext] followed by the [BrowserContext.NewPage] - // to control their exact life times. - NewPage(options ...BrowserNewPageOptions) (Page, error) - - // **NOTE** This API controls - // [Chromium Tracing] which is a low-level - // chromium-specific debugging tool. API to control [Playwright Tracing] could be found - // [here]. - // You can use [Browser.StartTracing] and [Browser.StopTracing] to create a trace file that can be opened in Chrome - // DevTools performance panel. - // - // [Chromium Tracing]: https://www.chromium.org/developers/how-tos/trace-event-profiling-tool - // [Playwright Tracing]: ../trace-viewer - // [here]: ./class-tracing - StartTracing(options ...BrowserStartTracingOptions) error - - // **NOTE** This API controls - // [Chromium Tracing] which is a low-level - // chromium-specific debugging tool. API to control [Playwright Tracing] could be found - // [here]. - // Returns the buffer with trace data. - // - // [Chromium Tracing]: https://www.chromium.org/developers/how-tos/trace-event-profiling-tool - // [Playwright Tracing]: ../trace-viewer - // [here]: ./class-tracing - StopTracing() ([]byte, error) - - // Returns the browser version. - Version() string -} - -// BrowserContexts provide a way to operate multiple independent browser sessions. -// If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser -// context. -// Playwright allows creating isolated non-persistent browser contexts with [Browser.NewContext] method. -// Non-persistent browser contexts don't write any browsing data to disk. -type BrowserContext interface { - EventEmitter - // **NOTE** Only works with Chromium browser's persistent context. - // Emitted when new background page is created in the context. - OnBackgroundPage(fn func(Page)) - - // Playwright has ability to mock clock and passage of time. - Clock() Clock - - // Emitted when Browser context gets closed. This might happen because of one of the following: - // - Browser context is closed. - // - Browser application is closed or crashed. - // - The [Browser.Close] method was called. - OnClose(fn func(BrowserContext)) - - // Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. - // The arguments passed into `console.log` and the page are available on the [ConsoleMessage] event handler argument. - OnConsole(fn func(ConsoleMessage)) - - // Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must** - // either [Dialog.Accept] or [Dialog.Dismiss] the dialog - otherwise the page will - // [freeze] waiting for the dialog, - // and actions like click will never finish. - // - // [freeze]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking - OnDialog(fn func(Dialog)) - - // The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event - // will also fire for popup pages. See also [Page.OnPopup] to receive events about popups relevant to a specific page. - // The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a - // popup with `window.open('http://example.com')`, this event will fire when the network request to - // "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen - // to this network request, use [BrowserContext.Route] and [BrowserContext.OnRequest] respectively instead of similar - // methods on the [Page]. - // **NOTE** Use [Page.WaitForLoadState] to wait until the page gets to a particular state (you should not need it in - // most cases). - OnPage(fn func(Page)) - - // Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular - // page, use [Page.OnPageError] instead. - OnWebError(fn func(WebError)) - - // Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To - // only listen for requests from a particular page, use [Page.OnRequest]. - // In order to intercept and mutate requests, see [BrowserContext.Route] or [Page.Route]. - OnRequest(fn func(Request)) - - // Emitted when a request fails, for example by timing out. To only listen for failed requests from a particular page, - // use [Page.OnRequestFailed]. - // **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request - // will complete with [BrowserContext.OnRequestFinished] event and not with [BrowserContext.OnRequestFailed]. - OnRequestFailed(fn func(Request)) - - // Emitted when a request finishes successfully after downloading the response body. For a successful response, the - // sequence of events is `request`, `response` and `requestfinished`. To listen for successful requests from a - // particular page, use [Page.OnRequestFinished]. - OnRequestFinished(fn func(Request)) - - // Emitted when [response] status and headers are received for a request. For a successful response, the sequence of - // events is `request`, `response` and `requestfinished`. To listen for response events from a particular page, use - // [Page.OnResponse]. - OnResponse(fn func(Response)) - - // Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies - // can be obtained via [BrowserContext.Cookies]. - AddCookies(cookies []OptionalCookie) error - - // Adds a script which would be evaluated in one of the following scenarios: - // - Whenever a page is created in the browser context or is navigated. - // - Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is - // evaluated in the context of the newly attached frame. - // The script is evaluated after the document was created but before any of its scripts were run. This is useful to - // amend the JavaScript environment, e.g. to seed `Math.random`. - // - // script: Script to be evaluated in all pages in the browser context. - AddInitScript(script Script) error - - // **NOTE** Background pages are only supported on Chromium-based browsers. - // All existing background pages in the context. - BackgroundPages() []Page - - // Returns the browser instance of the context. If it was launched as a persistent context null gets returned. - Browser() Browser - - // Removes cookies from context. Accepts optional filter. - ClearCookies(options ...BrowserContextClearCookiesOptions) error - - // Clears all permission overrides for the browser context. - ClearPermissions() error - - // Closes the browser context. All the pages that belong to the browser context will be closed. - // **NOTE** The default browser context cannot be closed. - Close(options ...BrowserContextCloseOptions) error - - // If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those - // URLs are returned. - Cookies(urls ...string) ([]Cookie, error) - - // The method adds a function called “[object Object]” on the `window` object of every frame in every page in the - // context. When called, the function executes “[object Object]” and returns a [Promise] which resolves to the return - // value of “[object Object]”. If the “[object Object]” returns a [Promise], it will be awaited. - // The first argument of the “[object Object]” function contains information about the caller: `{ browserContext: - // BrowserContext, page: Page, frame: Frame }`. - // See [Page.ExposeBinding] for page-only version. - // - // 1. name: Name of the function on the window object. - // 2. binding: Callback function that will be called in the Playwright's context. - ExposeBinding(name string, binding BindingCallFunction, handle ...bool) error - - // The method adds a function called “[object Object]” on the `window` object of every frame in every page in the - // context. When called, the function executes “[object Object]” and returns a [Promise] which resolves to the return - // value of “[object Object]”. - // If the “[object Object]” returns a [Promise], it will be awaited. - // See [Page.ExposeFunction] for page-only version. - // - // 1. name: Name of the function on the window object. - // 2. binding: Callback function that will be called in the Playwright's context. - ExposeFunction(name string, binding ExposedFunction) error - - // Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if - // specified. - // - // permissions: A list of permissions to grant. - // - // **NOTE** Supported permissions differ between browsers, and even between different versions of the same browser. - // Any permission may stop working after an update. - // - // Here are some permissions that may be supported by some browsers: - // - `'accelerometer'` - // - `'ambient-light-sensor'` - // - `'background-sync'` - // - `'camera'` - // - `'clipboard-read'` - // - `'clipboard-write'` - // - `'geolocation'` - // - `'gyroscope'` - // - `'magnetometer'` - // - `'microphone'` - // - `'midi-sysex'` (system-exclusive midi) - // - `'midi'` - // - `'notifications'` - // - `'payment-handler'` - // - `'storage-access'` - GrantPermissions(permissions []string, options ...BrowserContextGrantPermissionsOptions) error - - // **NOTE** CDP sessions are only supported on Chromium-based browsers. - // Returns the newly created session. - // - // page: Target to create new session for. For backwards-compatibility, this parameter is named `page`, but it can be a - // `Page` or `Frame` type. - NewCDPSession(page interface{}) (CDPSession, error) - - // Creates a new page in the browser context. - NewPage() (Page, error) - - // Returns all open pages in the context. - Pages() []Page - - // API testing helper associated with this context. Requests made with this API will use context cookies. - Request() APIRequestContext - - // Routing provides the capability to modify network requests that are made by any page in the browser context. Once - // route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted. - // **NOTE** [BrowserContext.Route] will not intercept requests intercepted by Service Worker. See - // [this] issue. We recommend disabling Service Workers when - // using request interception by setting “[object Object]” to `block`. - // - // 1. url: A glob pattern, regex pattern, or predicate that receives a [URL] to match during routing. If “[object Object]” is - // set in the context options and the provided URL is a string that does not start with `*`, it is resolved using the - // [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. - // 2. handler: handler function to route the request. - // - // [this]: https://github.com/microsoft/playwright/issues/1090 - Route(url interface{}, handler routeHandler, times ...int) error - - // If specified the network requests that are made in the context will be served from the HAR file. Read more about - // [Replaying from HAR]. - // Playwright will not serve requests intercepted by Service Worker from the HAR file. See - // [this] issue. We recommend disabling Service Workers when - // using request interception by setting “[object Object]” to `block`. - // - // har: Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a - // relative path, then it is resolved relative to the current working directory. - // - // [Replaying from HAR]: https://playwright.dev/docs/mock#replaying-from-har - // [this]: https://github.com/microsoft/playwright/issues/1090 - RouteFromHAR(har string, options ...BrowserContextRouteFromHAROptions) error - - // This method allows to modify websocket connections that are made by any page in the browser context. - // Note that only `WebSocket`s created after this method was called will be routed. It is recommended to call this - // method before creating any pages. - // - // 1. url: Only WebSockets with the url matching this pattern will be routed. A string pattern can be relative to the - // “[object Object]” context option. - // 2. handler: Handler function to route the WebSocket. - RouteWebSocket(url interface{}, handler func(WebSocketRoute)) error - - // **NOTE** Service workers are only supported on Chromium-based browsers. - // All existing service workers in the context. - ServiceWorkers() []Worker - - // This setting will change the default maximum navigation time for the following methods and related shortcuts: - // - [Page.GoBack] - // - [Page.GoForward] - // - [Page.Goto] - // - [Page.Reload] - // - [Page.SetContent] - // - [Page.ExpectNavigation] - // **NOTE** [Page.SetDefaultNavigationTimeout] and [Page.SetDefaultTimeout] take priority over - // [BrowserContext.SetDefaultNavigationTimeout]. - // - // timeout: Maximum navigation time in milliseconds - SetDefaultNavigationTimeout(timeout float64) - - // This setting will change the default maximum time for all the methods accepting “[object Object]” option. - // **NOTE** [Page.SetDefaultNavigationTimeout], [Page.SetDefaultTimeout] and - // [BrowserContext.SetDefaultNavigationTimeout] take priority over [BrowserContext.SetDefaultTimeout]. - // - // timeout: Maximum time in milliseconds. Pass `0` to disable timeout. - SetDefaultTimeout(timeout float64) - - // The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are - // merged with page-specific extra HTTP headers set with [Page.SetExtraHTTPHeaders]. If page overrides a particular - // header, page-specific header value will be used instead of the browser context header value. - // **NOTE** [BrowserContext.SetExtraHTTPHeaders] does not guarantee the order of headers in the outgoing requests. - // - // headers: An object containing additional HTTP headers to be sent with every request. All header values must be strings. - SetExtraHTTPHeaders(headers map[string]string) error - - // Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable. - SetGeolocation(geolocation *Geolocation) error - - // - // offline: Whether to emulate network being offline for the browser context. - SetOffline(offline bool) error - - // Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB - // snapshot. - StorageState(path ...string) (*StorageState, error) - - Tracing() Tracing - - // Removes all routes created with [BrowserContext.Route] and [BrowserContext.RouteFromHAR]. - UnrouteAll(options ...BrowserContextUnrouteAllOptions) error - - // Removes a route created with [BrowserContext.Route]. When “[object Object]” is not specified, removes all routes - // for the “[object Object]”. - // - // 1. url: A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with [BrowserContext.Route]. - // 2. handler: Optional handler function used to register a routing with [BrowserContext.Route]. - Unroute(url interface{}, handler ...routeHandler) error - - // Performs action and waits for a [ConsoleMessage] to be logged by in the pages in the context. If predicate is - // provided, it passes [ConsoleMessage] value into the `predicate` function and waits for `predicate(message)` to - // return a truthy value. Will throw an error if the page is closed before the [BrowserContext.OnConsole] event is - // fired. - ExpectConsoleMessage(cb func() error, options ...BrowserContextExpectConsoleMessageOptions) (ConsoleMessage, error) - - // Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy - // value. Will throw an error if the context closes before the event is fired. Returns the event data value. - // - // event: Event name, same one would pass into `browserContext.on(event)`. - ExpectEvent(event string, cb func() error, options ...BrowserContextExpectEventOptions) (interface{}, error) - - // Performs action and waits for a new [Page] to be created in the context. If predicate is provided, it passes [Page] - // value into the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error - // if the context closes before new [Page] is created. - ExpectPage(cb func() error, options ...BrowserContextExpectPageOptions) (Page, error) - - // **NOTE** In most cases, you should use [BrowserContext.ExpectEvent]. - // Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function - // and waits for `predicate(event)` to return a truthy value. Will throw an error if the browser context is closed - // before the `event` is fired. - // - // event: Event name, same one typically passed into `*.on(event)`. - WaitForEvent(event string, options ...BrowserContextWaitForEventOptions) (interface{}, error) -} - -// BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is -// a typical example of using Playwright to drive automation: -type BrowserType interface { - // This method attaches Playwright to an existing browser instance created via `BrowserType.launchServer` in Node.js. - // **NOTE** The major and minor version of the Playwright instance that connects needs to match the version of - // Playwright that launches the browser (1.2.3 → is compatible with 1.2.x). - // - // wsEndpoint: A Playwright browser websocket endpoint to connect to. You obtain this endpoint via `BrowserServer.wsEndpoint`. - Connect(wsEndpoint string, options ...BrowserTypeConnectOptions) (Browser, error) - - // This method attaches Playwright to an existing browser instance using the Chrome DevTools Protocol. - // The default browser context is accessible via [Browser.Contexts]. - // **NOTE** Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers. - // **NOTE** This connection is significantly lower fidelity than the Playwright protocol connection via - // [BrowserType.Connect]. If you are experiencing issues or attempting to use advanced functionality, you probably - // want to use [BrowserType.Connect]. - // - // endpointURL: A CDP websocket endpoint or http url to connect to. For example `http://localhost:9222/` or - // `ws://127.0.0.1:9222/devtools/browser/387adf4c-243f-4051-a181-46798f4a46f4`. - ConnectOverCDP(endpointURL string, options ...BrowserTypeConnectOverCDPOptions) (Browser, error) - - // A path where Playwright expects to find a bundled browser executable. - ExecutablePath() string - - // Returns the browser instance. - // - // [Chrome Canary]: https://www.google.com/chrome/browser/canary.html - // [Dev Channel]: https://www.chromium.org/getting-involved/dev-channel - // [this article]: https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/ - // [This article]: https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md - Launch(options ...BrowserTypeLaunchOptions) (Browser, error) - - // Returns the persistent browser context instance. - // Launches browser that uses persistent storage located at “[object Object]” and returns the only context. Closing - // this context will automatically close the browser. - // - // userDataDir: Path to a User Data Directory, which stores browser session data like cookies and local storage. Pass an empty - // string to create a temporary directory. - // - // More details for - // [Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md#introduction) and - // [Firefox](https://wiki.mozilla.org/Firefox/CommandLineOptions#User_profile). Chromium's user data directory is the - // **parent** directory of the "Profile Path" seen at `chrome://version`. - // - // Note that browsers do not allow launching multiple instances with the same User Data Directory. - LaunchPersistentContext(userDataDir string, options ...BrowserTypeLaunchPersistentContextOptions) (BrowserContext, error) - - // Returns browser name. For example: `chromium`, `webkit` or `firefox`. - Name() string -} - -// The `CDPSession` instances are used to talk raw Chrome Devtools Protocol: -// - protocol methods can be called with `session.send` method. -// - protocol events can be subscribed to with `session.on` method. -// -// Useful links: -// - Documentation on DevTools Protocol can be found here: -// [DevTools Protocol Viewer]. -// - Getting Started with DevTools Protocol: -// https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md -// -// [DevTools Protocol Viewer]: https://chromedevtools.github.io/devtools-protocol/ -type CDPSession interface { - EventEmitter - // Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be - // used to send messages. - Detach() error - - // - // 1. method: Protocol method name. - // 2. params: Optional method parameters. - Send(method string, params map[string]interface{}) (interface{}, error) -} - -// Accurately simulating time-dependent behavior is essential for verifying the correctness of applications. Learn -// more about [clock emulation]. -// Note that clock is installed for the entire [BrowserContext], so the time in all the pages and iframes is -// controlled by the same clock. -// -// [clock emulation]: https://playwright.dev/docs/clock -type Clock interface { - // Advance the clock by jumping forward in time. Only fires due timers at most once. This is equivalent to user - // closing the laptop lid for a while and reopening it later, after given time. - // - // ticks: Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are - // "08" for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds. - FastForward(ticks interface{}) error - - // Install fake implementations for the following time-related functions: - // - `Date` - // - `setTimeout` - // - `clearTimeout` - // - `setInterval` - // - `clearInterval` - // - `requestAnimationFrame` - // - `cancelAnimationFrame` - // - `requestIdleCallback` - // - `cancelIdleCallback` - // - `performance` - // Fake timers are used to manually control the flow of time in tests. They allow you to advance time, fire timers, - // and control the behavior of time-dependent functions. See [Clock.RunFor] and [Clock.FastForward] for more - // information. - Install(options ...ClockInstallOptions) error - - // Advance the clock, firing all the time-related callbacks. - // - // ticks: Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are - // "08" for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds. - RunFor(ticks interface{}) error - - // Advance the clock by jumping forward in time and pause the time. Once this method is called, no timers are fired - // unless [Clock.RunFor], [Clock.FastForward], [Clock.PauseAt] or [Clock.Resume] is called. - // Only fires due timers at most once. This is equivalent to user closing the laptop lid for a while and reopening it - // at the specified time and pausing. - // - // time: Time to pause at. - PauseAt(time interface{}) error - - // Resumes timers. Once this method is called, time resumes flowing, timers are fired as usual. - Resume() error - - // Makes `Date.now` and `new Date()` return fixed fake time at all times, keeps all the timers running. - // Use this method for simple scenarios where you only need to test with a predefined time. For more advanced - // scenarios, use [Clock.Install] instead. Read docs on [clock emulation] to learn more. - // - // time: Time to be set. - // - // [clock emulation]: https://playwright.dev/docs/clock - SetFixedTime(time interface{}) error - - // Sets system time, but does not trigger any timers. Use this to test how the web page reacts to a time shift, for - // example switching from summer to winter time, or changing time zones. - // - // time: Time to be set. - SetSystemTime(time interface{}) error -} - -// [ConsoleMessage] objects are dispatched by page via the [Page.OnConsole] event. For each console message logged in -// the page there will be corresponding event in the Playwright context. -type ConsoleMessage interface { - // List of arguments passed to a `console` function call. See also [Page.OnConsole]. - Args() []JSHandle - - Location() *ConsoleMessageLocation - - // The page that produced this console message, if any. - Page() Page - - // The text of the console message. - Text() string - - // The text of the console message. - String() string - - // One of the following values: `log`, `debug`, `info`, `error`, `warning`, `dir`, `dirxml`, `table`, - // `trace`, `clear`, `startGroup`, `startGroupCollapsed`, `endGroup`, `assert`, `profile`, - // `profileEnd`, `count`, `timeEnd`. - Type() string -} - -// [Dialog] objects are dispatched by page via the [Page.OnDialog] event. -// An example of using `Dialog` class: -// **NOTE** Dialogs are dismissed automatically, unless there is a [Page.OnDialog] listener. When listener is present, -// it **must** either [Dialog.Accept] or [Dialog.Dismiss] the dialog - otherwise the page will -// [freeze] waiting for the dialog, -// and actions like click will never finish. -// -// [freeze]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking -type Dialog interface { - // Returns when the dialog has been accepted. - Accept(promptText ...string) error - - // If dialog is prompt, returns default prompt value. Otherwise, returns empty string. - DefaultValue() string - - // Returns when the dialog has been dismissed. - Dismiss() error - - // A message displayed in the dialog. - Message() string - - // The page that initiated this dialog, if available. - Page() Page - - // Returns dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`. - Type() string -} - -// [Download] objects are dispatched by page via the [Page.OnDownload] event. -// All the downloaded files belonging to the browser context are deleted when the browser context is closed. -// Download event is emitted once the download starts. Download path becomes available once download completes. -type Download interface { - // Cancels a download. Will not fail if the download is already finished or canceled. Upon successful cancellations, - // `download.failure()` would resolve to `canceled`. - Cancel() error - - // Deletes the downloaded file. Will wait for the download to finish if necessary. - Delete() error - - // Returns download error if any. Will wait for the download to finish if necessary. - Failure() error - - // Get the page that the download belongs to. - Page() Page - - // Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method - // will wait for the download to finish if necessary. The method throws when connected remotely. - // Note that the download's file name is a random GUID, use [Download.SuggestedFilename] to get suggested file name. - Path() (string, error) - - // Copy the download to a user-specified path. It is safe to call this method while the download is still in progress. - // Will wait for the download to finish if necessary. - // - // path: Path where the download should be copied. - SaveAs(path string) error - - // Returns suggested filename for this download. It is typically computed by the browser from the - // [`Content-Disposition`] response - // header or the `download` attribute. See the spec on [whatwg]. - // Different browsers can use different logic for computing it. - // - // [`Content-Disposition`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition - // [whatwg]: https://html.spec.whatwg.org/#downloading-resources - SuggestedFilename() string - - // Returns downloaded url. - URL() string - - String() string -} - -// ElementHandle represents an in-page DOM element. ElementHandles can be created with the [Page.QuerySelector] -// -// method. -// **NOTE** The use of ElementHandle is discouraged, use [Locator] objects and web-first assertions instead. -// ElementHandle prevents DOM element from garbage collection unless the handle is disposed with [JSHandle.Dispose]. -// ElementHandles are auto-disposed when their origin frame gets navigated. -// ElementHandle instances can be used as an argument in [Page.EvalOnSelector] and [Page.Evaluate] methods. -// The difference between the [Locator] and ElementHandle is that the ElementHandle points to a particular element, -// while [Locator] captures the logic of how to retrieve an element. -// In the example below, handle points to a particular DOM element on page. If that element changes text or is used by -// React to render an entirely different component, handle is still pointing to that very DOM element. This can lead -// to unexpected behaviors. -// With the locator, every time the `element` is used, up-to-date DOM element is located in the page using the -// selector. So in the snippet below, underlying DOM element is going to be located twice. -type ElementHandle interface { - JSHandle - // This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is - // calculated relative to the main frame viewport - which is usually the same as the browser window. - // Scrolling affects the returned bounding box, similarly to - // [Element.GetBoundingClientRect]. - // That means `x` and/or `y` may be negative. - // Elements from child frames return the bounding box relative to the main frame, unlike the - // [Element.GetBoundingClientRect]. - // Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the - // following snippet should click the center of the element. - // - // [Element.GetBoundingClientRect]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect - // [Element.GetBoundingClientRect]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect - BoundingBox() (*Rect, error) - - // This method checks the element by performing the following steps: - // 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already - // checked, this method returns immediately. - // 2. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Mouse] to click in the center of the element. - // 5. Ensure that the element is now checked. If not, this method throws. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Check] instead. Read more about [locators]. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Check(options ...ElementHandleCheckOptions) error - - // This method clicks the element by performing the following steps: - // 1. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 2. Scroll the element into view if needed. - // 3. Use [Page.Mouse] to click in the center of the element, or the specified “[object Object]”. - // 4. Wait for initiated navigations to either succeed or fail, unless “[object Object]” option is set. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Click] instead. Read more about [locators]. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Click(options ...ElementHandleClickOptions) error - - // Returns the content frame for element handles referencing iframe nodes, or `null` otherwise - ContentFrame() (Frame, error) - - // This method double clicks the element by performing the following steps: - // 1. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 2. Scroll the element into view if needed. - // 3. Use [Page.Mouse] to double click in the center of the element, or the specified “[object Object]”. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // **NOTE** `elementHandle.dblclick()` dispatches two `click` events and a single `dblclick` event. - // - // Deprecated: Use locator-based [Locator.Dblclick] instead. Read more about [locators]. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Dblclick(options ...ElementHandleDblclickOptions) error - - // The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, - // `click` is dispatched. This is equivalent to calling - // [element.Click()]. - // - // Deprecated: Use locator-based [Locator.DispatchEvent] instead. Read more about [locators]. - // - // 1. typ: DOM event type: `"click"`, `"dragstart"`, etc. - // 2. eventInit: Optional event-specific initialization properties. - // - // [element.Click()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click - // [DeviceMotionEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent - // [DeviceOrientationEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent - // [DragEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent - // [Event]: https://developer.mozilla.org/en-US/docs/Web/API/Event/Event - // [FocusEvent]: https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent - // [KeyboardEvent]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent - // [MouseEvent]: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent - // [PointerEvent]: https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent - // [TouchEvent]: https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent - // [WheelEvent]: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent - // [locators]: https://playwright.dev/docs/locators - DispatchEvent(typ string, eventInit ...interface{}) error - - // Returns the return value of “[object Object]”. - // The method finds an element matching the specified selector in the `ElementHandle`s subtree and passes it as a - // first argument to “[object Object]”. If no elements match the selector, the method throws an error. - // If “[object Object]” returns a [Promise], then [ElementHandle.EvalOnSelector] would wait for the promise to resolve - // and return its value. - // - // Deprecated: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests. Use [Locator.Evaluate], other [Locator] helper methods or web-first assertions instead. - // - // 1. selector: A selector to query for. - // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 3. arg: Optional argument to pass to “[object Object]”. - EvalOnSelector(selector string, expression string, arg ...interface{}) (interface{}, error) - - // Returns the return value of “[object Object]”. - // The method finds all elements matching the specified selector in the `ElementHandle`'s subtree and passes an array - // of matched elements as a first argument to “[object Object]”. - // If “[object Object]” returns a [Promise], then [ElementHandle.EvalOnSelectorAll] would wait for the promise to - // resolve and return its value. - // - // Deprecated: In most cases, [Locator.EvaluateAll], other [Locator] helper methods and web-first assertions do a better job. - // - // 1. selector: A selector to query for. - // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 3. arg: Optional argument to pass to “[object Object]”. - EvalOnSelectorAll(selector string, expression string, arg ...interface{}) (interface{}, error) - - // This method waits for [actionability] checks, focuses the element, fills it and triggers an - // `input` event after filling. Note that you can pass an empty string to clear the input field. - // If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an - // error. However, if the element is inside the `<label>` element that has an associated - // [control], the control will be filled - // instead. - // To send fine-grained keyboard events, use [Locator.PressSequentially]. - // - // Deprecated: Use locator-based [Locator.Fill] instead. Read more about [locators]. - // - // value: Value to set for the `<input>`, `<textarea>` or `[contenteditable]` element. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - Fill(value string, options ...ElementHandleFillOptions) error - - // Calls [focus] on the element. - // - // Deprecated: Use locator-based [Locator.Focus] instead. Read more about [locators]. - // - // [focus]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus - // [locators]: https://playwright.dev/docs/locators - Focus() error - - // Returns element attribute value. - // - // Deprecated: Use locator-based [Locator.GetAttribute] instead. Read more about [locators]. - // - // name: Attribute name to get the value for. - // - // [locators]: https://playwright.dev/docs/locators - GetAttribute(name string) (string, error) - - // This method hovers over the element by performing the following steps: - // 1. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 2. Scroll the element into view if needed. - // 3. Use [Page.Mouse] to hover over the center of the element, or the specified “[object Object]”. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Hover] instead. Read more about [locators]. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Hover(options ...ElementHandleHoverOptions) error - - // Returns the `element.innerHTML`. - // - // Deprecated: Use locator-based [Locator.InnerHTML] instead. Read more about [locators]. - // - // [locators]: https://playwright.dev/docs/locators - InnerHTML() (string, error) - - // Returns the `element.innerText`. - // - // Deprecated: Use locator-based [Locator.InnerText] instead. Read more about [locators]. - // - // [locators]: https://playwright.dev/docs/locators - InnerText() (string, error) - - // Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element. - // Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated - // [control], returns the value of the - // control. - // - // Deprecated: Use locator-based [Locator.InputValue] instead. Read more about [locators]. - // - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - InputValue(options ...ElementHandleInputValueOptions) (string, error) - - // Returns whether the element is checked. Throws if the element is not a checkbox or radio input. - // - // Deprecated: Use locator-based [Locator.IsChecked] instead. Read more about [locators]. - // - // [locators]: https://playwright.dev/docs/locators - IsChecked() (bool, error) - - // Returns whether the element is disabled, the opposite of [enabled]. - // - // Deprecated: Use locator-based [Locator.IsDisabled] instead. Read more about [locators]. - // - // [enabled]: https://playwright.dev/docs/actionability#enabled - // [locators]: https://playwright.dev/docs/locators - IsDisabled() (bool, error) - - // Returns whether the element is [editable]. - // - // Deprecated: Use locator-based [Locator.IsEditable] instead. Read more about [locators]. - // - // [editable]: https://playwright.dev/docs/actionability#editable - // [locators]: https://playwright.dev/docs/locators - IsEditable() (bool, error) - - // Returns whether the element is [enabled]. - // - // Deprecated: Use locator-based [Locator.IsEnabled] instead. Read more about [locators]. - // - // [enabled]: https://playwright.dev/docs/actionability#enabled - // [locators]: https://playwright.dev/docs/locators - IsEnabled() (bool, error) - - // Returns whether the element is hidden, the opposite of [visible]. - // - // Deprecated: Use locator-based [Locator.IsHidden] instead. Read more about [locators]. - // - // [visible]: https://playwright.dev/docs/actionability#visible - // [locators]: https://playwright.dev/docs/locators - IsHidden() (bool, error) - - // Returns whether the element is [visible]. - // - // Deprecated: Use locator-based [Locator.IsVisible] instead. Read more about [locators]. - // - // [visible]: https://playwright.dev/docs/actionability#visible - // [locators]: https://playwright.dev/docs/locators - IsVisible() (bool, error) - - // Returns the frame containing the given element. - OwnerFrame() (Frame, error) - - // Focuses the element, and then uses [Keyboard.Down] and [Keyboard.Up]. - // “[object Object]” can specify the intended - // [keyboardEvent.Key] value or a single character - // to generate the text for. A superset of the “[object Object]” values can be found - // [here]. Examples of the keys are: - // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, - // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, - // etc. - // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, - // `ControlOrMeta`. - // Holding down `Shift` will type the text that corresponds to the “[object Object]” in the upper case. - // If “[object Object]” is a single character, it is case-sensitive, so the values `a` and `A` will generate different - // respective texts. - // Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When - // specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. - // - // Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators]. - // - // key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. - // - // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key - // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values - // [locators]: https://playwright.dev/docs/locators - Press(key string, options ...ElementHandlePressOptions) error - - // The method finds an element matching the specified selector in the `ElementHandle`'s subtree. If no elements match - // the selector, returns `null`. - // - // Deprecated: Use locator-based [Page.Locator] instead. Read more about [locators]. - // - // selector: A selector to query for. - // - // [locators]: https://playwright.dev/docs/locators - QuerySelector(selector string) (ElementHandle, error) - - // The method finds all elements matching the specified selector in the `ElementHandle`s subtree. If no elements match - // the selector, returns empty array. - // - // Deprecated: Use locator-based [Page.Locator] instead. Read more about [locators]. - // - // selector: A selector to query for. - // - // [locators]: https://playwright.dev/docs/locators - QuerySelectorAll(selector string) ([]ElementHandle, error) - - // This method captures a screenshot of the page, clipped to the size and position of this particular element. If the - // element is covered by other elements, it will not be actually visible on the screenshot. If the element is a - // scrollable container, only the currently scrolled content will be visible on the screenshot. - // This method waits for the [actionability] checks, then scrolls element into view before taking - // a screenshot. If the element is detached from DOM, the method throws an error. - // Returns the buffer with the captured screenshot. - // - // Deprecated: Use locator-based [Locator.Screenshot] instead. Read more about [locators]. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Screenshot(options ...ElementHandleScreenshotOptions) ([]byte, error) - - // This method waits for [actionability] checks, then tries to scroll element into view, unless - // it is completely visible as defined by - // [IntersectionObserver]'s `ratio`. - // Throws when `elementHandle` does not point to an element - // [connected] to a Document or a ShadowRoot. - // See [scrolling] for alternative ways to scroll. - // - // Deprecated: Use locator-based [Locator.ScrollIntoViewIfNeeded] instead. Read more about [locators]. - // - // [actionability]: https://playwright.dev/docs/actionability - // [IntersectionObserver]: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API - // [connected]: https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected - // [scrolling]: https://playwright.dev/docs/input#scrolling - // [locators]: https://playwright.dev/docs/locators - ScrollIntoViewIfNeeded(options ...ElementHandleScrollIntoViewIfNeededOptions) error - - // This method waits for [actionability] checks, waits until all specified options are present in - // the `<select>` element and selects these options. - // If the target element is not a `<select>` element, this method throws an error. However, if the element is inside - // the `<label>` element that has an associated - // [control], the control will be used - // instead. - // Returns the array of option values that have been successfully selected. - // Triggers a `change` and `input` event once all the provided options have been selected. - // - // Deprecated: Use locator-based [Locator.SelectOption] instead. Read more about [locators]. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - SelectOption(values SelectOptionValues, options ...ElementHandleSelectOptionOptions) ([]string, error) - - // This method waits for [actionability] checks, then focuses the element and selects all its - // text content. - // If the element is inside the `<label>` element that has an associated - // [control], focuses and selects text in - // the control instead. - // - // Deprecated: Use locator-based [Locator.SelectText] instead. Read more about [locators]. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - SelectText(options ...ElementHandleSelectTextOptions) error - - // This method checks or unchecks an element by performing the following steps: - // 1. Ensure that element is a checkbox or a radio input. If not, this method throws. - // 2. If the element already has the right checked state, this method returns immediately. - // 3. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 4. Scroll the element into view if needed. - // 5. Use [Page.Mouse] to click in the center of the element. - // 6. Ensure that the element is now checked or unchecked. If not, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.SetChecked] instead. Read more about [locators]. - // - // checked: Whether to check or uncheck the checkbox. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - SetChecked(checked bool, options ...ElementHandleSetCheckedOptions) error - - // Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then - // they are resolved relative to the current working directory. For empty array, clears the selected files. For inputs - // with a `[webkitdirectory]` attribute, only a single directory path is supported. - // This method expects [ElementHandle] to point to an - // [input element]. However, if the element is inside - // the `<label>` element that has an associated - // [control], targets the control instead. - // - // Deprecated: Use locator-based [Locator.SetInputFiles] instead. Read more about [locators]. - // - // [input element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - SetInputFiles(files interface{}, options ...ElementHandleSetInputFilesOptions) error - - // This method taps the element by performing the following steps: - // 1. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 2. Scroll the element into view if needed. - // 3. Use [Page.Touchscreen] to tap the center of the element, or the specified “[object Object]”. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // **NOTE** `elementHandle.tap()` requires that the `hasTouch` option of the browser context be set to true. - // - // Deprecated: Use locator-based [Locator.Tap] instead. Read more about [locators]. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Tap(options ...ElementHandleTapOptions) error - - // Returns the `node.textContent`. - // - // Deprecated: Use locator-based [Locator.TextContent] instead. Read more about [locators]. - // - // [locators]: https://playwright.dev/docs/locators - TextContent() (string, error) - - // Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the - // text. - // To press a special key, like `Control` or `ArrowDown`, use [ElementHandle.Press]. - // - // Deprecated: In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [Locator.PressSequentially]. - // - // text: A text to type into a focused element. - Type(text string, options ...ElementHandleTypeOptions) error - - // This method checks the element by performing the following steps: - // 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already - // unchecked, this method returns immediately. - // 2. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Mouse] to click in the center of the element. - // 5. Ensure that the element is now unchecked. If not, this method throws. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Uncheck] instead. Read more about [locators]. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Uncheck(options ...ElementHandleUncheckOptions) error - - // Returns when the element satisfies the “[object Object]”. - // Depending on the “[object Object]” parameter, this method waits for one of the [actionability] - // checks to pass. This method throws when the element is detached while waiting, unless waiting for the `"hidden"` - // state. - // - `"visible"` Wait until the element is [visible]. - // - `"hidden"` Wait until the element is [not visible] or not attached. Note that - // waiting for hidden does not throw when the element detaches. - // - `"stable"` Wait until the element is both [visible] and - // [stable]. - // - `"enabled"` Wait until the element is [enabled]. - // - `"disabled"` Wait until the element is [not enabled]. - // - `"editable"` Wait until the element is [editable]. - // If the element does not satisfy the condition for the “[object Object]” milliseconds, this method will throw. - // - // state: A state to wait for, see below for more details. - // - // [actionability]: https://playwright.dev/docs/actionability - // [visible]: https://playwright.dev/docs/actionability#visible - // [not visible]: https://playwright.dev/docs/actionability#visible - // [visible]: https://playwright.dev/docs/actionability#visible - // [stable]: https://playwright.dev/docs/actionability#stable - // [enabled]: https://playwright.dev/docs/actionability#enabled - // [not enabled]: https://playwright.dev/docs/actionability#enabled - // [editable]: https://playwright.dev/docs/actionability#editable - WaitForElementState(state ElementState, options ...ElementHandleWaitForElementStateOptions) error - - // Returns element specified by selector when it satisfies “[object Object]” option. Returns `null` if waiting for - // `hidden` or `detached`. - // Wait for the “[object Object]” relative to the element handle to satisfy “[object Object]” option (either - // appear/disappear from dom, or become visible/hidden). If at the moment of calling the method “[object Object]” - // already satisfies the condition, the method will return immediately. If the selector doesn't satisfy the condition - // for the “[object Object]” milliseconds, the function will throw. - // - // Deprecated: Use web assertions that assert visibility or a locator-based [Locator.WaitFor] instead. - // - // selector: A selector to query for. - WaitForSelector(selector string, options ...ElementHandleWaitForSelectorOptions) (ElementHandle, error) -} - -// [FileChooser] objects are dispatched by the page in the [Page.OnFileChooser] event. -type FileChooser interface { - // Returns input element associated with this file chooser. - Element() ElementHandle - - // Returns whether this file chooser accepts multiple files. - IsMultiple() bool - - // Returns page this file chooser belongs to. - Page() Page - - // Sets the value of the file input this chooser is associated with. If some of the `filePaths` are relative paths, - // then they are resolved relative to the current working directory. For empty array, clears the selected files. - SetFiles(files interface{}, options ...FileChooserSetFilesOptions) error -} - -// At every point of time, page exposes its current frame tree via the [Page.MainFrame] and [Frame.ChildFrames] -// methods. -// [Frame] object's lifecycle is controlled by three events, dispatched on the page object: -// - [Page.OnFrameAttached] - fired when the frame gets attached to the page. A Frame can be attached to the page -// only once. -// - [Page.OnFrameNavigated] - fired when the frame commits navigation to a different URL. -// - [Page.OnFrameDetached] - fired when the frame gets detached from the page. A Frame can be detached from the -// page only once. -// -// An example of dumping frame tree: -type Frame interface { - // Returns the added tag when the script's onload fires or when the script content was injected into frame. - // Adds a `<script>` tag into the page with the desired url or content. - AddScriptTag(options FrameAddScriptTagOptions) (ElementHandle, error) - - // Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame. - // Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the - // content. - AddStyleTag(options FrameAddStyleTagOptions) (ElementHandle, error) - - // This method checks an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is - // already checked, this method returns immediately. - // 3. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 4. Scroll the element into view if needed. - // 5. Use [Page.Mouse] to click in the center of the element. - // 6. Ensure that the element is now checked. If not, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Check] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Check(selector string, options ...FrameCheckOptions) error - - ChildFrames() []Frame - - // This method clicks an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Mouse] to click in the center of the element, or the specified “[object Object]”. - // 5. Wait for initiated navigations to either succeed or fail, unless “[object Object]” option is set. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Click] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Click(selector string, options ...FrameClickOptions) error - - // Gets the full HTML contents of the frame, including the doctype. - Content() (string, error) - - // This method double clicks an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Mouse] to double click in the center of the element, or the specified “[object Object]”. if the - // first click of the `dblclick()` triggers a navigation event, this method will throw. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // **NOTE** `frame.dblclick()` dispatches two `click` events and a single `dblclick` event. - // - // Deprecated: Use locator-based [Locator.Dblclick] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Dblclick(selector string, options ...FrameDblclickOptions) error - - // The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, - // `click` is dispatched. This is equivalent to calling - // [element.Click()]. - // - // Deprecated: Use locator-based [Locator.DispatchEvent] instead. Read more about [locators]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. typ: DOM event type: `"click"`, `"dragstart"`, etc. - // 3. eventInit: Optional event-specific initialization properties. - // - // [element.Click()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click - // [DeviceMotionEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent - // [DeviceOrientationEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent - // [DragEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent - // [Event]: https://developer.mozilla.org/en-US/docs/Web/API/Event/Event - // [FocusEvent]: https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent - // [KeyboardEvent]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent - // [MouseEvent]: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent - // [PointerEvent]: https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent - // [TouchEvent]: https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent - // [WheelEvent]: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent - // [locators]: https://playwright.dev/docs/locators - DispatchEvent(selector string, typ string, eventInit interface{}, options ...FrameDispatchEventOptions) error - - // - // 1. source: A selector to search for an element to drag. If there are multiple elements satisfying the selector, the first will - // be used. - // 2. target: A selector to search for an element to drop onto. If there are multiple elements satisfying the selector, the first - // will be used. - DragAndDrop(source string, target string, options ...FrameDragAndDropOptions) error - - // Returns the return value of “[object Object]”. - // The method finds an element matching the specified selector within the frame and passes it as a first argument to - // “[object Object]”. If no elements match the selector, the method throws an error. - // If “[object Object]” returns a [Promise], then [Frame.EvalOnSelector] would wait for the promise to resolve and - // return its value. - // - // Deprecated: This method does not wait for the element to pass the actionability checks and therefore can lead to the flaky tests. Use [Locator.Evaluate], other [Locator] helper methods or web-first assertions instead. - // - // 1. selector: A selector to query for. - // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 3. arg: Optional argument to pass to “[object Object]”. - EvalOnSelector(selector string, expression string, arg interface{}, options ...FrameEvalOnSelectorOptions) (interface{}, error) - - // Returns the return value of “[object Object]”. - // The method finds all elements matching the specified selector within the frame and passes an array of matched - // elements as a first argument to “[object Object]”. - // If “[object Object]” returns a [Promise], then [Frame.EvalOnSelectorAll] would wait for the promise to resolve and - // return its value. - // - // Deprecated: In most cases, [Locator.EvaluateAll], other [Locator] helper methods and web-first assertions do a better job. - // - // 1. selector: A selector to query for. - // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 3. arg: Optional argument to pass to “[object Object]”. - EvalOnSelectorAll(selector string, expression string, arg ...interface{}) (interface{}, error) - - // Returns the return value of “[object Object]”. - // If the function passed to the [Frame.Evaluate] returns a [Promise], then [Frame.Evaluate] would wait for the - // promise to resolve and return its value. - // If the function passed to the [Frame.Evaluate] returns a non-[Serializable] value, then [Frame.Evaluate] returns - // `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`: - // `-0`, `NaN`, `Infinity`, `-Infinity`. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - Evaluate(expression string, arg ...interface{}) (interface{}, error) - - // Returns the return value of “[object Object]” as a [JSHandle]. - // The only difference between [Frame.Evaluate] and [Frame.EvaluateHandle] is that [Frame.EvaluateHandle] returns - // [JSHandle]. - // If the function, passed to the [Frame.EvaluateHandle], returns a [Promise], then [Frame.EvaluateHandle] would wait - // for the promise to resolve and return its value. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - EvaluateHandle(expression string, arg ...interface{}) (JSHandle, error) - - // This method waits for an element matching “[object Object]”, waits for [actionability] checks, - // focuses the element, fills it and triggers an `input` event after filling. Note that you can pass an empty string - // to clear the input field. - // If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an - // error. However, if the element is inside the `<label>` element that has an associated - // [control], the control will be filled - // instead. - // To send fine-grained keyboard events, use [Locator.PressSequentially]. - // - // Deprecated: Use locator-based [Locator.Fill] instead. Read more about [locators]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. value: Value to fill for the `<input>`, `<textarea>` or `[contenteditable]` element. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - Fill(selector string, value string, options ...FrameFillOptions) error - - // This method fetches an element with “[object Object]” and focuses it. If there's no element matching - // “[object Object]”, the method waits until a matching element appears in the DOM. - // - // Deprecated: Use locator-based [Locator.Focus] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [locators]: https://playwright.dev/docs/locators - Focus(selector string, options ...FrameFocusOptions) error - - // Returns the `frame` or `iframe` element handle which corresponds to this frame. - // This is an inverse of [ElementHandle.ContentFrame]. Note that returned handle actually belongs to the parent frame. - // This method throws an error if the frame has been detached before `frameElement()` returns. - FrameElement() (ElementHandle, error) - - // When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements - // in that iframe. - // - // selector: A selector to use when resolving DOM element. - FrameLocator(selector string) FrameLocator - - // Returns element attribute value. - // - // Deprecated: Use locator-based [Locator.GetAttribute] instead. Read more about [locators]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. name: Attribute name to get the value for. - // - // [locators]: https://playwright.dev/docs/locators - GetAttribute(selector string, name string, options ...FrameGetAttributeOptions) (string, error) - - // Allows locating elements by their alt text. - // - // text: Text to locate the element for. - GetByAltText(text interface{}, options ...FrameGetByAltTextOptions) Locator - - // Allows locating input elements by the text of the associated `<label>` or `aria-labelledby` element, or by the - // `aria-label` attribute. - // - // text: Text to locate the element for. - GetByLabel(text interface{}, options ...FrameGetByLabelOptions) Locator - - // Allows locating input elements by the placeholder text. - // - // text: Text to locate the element for. - GetByPlaceholder(text interface{}, options ...FrameGetByPlaceholderOptions) Locator - - // Allows locating elements by their [ARIA role], - // [ARIA attributes] and - // [accessible name]. - // - // # Details - // - // Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback - // about the ARIA guidelines. - // Many html elements have an implicitly [defined role] - // that is recognized by the role selector. You can find all the - // [supported roles here]. ARIA guidelines **do not recommend** - // duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values. - // - // role: Required aria role. - // - // [ARIA role]: https://www.w3.org/TR/wai-aria-1.2/#roles - // [ARIA attributes]: https://www.w3.org/TR/wai-aria-1.2/#aria-attributes - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - // [defined role]: https://w3c.github.io/html-aam/#html-element-role-mappings - // [supported roles here]: https://www.w3.org/TR/wai-aria-1.2/#role_definitions - GetByRole(role AriaRole, options ...FrameGetByRoleOptions) Locator - - // Locate element by the test id. - // - // # Details - // - // By default, the `data-testid` attribute is used as a test id. Use [Selectors.SetTestIdAttribute] to configure a - // different test id attribute if necessary. - // - // testId: Id to locate the element by. - GetByTestId(testId interface{}) Locator - - // Allows locating elements that contain given text. - // See also [Locator.Filter] that allows to match by another criteria, like an accessible role, and then filter by the - // text content. - // - // # Details - // - // Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into - // one, turns line breaks into spaces and ignores leading and trailing whitespace. - // Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For - // example, locating by text `"Log in"` matches `<input type=button value="Log in">`. - // - // text: Text to locate the element for. - GetByText(text interface{}, options ...FrameGetByTextOptions) Locator - - // Allows locating elements by their title attribute. - // - // text: Text to locate the element for. - GetByTitle(text interface{}, options ...FrameGetByTitleOptions) Locator - - // Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of - // the last redirect. - // The method will throw an error if: - // - there's an SSL error (e.g. in case of self-signed certificates). - // - target URL is invalid. - // - the “[object Object]” is exceeded during navigation. - // - the remote server does not respond or is unreachable. - // - the main resource failed to load. - // The method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 - // "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling - // [Response.Status]. - // **NOTE** The method either throws an error or returns a main resource response. The only exceptions are navigation - // to `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`. - // **NOTE** Headless mode doesn't support navigation to a PDF document. See the - // [upstream issue]. - // - // url: URL to navigate frame to. The url should include scheme, e.g. `https://`. - // - // [upstream issue]: https://bugs.chromium.org/p/chromium/issues/detail?id=761295 - Goto(url string, options ...FrameGotoOptions) (Response, error) - - // This method hovers over an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Mouse] to hover over the center of the element, or the specified “[object Object]”. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Hover] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Hover(selector string, options ...FrameHoverOptions) error - - // Returns `element.innerHTML`. - // - // Deprecated: Use locator-based [Locator.InnerHTML] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [locators]: https://playwright.dev/docs/locators - InnerHTML(selector string, options ...FrameInnerHTMLOptions) (string, error) - - // Returns `element.innerText`. - // - // Deprecated: Use locator-based [Locator.InnerText] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [locators]: https://playwright.dev/docs/locators - InnerText(selector string, options ...FrameInnerTextOptions) (string, error) - - // Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element. - // Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated - // [control], returns the value of the - // control. - // - // Deprecated: Use locator-based [Locator.InputValue] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - InputValue(selector string, options ...FrameInputValueOptions) (string, error) - - // Returns whether the element is checked. Throws if the element is not a checkbox or radio input. - // - // Deprecated: Use locator-based [Locator.IsChecked] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [locators]: https://playwright.dev/docs/locators - IsChecked(selector string, options ...FrameIsCheckedOptions) (bool, error) - - // Returns `true` if the frame has been detached, or `false` otherwise. - IsDetached() bool - - // Returns whether the element is disabled, the opposite of [enabled]. - // - // Deprecated: Use locator-based [Locator.IsDisabled] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [enabled]: https://playwright.dev/docs/actionability#enabled - // [locators]: https://playwright.dev/docs/locators - IsDisabled(selector string, options ...FrameIsDisabledOptions) (bool, error) - - // Returns whether the element is [editable]. - // - // Deprecated: Use locator-based [Locator.IsEditable] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [editable]: https://playwright.dev/docs/actionability#editable - // [locators]: https://playwright.dev/docs/locators - IsEditable(selector string, options ...FrameIsEditableOptions) (bool, error) - - // Returns whether the element is [enabled]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [enabled]: https://playwright.dev/docs/actionability#enabled - IsEnabled(selector string, options ...FrameIsEnabledOptions) (bool, error) - - // Returns whether the element is hidden, the opposite of [visible]. “[object Object]” - // that does not match any elements is considered hidden. - // - // Deprecated: Use locator-based [Locator.IsHidden] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [visible]: https://playwright.dev/docs/actionability#visible - // [locators]: https://playwright.dev/docs/locators - IsHidden(selector string, options ...FrameIsHiddenOptions) (bool, error) - - // Returns whether the element is [visible]. “[object Object]” that does not match any - // elements is considered not visible. - // - // Deprecated: Use locator-based [Locator.IsVisible] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [visible]: https://playwright.dev/docs/actionability#visible - // [locators]: https://playwright.dev/docs/locators - IsVisible(selector string, options ...FrameIsVisibleOptions) (bool, error) - - // The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved - // to the element immediately before performing an action, so a series of actions on the same locator can in fact be - // performed on different DOM elements. That would happen if the DOM structure between those actions has changed. - // [Learn more about locators]. - // [Learn more about locators]. - // - // selector: A selector to use when resolving DOM element. - // - // [Learn more about locators]: https://playwright.dev/docs/locators - // [Learn more about locators]: https://playwright.dev/docs/locators - Locator(selector string, options ...FrameLocatorOptions) Locator - - // Returns frame's name attribute as specified in the tag. - // If the name is empty, returns the id attribute instead. - // **NOTE** This value is calculated once when the frame is created, and will not update if the attribute is changed - // later. - Name() string - - // Returns the page containing this frame. - Page() Page - - // Parent frame, if any. Detached frames and main frames return `null`. - ParentFrame() Frame - - // “[object Object]” can specify the intended - // [keyboardEvent.Key] value or a single character - // to generate the text for. A superset of the “[object Object]” values can be found - // [here]. Examples of the keys are: - // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, - // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, - // etc. - // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, - // `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS. - // Holding down `Shift` will type the text that corresponds to the “[object Object]” in the upper case. - // If “[object Object]” is a single character, it is case-sensitive, so the values `a` and `A` will generate different - // respective texts. - // Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When - // specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. - // - // Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. - // - // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key - // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values - // [locators]: https://playwright.dev/docs/locators - Press(selector string, key string, options ...FramePressOptions) error - - // Returns the ElementHandle pointing to the frame element. - // **NOTE** The use of [ElementHandle] is discouraged, use [Locator] objects and web-first assertions instead. - // The method finds an element matching the specified selector within the frame. If no elements match the selector, - // returns `null`. - // - // Deprecated: Use locator-based [Frame.Locator] instead. Read more about [locators]. - // - // selector: A selector to query for. - // - // [locators]: https://playwright.dev/docs/locators - QuerySelector(selector string, options ...FrameQuerySelectorOptions) (ElementHandle, error) - - // Returns the ElementHandles pointing to the frame elements. - // **NOTE** The use of [ElementHandle] is discouraged, use [Locator] objects instead. - // The method finds all elements matching the specified selector within the frame. If no elements match the selector, - // returns empty array. - // - // Deprecated: Use locator-based [Frame.Locator] instead. Read more about [locators]. - // - // selector: A selector to query for. - // - // [locators]: https://playwright.dev/docs/locators - QuerySelectorAll(selector string) ([]ElementHandle, error) - - // This method waits for an element matching “[object Object]”, waits for [actionability] checks, - // waits until all specified options are present in the `<select>` element and selects these options. - // If the target element is not a `<select>` element, this method throws an error. However, if the element is inside - // the `<label>` element that has an associated - // [control], the control will be used - // instead. - // Returns the array of option values that have been successfully selected. - // Triggers a `change` and `input` event once all the provided options have been selected. - // - // Deprecated: Use locator-based [Locator.SelectOption] instead. Read more about [locators]. - // - // selector: A selector to query for. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - SelectOption(selector string, values SelectOptionValues, options ...FrameSelectOptionOptions) ([]string, error) - - // This method checks or unchecks an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. - // 3. If the element already has the right checked state, this method returns immediately. - // 4. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 5. Scroll the element into view if needed. - // 6. Use [Page.Mouse] to click in the center of the element. - // 7. Ensure that the element is now checked or unchecked. If not, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.SetChecked] instead. Read more about [locators]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. checked: Whether to check or uncheck the checkbox. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - SetChecked(selector string, checked bool, options ...FrameSetCheckedOptions) error - - // This method internally calls [document.Write()], - // inheriting all its specific characteristics and behaviors. - // - // html: HTML markup to assign to the page. - // - // [document.Write()]: https://developer.mozilla.org/en-US/docs/Web/API/Document/write - SetContent(html string, options ...FrameSetContentOptions) error - - // Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then - // they are resolved relative to the current working directory. For empty array, clears the selected files. - // This method expects “[object Object]” to point to an - // [input element]. However, if the element is inside - // the `<label>` element that has an associated - // [control], targets the control instead. - // - // Deprecated: Use locator-based [Locator.SetInputFiles] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [input element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - SetInputFiles(selector string, files interface{}, options ...FrameSetInputFilesOptions) error - - // This method taps an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Touchscreen] to tap the center of the element, or the specified “[object Object]”. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // **NOTE** `frame.tap()` requires that the `hasTouch` option of the browser context be set to true. - // - // Deprecated: Use locator-based [Locator.Tap] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Tap(selector string, options ...FrameTapOptions) error - - // Returns `element.textContent`. - // - // Deprecated: Use locator-based [Locator.TextContent] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [locators]: https://playwright.dev/docs/locators - TextContent(selector string, options ...FrameTextContentOptions) (string, error) - - // Returns the page title. - Title() (string, error) - - // Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `frame.type` can be used - // to send fine-grained keyboard events. To fill values in form fields, use [Frame.Fill]. - // To press a special key, like `Control` or `ArrowDown`, use [Keyboard.Press]. - // - // Deprecated: In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [Locator.PressSequentially]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. text: A text to type into a focused element. - Type(selector string, text string, options ...FrameTypeOptions) error - - // This method checks an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is - // already unchecked, this method returns immediately. - // 3. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 4. Scroll the element into view if needed. - // 5. Use [Page.Mouse] to click in the center of the element. - // 6. Ensure that the element is now unchecked. If not, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Uncheck] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Uncheck(selector string, options ...FrameUncheckOptions) error - - // Returns frame's url. - URL() string - - // Returns when the “[object Object]” returns a truthy value, returns that value. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - WaitForFunction(expression string, arg interface{}, options ...FrameWaitForFunctionOptions) (JSHandle, error) - - // Waits for the required load state to be reached. - // This returns when the frame reaches a required load state, `load` by default. The navigation must have been - // committed when this method is called. If current document has already reached the required state, resolves - // immediately. - // **NOTE** Most of the time, this method is not needed because Playwright - // [auto-waits before every action]. - // - // [auto-waits before every action]: https://playwright.dev/docs/actionability - WaitForLoadState(options ...FrameWaitForLoadStateOptions) error - - // Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the - // navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or - // navigation due to History API usage, the navigation will resolve with `null`. - // - // Deprecated: This method is inherently racy, please use [Frame.WaitForURL] instead. - // - // [History API]: https://developer.mozilla.org/en-US/docs/Web/API/History_API - ExpectNavigation(cb func() error, options ...FrameExpectNavigationOptions) (Response, error) - - // Returns when element specified by selector satisfies “[object Object]” option. Returns `null` if waiting for - // `hidden` or `detached`. - // **NOTE** Playwright automatically waits for element to be ready before performing an action. Using [Locator] - // objects and web-first assertions make the code wait-for-selector-free. - // Wait for the “[object Object]” to satisfy “[object Object]” option (either appear/disappear from dom, or become - // visible/hidden). If at the moment of calling the method “[object Object]” already satisfies the condition, the - // method will return immediately. If the selector doesn't satisfy the condition for the “[object Object]” - // milliseconds, the function will throw. - // - // Deprecated: Use web assertions that assert visibility or a locator-based [Locator.WaitFor] instead. Read more about [locators]. - // - // selector: A selector to query for. - // - // [locators]: https://playwright.dev/docs/locators - WaitForSelector(selector string, options ...FrameWaitForSelectorOptions) (ElementHandle, error) - - // Waits for the given “[object Object]” in milliseconds. - // Note that `frame.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going - // to be flaky. Use signals such as network events, selectors becoming visible and others instead. - // - // Deprecated: Never wait for timeout in production. Tests that wait for time are inherently flaky. Use [Locator] actions and web assertions that wait automatically. - // - // timeout: A timeout to wait for - WaitForTimeout(timeout float64) - - // Waits for the frame to navigate to the given URL. - // - // url: A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if - // the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly - // equal to the string. - WaitForURL(url interface{}, options ...FrameWaitForURLOptions) error -} - -// FrameLocator represents a view to the `iframe` on the page. It captures the logic sufficient to retrieve the -// `iframe` and locate elements in that iframe. FrameLocator can be created with either [Locator.ContentFrame], -// [Page.FrameLocator] or [Locator.FrameLocator] method. -// **Strictness** -// Frame locators are strict. This means that all operations on frame locators will throw if more than one element -// matches a given selector. -// **Converting Locator to FrameLocator** -// If you have a [Locator] object pointing to an `iframe` it can be converted to [FrameLocator] using -// [Locator.ContentFrame]. -// **Converting FrameLocator to Locator** -// If you have a [FrameLocator] object it can be converted to [Locator] pointing to the same `iframe` using -// [FrameLocator.Owner]. -type FrameLocator interface { - // Returns locator to the first matching frame. - // - // Deprecated: Use [Locator.First] followed by [Locator.ContentFrame] instead. - First() FrameLocator - - // When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements - // in that iframe. - // - // selector: A selector to use when resolving DOM element. - FrameLocator(selector string) FrameLocator - - // Allows locating elements by their alt text. - // - // text: Text to locate the element for. - GetByAltText(text interface{}, options ...FrameLocatorGetByAltTextOptions) Locator - - // Allows locating input elements by the text of the associated `<label>` or `aria-labelledby` element, or by the - // `aria-label` attribute. - // - // text: Text to locate the element for. - GetByLabel(text interface{}, options ...FrameLocatorGetByLabelOptions) Locator - - // Allows locating input elements by the placeholder text. - // - // text: Text to locate the element for. - GetByPlaceholder(text interface{}, options ...FrameLocatorGetByPlaceholderOptions) Locator - - // Allows locating elements by their [ARIA role], - // [ARIA attributes] and - // [accessible name]. - // - // # Details - // - // Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback - // about the ARIA guidelines. - // Many html elements have an implicitly [defined role] - // that is recognized by the role selector. You can find all the - // [supported roles here]. ARIA guidelines **do not recommend** - // duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values. - // - // role: Required aria role. - // - // [ARIA role]: https://www.w3.org/TR/wai-aria-1.2/#roles - // [ARIA attributes]: https://www.w3.org/TR/wai-aria-1.2/#aria-attributes - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - // [defined role]: https://w3c.github.io/html-aam/#html-element-role-mappings - // [supported roles here]: https://www.w3.org/TR/wai-aria-1.2/#role_definitions - GetByRole(role AriaRole, options ...FrameLocatorGetByRoleOptions) Locator - - // Locate element by the test id. - // - // # Details - // - // By default, the `data-testid` attribute is used as a test id. Use [Selectors.SetTestIdAttribute] to configure a - // different test id attribute if necessary. - // - // testId: Id to locate the element by. - GetByTestId(testId interface{}) Locator - - // Allows locating elements that contain given text. - // See also [Locator.Filter] that allows to match by another criteria, like an accessible role, and then filter by the - // text content. - // - // # Details - // - // Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into - // one, turns line breaks into spaces and ignores leading and trailing whitespace. - // Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For - // example, locating by text `"Log in"` matches `<input type=button value="Log in">`. - // - // text: Text to locate the element for. - GetByText(text interface{}, options ...FrameLocatorGetByTextOptions) Locator - - // Allows locating elements by their title attribute. - // - // text: Text to locate the element for. - GetByTitle(text interface{}, options ...FrameLocatorGetByTitleOptions) Locator - - // Returns locator to the last matching frame. - // - // Deprecated: Use [Locator.Last] followed by [Locator.ContentFrame] instead. - Last() FrameLocator - - // The method finds an element matching the specified selector in the locator's subtree. It also accepts filter - // options, similar to [Locator.Filter] method. - // [Learn more about locators]. - // - // selectorOrLocator: A selector or locator to use when resolving DOM element. - // - // [Learn more about locators]: https://playwright.dev/docs/locators - Locator(selectorOrLocator interface{}, options ...FrameLocatorLocatorOptions) Locator - - // Returns locator to the n-th matching frame. It's zero based, `nth(0)` selects the first frame. - // - // Deprecated: Use [Locator.Nth] followed by [Locator.ContentFrame] instead. - Nth(index int) FrameLocator - - // Returns a [Locator] object pointing to the same `iframe` as this frame locator. - // Useful when you have a [FrameLocator] object obtained somewhere, and later on would like to interact with the - // `iframe` element. - // For a reverse operation, use [Locator.ContentFrame]. - Owner() Locator -} - -// JSHandle represents an in-page JavaScript object. JSHandles can be created with the [Page.EvaluateHandle] method. -// JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is exposed with -// [JSHandle.Dispose]. JSHandles are auto-disposed when their origin frame gets navigated or the parent context gets -// destroyed. -// JSHandle instances can be used as an argument in [Page.EvalOnSelector], [Page.Evaluate] and [Page.EvaluateHandle] -// methods. -type JSHandle interface { - // Returns either `null` or the object handle itself, if the object handle is an instance of [ElementHandle]. - AsElement() ElementHandle - - // The `jsHandle.dispose` method stops referencing the element handle. - Dispose() error - - // Returns the return value of “[object Object]”. - // This method passes this handle as the first argument to “[object Object]”. - // If “[object Object]” returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return - // its value. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - Evaluate(expression string, arg ...interface{}) (interface{}, error) - - // Returns the return value of “[object Object]” as a [JSHandle]. - // This method passes this handle as the first argument to “[object Object]”. - // The only difference between `jsHandle.evaluate` and `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` - // returns [JSHandle]. - // If the function passed to the `jsHandle.evaluateHandle` returns a [Promise], then `jsHandle.evaluateHandle` would - // wait for the promise to resolve and return its value. - // See [Page.EvaluateHandle] for more details. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - EvaluateHandle(expression string, arg ...interface{}) (JSHandle, error) - - // The method returns a map with **own property names** as keys and JSHandle instances for the property values. - GetProperties() (map[string]JSHandle, error) - - // Fetches a single property from the referenced object. - // - // propertyName: property to get - GetProperty(propertyName string) (JSHandle, error) - - // Returns a JSON representation of the object. If the object has a `toJSON` function, it **will not be called**. - // **NOTE** The method will return an empty JSON object if the referenced object is not stringifiable. It will throw - // an error if the object has circular references. - JSONValue() (interface{}, error) - - String() string -} - -// Keyboard provides an api for managing a virtual keyboard. The high level api is [Keyboard.Type], which takes raw -// characters and generates proper `keydown`, `keypress`/`input`, and `keyup` events on your page. -// For finer control, you can use [Keyboard.Down], [Keyboard.Up], and [Keyboard.InsertText] to manually fire events as -// if they were generated from a real keyboard. -// An example of holding down `Shift` in order to select and delete some text: -// An example of pressing uppercase `A` -// An example to trigger select-all with the keyboard -type Keyboard interface { - // Dispatches a `keydown` event. - // “[object Object]” can specify the intended - // [keyboardEvent.Key] value or a single character - // to generate the text for. A superset of the “[object Object]” values can be found - // [here]. Examples of the keys are: - // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, - // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, - // etc. - // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, - // `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS. - // Holding down `Shift` will type the text that corresponds to the “[object Object]” in the upper case. - // If “[object Object]” is a single character, it is case-sensitive, so the values `a` and `A` will generate different - // respective texts. - // If “[object Object]” is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`, subsequent key presses will be sent - // with that modifier active. To release the modifier key, use [Keyboard.Up]. - // After the key is pressed once, subsequent calls to [Keyboard.Down] will have - // [repeat] set to true. To release the key, - // use [Keyboard.Up]. - // **NOTE** Modifier keys DO influence `keyboard.down`. Holding down `Shift` will type the text in upper case. - // - // key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. - // - // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key - // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values - // [repeat]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat - Down(key string) error - - // Dispatches only `input` event, does not emit the `keydown`, `keyup` or `keypress` events. - // - // text: Sets input to the specified text value. - InsertText(text string) error - - // **NOTE** In most cases, you should use [Locator.Press] instead. - // “[object Object]” can specify the intended - // [keyboardEvent.Key] value or a single character - // to generate the text for. A superset of the “[object Object]” values can be found - // [here]. Examples of the keys are: - // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, - // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, - // etc. - // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, - // `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS. - // Holding down `Shift` will type the text that corresponds to the “[object Object]” in the upper case. - // If “[object Object]” is a single character, it is case-sensitive, so the values `a` and `A` will generate different - // respective texts. - // Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When - // specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. - // - // key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. - // - // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key - // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values - Press(key string, options ...KeyboardPressOptions) error - - // **NOTE** In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is - // special keyboard handling on the page - in this case use [Locator.PressSequentially]. - // Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. - // To press a special key, like `Control` or `ArrowDown`, use [Keyboard.Press]. - // - // text: A text to type into a focused element. - Type(text string, options ...KeyboardTypeOptions) error - - // Dispatches a `keyup` event. - // - // key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. - Up(key string) error -} - -// Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent a -// way to find element(s) on the page at any moment. A locator can be created with the [Page.Locator] method. -// [Learn more about locators]. -// -// [Learn more about locators]: https://playwright.dev/docs/locators -type Locator interface { - // When the locator points to a list of elements, this returns an array of locators, pointing to their respective - // elements. - // **NOTE** [Locator.All] does not wait for elements to match the locator, and instead immediately returns whatever is - // present in the page. - // When the list of elements changes dynamically, [Locator.All] will produce unpredictable and flaky results. - // When the list of elements is stable, but loaded dynamically, wait for the full list to finish loading before - // calling [Locator.All]. - All() ([]Locator, error) - - // Returns an array of `node.innerText` values for all matching nodes. - // **NOTE** If you need to assert text on the page, prefer [LocatorAssertions.ToHaveText] with “[object Object]” - // option to avoid flakiness. See [assertions guide] for more details. - // - // [assertions guide]: https://playwright.dev/docs/test-assertions - AllInnerTexts() ([]string, error) - - // Returns an array of `node.textContent` values for all matching nodes. - // **NOTE** If you need to assert text on the page, prefer [LocatorAssertions.ToHaveText] to avoid flakiness. See - // [assertions guide] for more details. - // - // [assertions guide]: https://playwright.dev/docs/test-assertions - AllTextContents() ([]string, error) - - // Creates a locator that matches both this locator and the argument locator. - // - // locator: Additional locator to match. - And(locator Locator) Locator - - // Captures the aria snapshot of the given element. Read more about [aria snapshots] and - // [LocatorAssertions.ToMatchAriaSnapshot] for the corresponding assertion. - // - // # Details - // - // This method captures the aria snapshot of the given element. The snapshot is a string that represents the state of - // the element and its children. The snapshot can be used to assert the state of the element in the test, or to - // compare it to state in the future. - // The ARIA snapshot is represented using [YAML] markup language: - // - The keys of the objects are the roles and optional accessible names of the elements. - // - The values are either text content or an array of child elements. - // - Generic static text can be represented with the `text` key. - // Below is the HTML markup and the respective ARIA snapshot: - // ```html - // <ul aria-label="Links"> - // <li><a href="/">Home</a></li> - // <li><a href="/about">About</a></li> - // <ul> - // ``` - // ```yml - // - list "Links": - // - listitem: - // - link "Home" - // - listitem: - // - link "About" - // ``` - // - // [aria snapshots]: https://playwright.dev/docs/aria-snapshots - // [YAML]: https://yaml.org/spec/1.2.2/ - AriaSnapshot(options ...LocatorAriaSnapshotOptions) (string, error) - - // Calls [blur] on the element. - // - // [blur]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur - Blur(options ...LocatorBlurOptions) error - - // This method returns the bounding box of the element matching the locator, or `null` if the element is not visible. - // The bounding box is calculated relative to the main frame viewport - which is usually the same as the browser - // window. - // - // # Details - // - // Scrolling affects the returned bounding box, similarly to - // [Element.GetBoundingClientRect]. - // That means `x` and/or `y` may be negative. - // Elements from child frames return the bounding box relative to the main frame, unlike the - // [Element.GetBoundingClientRect]. - // Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the - // following snippet should click the center of the element. - // - // [Element.GetBoundingClientRect]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect - // [Element.GetBoundingClientRect]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect - BoundingBox(options ...LocatorBoundingBoxOptions) (*Rect, error) - - // Ensure that checkbox or radio element is checked. - // - // # Details - // - // Performs the following steps: - // 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already - // checked, this method returns immediately. - // 2. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Mouse] to click in the center of the element. - // 5. Ensure that the element is now checked. If not, this method throws. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // [actionability]: https://playwright.dev/docs/actionability - Check(options ...LocatorCheckOptions) error - - // Clear the input field. - // - // # Details - // - // This method waits for [actionability] checks, focuses the element, clears it and triggers an - // `input` event after clearing. - // If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an - // error. However, if the element is inside the `<label>` element that has an associated - // [control], the control will be cleared - // instead. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - Clear(options ...LocatorClearOptions) error - - // Click an element. - // - // # Details - // - // This method clicks the element by performing the following steps: - // 1. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 2. Scroll the element into view if needed. - // 3. Use [Page.Mouse] to click in the center of the element, or the specified “[object Object]”. - // 4. Wait for initiated navigations to either succeed or fail, unless “[object Object]” option is set. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // [actionability]: https://playwright.dev/docs/actionability - Click(options ...LocatorClickOptions) error - - // Returns the number of elements matching the locator. - // **NOTE** If you need to assert the number of elements on the page, prefer [LocatorAssertions.ToHaveCount] to avoid - // flakiness. See [assertions guide] for more details. - // - // [assertions guide]: https://playwright.dev/docs/test-assertions - Count() (int, error) - - // Double-click an element. - // - // # Details - // - // This method double clicks the element by performing the following steps: - // 1. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 2. Scroll the element into view if needed. - // 3. Use [Page.Mouse] to double click in the center of the element, or the specified “[object Object]”. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // **NOTE** `element.dblclick()` dispatches two `click` events and a single `dblclick` event. - // - // [actionability]: https://playwright.dev/docs/actionability - Dblclick(options ...LocatorDblclickOptions) error - - // Programmatically dispatch an event on the matching element. - // - // # Details - // - // The snippet above dispatches the `click` event on the element. Regardless of the visibility state of the element, - // `click` is dispatched. This is equivalent to calling - // [element.Click()]. - // Under the hood, it creates an instance of an event based on the given “[object Object]”, initializes it with - // “[object Object]” properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by - // default. - // Since “[object Object]” is event-specific, please refer to the events documentation for the lists of initial - // properties: - // - [DeviceMotionEvent] - // - [DeviceOrientationEvent] - // - [DragEvent] - // - [Event] - // - [FocusEvent] - // - [KeyboardEvent] - // - [MouseEvent] - // - [PointerEvent] - // - [TouchEvent] - // - [WheelEvent] - // You can also specify [JSHandle] as the property value if you want live objects to be passed into the event: - // - // 1. typ: DOM event type: `"click"`, `"dragstart"`, etc. - // 2. eventInit: Optional event-specific initialization properties. - // - // [element.Click()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click - // [DeviceMotionEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent - // [DeviceOrientationEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent - // [DragEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent - // [Event]: https://developer.mozilla.org/en-US/docs/Web/API/Event/Event - // [FocusEvent]: https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent - // [KeyboardEvent]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent - // [MouseEvent]: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent - // [PointerEvent]: https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent - // [TouchEvent]: https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent - // [WheelEvent]: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent - DispatchEvent(typ string, eventInit interface{}, options ...LocatorDispatchEventOptions) error - - // Drag the source element towards the target element and drop it. - // - // # Details - // - // This method drags the locator to another target locator or target position. It will first move to the source - // element, perform a `mousedown`, then move to the target element or position and perform a `mouseup`. - // - // target: Locator of the element to drag to. - DragTo(target Locator, options ...LocatorDragToOptions) error - - // Resolves given locator to the first matching DOM element. If there are no matching elements, waits for one. If - // multiple elements match the locator, throws. - // - // Deprecated: Always prefer using [Locator]s and web assertions over [ElementHandle]s because latter are inherently racy. - ElementHandle(options ...LocatorElementHandleOptions) (ElementHandle, error) - - // Resolves given locator to all matching DOM elements. If there are no matching elements, returns an empty list. - // - // Deprecated: Always prefer using [Locator]s and web assertions over [ElementHandle]s because latter are inherently racy. - ElementHandles() ([]ElementHandle, error) - - // Returns a [FrameLocator] object pointing to the same `iframe` as this locator. - // Useful when you have a [Locator] object obtained somewhere, and later on would like to interact with the content - // inside the frame. - // For a reverse operation, use [FrameLocator.Owner]. - ContentFrame() FrameLocator - - // Execute JavaScript code in the page, taking the matching element as an argument. - // - // # Details - // - // Returns the return value of “[object Object]”, called with the matching element as a first argument, and - // “[object Object]” as a second argument. - // If “[object Object]” returns a [Promise], this method will wait for the promise to resolve and return its value. - // If “[object Object]” throws or rejects, this method throws. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - Evaluate(expression string, arg interface{}, options ...LocatorEvaluateOptions) (interface{}, error) - - // Execute JavaScript code in the page, taking all matching elements as an argument. - // - // # Details - // - // Returns the return value of “[object Object]”, called with an array of all matching elements as a first argument, - // and “[object Object]” as a second argument. - // If “[object Object]” returns a [Promise], this method will wait for the promise to resolve and return its value. - // If “[object Object]” throws or rejects, this method throws. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - EvaluateAll(expression string, arg ...interface{}) (interface{}, error) - - // Execute JavaScript code in the page, taking the matching element as an argument, and return a [JSHandle] with the - // result. - // - // # Details - // - // Returns the return value of “[object Object]” as a[JSHandle], called with the matching element as a first argument, - // and “[object Object]” as a second argument. - // The only difference between [Locator.Evaluate] and [Locator.EvaluateHandle] is that [Locator.EvaluateHandle] - // returns [JSHandle]. - // If “[object Object]” returns a [Promise], this method will wait for the promise to resolve and return its value. - // If “[object Object]” throws or rejects, this method throws. - // See [Page.EvaluateHandle] for more details. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - EvaluateHandle(expression string, arg interface{}, options ...LocatorEvaluateHandleOptions) (JSHandle, error) - - // Set a value to the input field. - // - // # Details - // - // This method waits for [actionability] checks, focuses the element, fills it and triggers an - // `input` event after filling. Note that you can pass an empty string to clear the input field. - // If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an - // error. However, if the element is inside the `<label>` element that has an associated - // [control], the control will be filled - // instead. - // To send fine-grained keyboard events, use [Locator.PressSequentially]. - // - // value: Value to set for the `<input>`, `<textarea>` or `[contenteditable]` element. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - Fill(value string, options ...LocatorFillOptions) error - - // This method narrows existing locator according to the options, for example filters by text. It can be chained to - // filter multiple times. - Filter(options ...LocatorFilterOptions) Locator - - // Returns locator to the first matching element. - First() Locator - - // Calls [focus] on the matching element. - // - // [focus]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus - Focus(options ...LocatorFocusOptions) error - - // When working with iframes, you can create a frame locator that will enter the iframe and allow locating elements in - // that iframe: - // - // selector: A selector to use when resolving DOM element. - FrameLocator(selector string) FrameLocator - - // Returns the matching element's attribute value. - // **NOTE** If you need to assert an element's attribute, prefer [LocatorAssertions.ToHaveAttribute] to avoid - // flakiness. See [assertions guide] for more details. - // - // name: Attribute name to get the value for. - // - // [assertions guide]: https://playwright.dev/docs/test-assertions - GetAttribute(name string, options ...LocatorGetAttributeOptions) (string, error) - - // Allows locating elements by their alt text. - // - // text: Text to locate the element for. - GetByAltText(text interface{}, options ...LocatorGetByAltTextOptions) Locator - - // Allows locating input elements by the text of the associated `<label>` or `aria-labelledby` element, or by the - // `aria-label` attribute. - // - // text: Text to locate the element for. - GetByLabel(text interface{}, options ...LocatorGetByLabelOptions) Locator - - // Allows locating input elements by the placeholder text. - // - // text: Text to locate the element for. - GetByPlaceholder(text interface{}, options ...LocatorGetByPlaceholderOptions) Locator - - // Allows locating elements by their [ARIA role], - // [ARIA attributes] and - // [accessible name]. - // - // # Details - // - // Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback - // about the ARIA guidelines. - // Many html elements have an implicitly [defined role] - // that is recognized by the role selector. You can find all the - // [supported roles here]. ARIA guidelines **do not recommend** - // duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values. - // - // role: Required aria role. - // - // [ARIA role]: https://www.w3.org/TR/wai-aria-1.2/#roles - // [ARIA attributes]: https://www.w3.org/TR/wai-aria-1.2/#aria-attributes - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - // [defined role]: https://w3c.github.io/html-aam/#html-element-role-mappings - // [supported roles here]: https://www.w3.org/TR/wai-aria-1.2/#role_definitions - GetByRole(role AriaRole, options ...LocatorGetByRoleOptions) Locator - - // Locate element by the test id. - // - // # Details - // - // By default, the `data-testid` attribute is used as a test id. Use [Selectors.SetTestIdAttribute] to configure a - // different test id attribute if necessary. - // - // testId: Id to locate the element by. - GetByTestId(testId interface{}) Locator - - // Allows locating elements that contain given text. - // See also [Locator.Filter] that allows to match by another criteria, like an accessible role, and then filter by the - // text content. - // - // # Details - // - // Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into - // one, turns line breaks into spaces and ignores leading and trailing whitespace. - // Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For - // example, locating by text `"Log in"` matches `<input type=button value="Log in">`. - // - // text: Text to locate the element for. - GetByText(text interface{}, options ...LocatorGetByTextOptions) Locator - - // Allows locating elements by their title attribute. - // - // text: Text to locate the element for. - GetByTitle(text interface{}, options ...LocatorGetByTitleOptions) Locator - - // Highlight the corresponding element(s) on the screen. Useful for debugging, don't commit the code that uses - // [Locator.Highlight]. - Highlight() error - - // Hover over the matching element. - // - // # Details - // - // This method hovers over the element by performing the following steps: - // 1. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 2. Scroll the element into view if needed. - // 3. Use [Page.Mouse] to hover over the center of the element, or the specified “[object Object]”. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // [actionability]: https://playwright.dev/docs/actionability - Hover(options ...LocatorHoverOptions) error - - // Returns the [`element.innerHTML`]. - // - // [`element.innerHTML`]: https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML - InnerHTML(options ...LocatorInnerHTMLOptions) (string, error) - - // Returns the [`element.innerText`]. - // **NOTE** If you need to assert text on the page, prefer [LocatorAssertions.ToHaveText] with “[object Object]” - // option to avoid flakiness. See [assertions guide] for more details. - // - // [`element.innerText`]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText - // [assertions guide]: https://playwright.dev/docs/test-assertions - InnerText(options ...LocatorInnerTextOptions) (string, error) - - // Returns the value for the matching `<input>` or `<textarea>` or `<select>` element. - // **NOTE** If you need to assert input value, prefer [LocatorAssertions.ToHaveValue] to avoid flakiness. See - // [assertions guide] for more details. - // - // # Details - // - // Throws elements that are not an input, textarea or a select. However, if the element is inside the `<label>` - // element that has an associated - // [control], returns the value of the - // control. - // - // [assertions guide]: https://playwright.dev/docs/test-assertions - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - InputValue(options ...LocatorInputValueOptions) (string, error) - - // Returns whether the element is checked. Throws if the element is not a checkbox or radio input. - // **NOTE** If you need to assert that checkbox is checked, prefer [LocatorAssertions.ToBeChecked] to avoid flakiness. - // See [assertions guide] for more details. - // - // [assertions guide]: https://playwright.dev/docs/test-assertions - IsChecked(options ...LocatorIsCheckedOptions) (bool, error) - - // Returns whether the element is disabled, the opposite of [enabled]. - // **NOTE** If you need to assert that an element is disabled, prefer [LocatorAssertions.ToBeDisabled] to avoid - // flakiness. See [assertions guide] for more details. - // - // [enabled]: https://playwright.dev/docs/actionability#enabled - // [assertions guide]: https://playwright.dev/docs/test-assertions - IsDisabled(options ...LocatorIsDisabledOptions) (bool, error) - - // Returns whether the element is [editable]. If the target element is not an `<input>`, - // `<textarea>`, `<select>`, `[contenteditable]` and does not have a role allowing `[aria-readonly]`, this method - // throws an error. - // **NOTE** If you need to assert that an element is editable, prefer [LocatorAssertions.ToBeEditable] to avoid - // flakiness. See [assertions guide] for more details. - // - // [editable]: https://playwright.dev/docs/actionability#editable - // [assertions guide]: https://playwright.dev/docs/test-assertions - IsEditable(options ...LocatorIsEditableOptions) (bool, error) - - // Returns whether the element is [enabled]. - // **NOTE** If you need to assert that an element is enabled, prefer [LocatorAssertions.ToBeEnabled] to avoid - // flakiness. See [assertions guide] for more details. - // - // [enabled]: https://playwright.dev/docs/actionability#enabled - // [assertions guide]: https://playwright.dev/docs/test-assertions - IsEnabled(options ...LocatorIsEnabledOptions) (bool, error) - - // Returns whether the element is hidden, the opposite of [visible]. - // **NOTE** If you need to assert that element is hidden, prefer [LocatorAssertions.ToBeHidden] to avoid flakiness. - // See [assertions guide] for more details. - // - // [visible]: https://playwright.dev/docs/actionability#visible - // [assertions guide]: https://playwright.dev/docs/test-assertions - IsHidden(options ...LocatorIsHiddenOptions) (bool, error) - - // Returns whether the element is [visible]. - // **NOTE** If you need to assert that element is visible, prefer [LocatorAssertions.ToBeVisible] to avoid flakiness. - // See [assertions guide] for more details. - // - // [visible]: https://playwright.dev/docs/actionability#visible - // [assertions guide]: https://playwright.dev/docs/test-assertions - IsVisible(options ...LocatorIsVisibleOptions) (bool, error) - - // Returns locator to the last matching element. - Last() Locator - - // The method finds an element matching the specified selector in the locator's subtree. It also accepts filter - // options, similar to [Locator.Filter] method. - // [Learn more about locators]. - // - // selectorOrLocator: A selector or locator to use when resolving DOM element. - // - // [Learn more about locators]: https://playwright.dev/docs/locators - Locator(selectorOrLocator interface{}, options ...LocatorLocatorOptions) Locator - - // Returns locator to the n-th matching element. It's zero based, `nth(0)` selects the first element. - Nth(index int) Locator - - // Creates a locator matching all elements that match one or both of the two locators. - // Note that when both locators match something, the resulting locator will have multiple matches, potentially causing - // a [locator strictness] violation. - // - // locator: Alternative locator to match. - // - // [locator strictness]: https://playwright.dev/docs/locators#strictness - // ["strict mode violation" error]: https://playwright.dev/docs/locators#strictness - Or(locator Locator) Locator - - // A page this locator belongs to. - Page() (Page, error) - - // Focuses the matching element and presses a combination of the keys. - // - // # Details - // - // Focuses the element, and then uses [Keyboard.Down] and [Keyboard.Up]. - // “[object Object]” can specify the intended - // [keyboardEvent.Key] value or a single character - // to generate the text for. A superset of the “[object Object]” values can be found - // [here]. Examples of the keys are: - // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, - // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, - // etc. - // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, - // `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS. - // Holding down `Shift` will type the text that corresponds to the “[object Object]” in the upper case. - // If “[object Object]” is a single character, it is case-sensitive, so the values `a` and `A` will generate different - // respective texts. - // Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When - // specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. - // - // key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. - // - // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key - // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values - Press(key string, options ...LocatorPressOptions) error - - // **NOTE** In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is - // special keyboard handling on the page. - // Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the - // text. - // To press a special key, like `Control` or `ArrowDown`, use [Locator.Press]. - // - // text: String of characters to sequentially press into a focused element. - PressSequentially(text string, options ...LocatorPressSequentiallyOptions) error - - // Take a screenshot of the element matching the locator. - // - // # Details - // - // This method captures a screenshot of the page, clipped to the size and position of a particular element matching - // the locator. If the element is covered by other elements, it will not be actually visible on the screenshot. If the - // element is a scrollable container, only the currently scrolled content will be visible on the screenshot. - // This method waits for the [actionability] checks, then scrolls element into view before taking - // a screenshot. If the element is detached from DOM, the method throws an error. - // Returns the buffer with the captured screenshot. - // - // [actionability]: https://playwright.dev/docs/actionability - Screenshot(options ...LocatorScreenshotOptions) ([]byte, error) - - // This method waits for [actionability] checks, then tries to scroll element into view, unless - // it is completely visible as defined by - // [IntersectionObserver]'s `ratio`. - // See [scrolling] for alternative ways to scroll. - // - // [actionability]: https://playwright.dev/docs/actionability - // [IntersectionObserver]: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API - // [scrolling]: https://playwright.dev/docs/input#scrolling - ScrollIntoViewIfNeeded(options ...LocatorScrollIntoViewIfNeededOptions) error - - // Selects option or options in `<select>`. - // - // # Details - // - // This method waits for [actionability] checks, waits until all specified options are present in - // the `<select>` element and selects these options. - // If the target element is not a `<select>` element, this method throws an error. However, if the element is inside - // the `<label>` element that has an associated - // [control], the control will be used - // instead. - // Returns the array of option values that have been successfully selected. - // Triggers a `change` and `input` event once all the provided options have been selected. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - SelectOption(values SelectOptionValues, options ...LocatorSelectOptionOptions) ([]string, error) - - // This method waits for [actionability] checks, then focuses the element and selects all its - // text content. - // If the element is inside the `<label>` element that has an associated - // [control], focuses and selects text in - // the control instead. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - SelectText(options ...LocatorSelectTextOptions) error - - // Set the state of a checkbox or a radio element. - // - // # Details - // - // This method checks or unchecks an element by performing the following steps: - // 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. - // 2. If the element already has the right checked state, this method returns immediately. - // 3. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 4. Scroll the element into view if needed. - // 5. Use [Page.Mouse] to click in the center of the element. - // 6. Ensure that the element is now checked or unchecked. If not, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // checked: Whether to check or uncheck the checkbox. - // - // [actionability]: https://playwright.dev/docs/actionability - SetChecked(checked bool, options ...LocatorSetCheckedOptions) error - - // Upload file or multiple files into `<input type=file>`. For inputs with a `[webkitdirectory]` attribute, only a - // single directory path is supported. - // - // # Details - // - // Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then - // they are resolved relative to the current working directory. For empty array, clears the selected files. - // This method expects [Locator] to point to an - // [input element]. However, if the element is inside - // the `<label>` element that has an associated - // [control], targets the control instead. - // - // [input element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - SetInputFiles(files interface{}, options ...LocatorSetInputFilesOptions) error - - // Perform a tap gesture on the element matching the locator. For examples of emulating other gestures by manually - // dispatching touch events, see the [emulating legacy touch events] page. - // - // # Details - // - // This method taps the element by performing the following steps: - // 1. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 2. Scroll the element into view if needed. - // 3. Use [Page.Touchscreen] to tap the center of the element, or the specified “[object Object]”. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // **NOTE** `element.tap()` requires that the `hasTouch` option of the browser context be set to true. - // - // [emulating legacy touch events]: https://playwright.dev/docs/touch-events - // [actionability]: https://playwright.dev/docs/actionability - Tap(options ...LocatorTapOptions) error - - // Returns the [`node.textContent`]. - // **NOTE** If you need to assert text on the page, prefer [LocatorAssertions.ToHaveText] to avoid flakiness. See - // [assertions guide] for more details. - // - // [`node.textContent`]: https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent - // [assertions guide]: https://playwright.dev/docs/test-assertions - TextContent(options ...LocatorTextContentOptions) (string, error) - - // Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the - // text. - // To press a special key, like `Control` or `ArrowDown`, use [Locator.Press]. - // - // Deprecated: In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [Locator.PressSequentially]. - // - // text: A text to type into a focused element. - Type(text string, options ...LocatorTypeOptions) error - - // Ensure that checkbox or radio element is unchecked. - // - // # Details - // - // This method unchecks the element by performing the following steps: - // 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already - // unchecked, this method returns immediately. - // 2. Wait for [actionability] checks on the element, unless “[object Object]” option is set. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Mouse] to click in the center of the element. - // 5. Ensure that the element is now unchecked. If not, this method throws. - // If the element is detached from the DOM at any moment during the action, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // [actionability]: https://playwright.dev/docs/actionability - Uncheck(options ...LocatorUncheckOptions) error - - // Returns when element specified by locator satisfies the “[object Object]” option. - // If target element already satisfies the condition, the method returns immediately. Otherwise, waits for up to - // “[object Object]” milliseconds until the condition is met. - WaitFor(options ...LocatorWaitForOptions) error - - Err() error -} - -// The [LocatorAssertions] class provides assertion methods that can be used to make assertions about the [Locator] -// state in the tests. -type LocatorAssertions interface { - // Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain - // text `"error"`: - Not() LocatorAssertions - - // Ensures that [Locator] points to an element that is - // [connected] to a Document or a ShadowRoot. - // - // [connected]: https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected - ToBeAttached(options ...LocatorAssertionsToBeAttachedOptions) error - - // Ensures the [Locator] points to a checked input. - ToBeChecked(options ...LocatorAssertionsToBeCheckedOptions) error - - // Ensures the [Locator] points to a disabled element. Element is disabled if it has "disabled" attribute or is - // disabled via - // ['aria-disabled']. Note - // that only native control elements such as HTML `button`, `input`, `select`, `textarea`, `option`, `optgroup` can be - // disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser. - // - // ['aria-disabled']: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled - ToBeDisabled(options ...LocatorAssertionsToBeDisabledOptions) error - - // Ensures the [Locator] points to an editable element. - ToBeEditable(options ...LocatorAssertionsToBeEditableOptions) error - - // Ensures the [Locator] points to an empty editable element or to a DOM node that has no text. - ToBeEmpty(options ...LocatorAssertionsToBeEmptyOptions) error - - // Ensures the [Locator] points to an enabled element. - ToBeEnabled(options ...LocatorAssertionsToBeEnabledOptions) error - - // Ensures the [Locator] points to a focused DOM node. - ToBeFocused(options ...LocatorAssertionsToBeFocusedOptions) error - - // Ensures that [Locator] either does not resolve to any DOM node, or resolves to a - // [non-visible] one. - // - // [non-visible]: https://playwright.dev/docs/actionability#visible - ToBeHidden(options ...LocatorAssertionsToBeHiddenOptions) error - - // Ensures the [Locator] points to an element that intersects viewport, according to the - // [intersection observer API]. - // - // [intersection observer API]: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API - ToBeInViewport(options ...LocatorAssertionsToBeInViewportOptions) error - - // Ensures that [Locator] points to an attached and [visible] DOM node. - // To check that at least one element from the list is visible, use [Locator.First]. - // - // [visible]: https://playwright.dev/docs/actionability#visible - ToBeVisible(options ...LocatorAssertionsToBeVisibleOptions) error - - // Ensures the [Locator] points to an element with given CSS classes. All classes from the asserted value, separated - // by spaces, must be present in the - // [Element.ClassList] in any order. - // - // expected: A string containing expected class names, separated by spaces, or a list of such strings to assert multiple - // elements. - // - // [Element.ClassList]: https://developer.mozilla.org/en-US/docs/Web/API/Element/classList - ToContainClass(expected interface{}, options ...LocatorAssertionsToContainClassOptions) error - - // Ensures the [Locator] points to an element that contains the given text. All nested elements will be considered - // when computing the text content of the element. You can use regular expressions for the value as well. - // - // # Details - // - // When `expected` parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual - // text and in the expected string before matching. When regular expression is used, the actual text is matched as is. - // - // expected: Expected substring or RegExp or a list of those. - ToContainText(expected interface{}, options ...LocatorAssertionsToContainTextOptions) error - - // Ensures the [Locator] points to an element with a given - // [accessible description]. - // - // description: Expected accessible description. - // - // [accessible description]: https://w3c.github.io/accname/#dfn-accessible-description - ToHaveAccessibleDescription(description interface{}, options ...LocatorAssertionsToHaveAccessibleDescriptionOptions) error - - // Ensures the [Locator] points to an element with a given - // [aria errormessage]. - // - // errorMessage: Expected accessible error message. - // - // [aria errormessage]: https://w3c.github.io/aria/#aria-errormessage - ToHaveAccessibleErrorMessage(errorMessage interface{}, options ...LocatorAssertionsToHaveAccessibleErrorMessageOptions) error - - // Ensures the [Locator] points to an element with a given - // [accessible name]. - // - // name: Expected accessible name. - // - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - ToHaveAccessibleName(name interface{}, options ...LocatorAssertionsToHaveAccessibleNameOptions) error - - // Ensures the [Locator] points to an element with given attribute. - // - // 1. name: Attribute name. - // 2. value: Expected attribute value. - ToHaveAttribute(name string, value interface{}, options ...LocatorAssertionsToHaveAttributeOptions) error - - // Ensures the [Locator] points to an element with given CSS classes. When a string is provided, it must fully match - // the element's `class` attribute. To match individual classes use [LocatorAssertions.ToContainClass]. - // - // expected: Expected class or RegExp or a list of those. - ToHaveClass(expected interface{}, options ...LocatorAssertionsToHaveClassOptions) error - - // Ensures the [Locator] resolves to an exact number of DOM nodes. - // - // count: Expected count. - ToHaveCount(count int, options ...LocatorAssertionsToHaveCountOptions) error - - // Ensures the [Locator] resolves to an element with the given computed CSS style. - // - // 1. name: CSS property name. - // 2. value: CSS property value. - ToHaveCSS(name string, value interface{}, options ...LocatorAssertionsToHaveCSSOptions) error - - // Ensures the [Locator] points to an element with the given DOM Node ID. - // - // id: Element id. - ToHaveId(id interface{}, options ...LocatorAssertionsToHaveIdOptions) error - - // Ensures the [Locator] points to an element with given JavaScript property. Note that this property can be of a - // primitive type as well as a plain serializable JavaScript object. - // - // 1. name: Property name. - // 2. value: Property value. - ToHaveJSProperty(name string, value interface{}, options ...LocatorAssertionsToHaveJSPropertyOptions) error - - // Ensures the [Locator] points to an element with a given [ARIA role]. - // Note that role is matched as a string, disregarding the ARIA role hierarchy. For example, asserting a superclass - // role `"checkbox"` on an element with a subclass role `"switch"` will fail. - // - // role: Required aria role. - // - // [ARIA role]: https://www.w3.org/TR/wai-aria-1.2/#roles - ToHaveRole(role AriaRole, options ...LocatorAssertionsToHaveRoleOptions) error - - // Ensures the [Locator] points to an element with the given text. All nested elements will be considered when - // computing the text content of the element. You can use regular expressions for the value as well. - // - // # Details - // - // When `expected` parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual - // text and in the expected string before matching. When regular expression is used, the actual text is matched as is. - // - // expected: Expected string or RegExp or a list of those. - ToHaveText(expected interface{}, options ...LocatorAssertionsToHaveTextOptions) error - - // Ensures the [Locator] points to an element with the given input value. You can use regular expressions for the - // value as well. - // - // value: Expected value. - ToHaveValue(value interface{}, options ...LocatorAssertionsToHaveValueOptions) error - - // Ensures the [Locator] points to multi-select/combobox (i.e. a `select` with the `multiple` attribute) and the - // specified values are selected. - // - // values: Expected options currently selected. - ToHaveValues(values []interface{}, options ...LocatorAssertionsToHaveValuesOptions) error - - // Asserts that the target element matches the given [accessibility snapshot]. - // - // [accessibility snapshot]: https://playwright.dev/docs/aria-snapshots - ToMatchAriaSnapshot(expected string, options ...LocatorAssertionsToMatchAriaSnapshotOptions) error -} - -// The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport. -// Every `page` object has its own Mouse, accessible with [Page.Mouse]. -type Mouse interface { - // Shortcut for [Mouse.Move], [Mouse.Down], [Mouse.Up]. - // - // 1. x: X coordinate relative to the main frame's viewport in CSS pixels. - // 2. y: Y coordinate relative to the main frame's viewport in CSS pixels. - Click(x float64, y float64, options ...MouseClickOptions) error - - // Shortcut for [Mouse.Move], [Mouse.Down], [Mouse.Up], [Mouse.Down] and [Mouse.Up]. - // - // 1. x: X coordinate relative to the main frame's viewport in CSS pixels. - // 2. y: Y coordinate relative to the main frame's viewport in CSS pixels. - Dblclick(x float64, y float64, options ...MouseDblclickOptions) error - - // Dispatches a `mousedown` event. - Down(options ...MouseDownOptions) error - - // Dispatches a `mousemove` event. - // - // 1. x: X coordinate relative to the main frame's viewport in CSS pixels. - // 2. y: Y coordinate relative to the main frame's viewport in CSS pixels. - Move(x float64, y float64, options ...MouseMoveOptions) error - - // Dispatches a `mouseup` event. - Up(options ...MouseUpOptions) error - - // Dispatches a `wheel` event. This method is usually used to manually scroll the page. See - // [scrolling] for alternative ways to scroll. - // **NOTE** Wheel events may cause scrolling if they are not handled, and this method does not wait for the scrolling - // to finish before returning. - // - // 1. deltaX: Pixels to scroll horizontally. - // 2. deltaY: Pixels to scroll vertically. - // - // [scrolling]: https://playwright.dev/docs/input#scrolling - Wheel(deltaX float64, deltaY float64) error -} - -// Page provides methods to interact with a single tab in a [Browser], or an -// [extension background page] in Chromium. One [Browser] -// instance might have multiple [Page] instances. -// This example creates a page, navigates it to a URL, and then saves a screenshot: -// The Page class emits various events (described below) which can be handled using any of Node's native -// [`EventEmitter`] methods, such as `on`, `once` or -// `removeListener`. -// This example logs a message for a single page `load` event: -// To unsubscribe from events use the `removeListener` method: -// -// [extension background page]: https://developer.chrome.com/extensions/background_pages -// [`EventEmitter`]: https://nodejs.org/api/events.html#events_class_eventemitter -type Page interface { - EventEmitter - // Playwright has ability to mock clock and passage of time. - Clock() Clock - - // Emitted when the page closes. - OnClose(fn func(Page)) - - // Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. - // The arguments passed into `console.log` are available on the [ConsoleMessage] event handler argument. - OnConsole(fn func(ConsoleMessage)) - - // Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page - // crashes, ongoing and subsequent operations will throw. - // The most common way to deal with crashes is to catch an exception: - OnCrash(fn func(Page)) - - // Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must** - // either [Dialog.Accept] or [Dialog.Dismiss] the dialog - otherwise the page will - // [freeze] waiting for the dialog, - // and actions like click will never finish. - // - // [freeze]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking - OnDialog(fn func(Dialog)) - - // Emitted when the JavaScript - // [`DOMContentLoaded`] event is dispatched. - // - // [`DOMContentLoaded`]: https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded - OnDOMContentLoaded(fn func(Page)) - - // Emitted when attachment download started. User can access basic file operations on downloaded content via the - // passed [Download] instance. - OnDownload(fn func(Download)) - - // Emitted when a file chooser is supposed to appear, such as after clicking the `<input type=file>`. Playwright can - // respond to it via setting the input files using [FileChooser.SetFiles] that can be uploaded after that. - OnFileChooser(fn func(FileChooser)) - - // Emitted when a frame is attached. - OnFrameAttached(fn func(Frame)) - - // Emitted when a frame is detached. - OnFrameDetached(fn func(Frame)) - - // Emitted when a frame is navigated to a new url. - OnFrameNavigated(fn func(Frame)) - - // Emitted when the JavaScript [`load`] event is dispatched. - // - // [`load`]: https://developer.mozilla.org/en-US/docs/Web/Events/load - OnLoad(fn func(Page)) - - // Emitted when an uncaught exception happens within the page. - OnPageError(fn func(error)) - - // Emitted when the page opens a new tab or window. This event is emitted in addition to the [BrowserContext.OnPage], - // but only for popups relevant to this page. - // The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a - // popup with `window.open('http://example.com')`, this event will fire when the network request to - // "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen - // to this network request, use [BrowserContext.Route] and [BrowserContext.OnRequest] respectively instead of similar - // methods on the [Page]. - // **NOTE** Use [Page.WaitForLoadState] to wait until the page gets to a particular state (you should not need it in - // most cases). - OnPopup(fn func(Page)) - - // Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, - // see [Page.Route] or [BrowserContext.Route]. - OnRequest(fn func(Request)) - - // Emitted when a request fails, for example by timing out. - // **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request - // will complete with [Page.OnRequestFinished] event and not with [Page.OnRequestFailed]. A request will only be - // considered failed when the client cannot get an HTTP response from the server, e.g. due to network error - // net::ERR_FAILED. - OnRequestFailed(fn func(Request)) - - // Emitted when a request finishes successfully after downloading the response body. For a successful response, the - // sequence of events is `request`, `response` and `requestfinished`. - OnRequestFinished(fn func(Request)) - - // Emitted when [response] status and headers are received for a request. For a successful response, the sequence of - // events is `request`, `response` and `requestfinished`. - OnResponse(fn func(Response)) - - // Emitted when [WebSocket] request is sent. - OnWebSocket(fn func(WebSocket)) - - // Emitted when a dedicated [WebWorker] is spawned - // by the page. - // - // [WebWorker]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API - OnWorker(fn func(Worker)) - - // Adds a script which would be evaluated in one of the following scenarios: - // - Whenever the page is navigated. - // - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the - // newly attached frame. - // The script is evaluated after the document was created but before any of its scripts were run. This is useful to - // amend the JavaScript environment, e.g. to seed `Math.random`. - // - // script: Script to be evaluated in the page. - AddInitScript(script Script) error - - // Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload - // fires or when the script content was injected into frame. - AddScriptTag(options PageAddScriptTagOptions) (ElementHandle, error) - - // Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the - // content. Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame. - AddStyleTag(options PageAddStyleTagOptions) (ElementHandle, error) - - // Brings page to front (activates tab). - BringToFront() error - - // This method checks an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is - // already checked, this method returns immediately. - // 3. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 4. Scroll the element into view if needed. - // 5. Use [Page.Mouse] to click in the center of the element. - // 6. Ensure that the element is now checked. If not, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Check] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Check(selector string, options ...PageCheckOptions) error - - // This method clicks an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Mouse] to click in the center of the element, or the specified “[object Object]”. - // 5. Wait for initiated navigations to either succeed or fail, unless “[object Object]” option is set. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Click] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Click(selector string, options ...PageClickOptions) error - - // If “[object Object]” is `false`, does not run any unload handlers and waits for the page to be closed. If - // “[object Object]” is `true` the method will run unload handlers, but will **not** wait for the page to close. - // By default, `page.close()` **does not** run `beforeunload` handlers. - // **NOTE** if “[object Object]” is passed as true, a `beforeunload` dialog might be summoned and should be handled - // manually via [Page.OnDialog] event. - Close(options ...PageCloseOptions) error - - // Gets the full HTML contents of the page, including the doctype. - Content() (string, error) - - // Get the browser context that the page belongs to. - Context() BrowserContext - - // This method double clicks an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Mouse] to double click in the center of the element, or the specified “[object Object]”. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // **NOTE** `page.dblclick()` dispatches two `click` events and a single `dblclick` event. - // - // Deprecated: Use locator-based [Locator.Dblclick] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Dblclick(selector string, options ...PageDblclickOptions) error - - // The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, - // `click` is dispatched. This is equivalent to calling - // [element.Click()]. - // - // Deprecated: Use locator-based [Locator.DispatchEvent] instead. Read more about [locators]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. typ: DOM event type: `"click"`, `"dragstart"`, etc. - // 3. eventInit: Optional event-specific initialization properties. - // - // [element.Click()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click - // [DeviceMotionEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent - // [DeviceOrientationEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent - // [DragEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent - // [Event]: https://developer.mozilla.org/en-US/docs/Web/API/Event/Event - // [FocusEvent]: https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent - // [KeyboardEvent]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent - // [MouseEvent]: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent - // [PointerEvent]: https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent - // [TouchEvent]: https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent - // [WheelEvent]: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent - // [locators]: https://playwright.dev/docs/locators - DispatchEvent(selector string, typ string, eventInit interface{}, options ...PageDispatchEventOptions) error - - // This method drags the source element to the target element. It will first move to the source element, perform a - // `mousedown`, then move to the target element and perform a `mouseup`. - // - // 1. source: A selector to search for an element to drag. If there are multiple elements satisfying the selector, the first will - // be used. - // 2. target: A selector to search for an element to drop onto. If there are multiple elements satisfying the selector, the first - // will be used. - DragAndDrop(source string, target string, options ...PageDragAndDropOptions) error - - // This method changes the `CSS media type` through the `media` argument, and/or the `prefers-colors-scheme` media - // feature, using the `colorScheme` argument. - EmulateMedia(options ...PageEmulateMediaOptions) error - - // The method finds an element matching the specified selector within the page and passes it as a first argument to - // “[object Object]”. If no elements match the selector, the method throws an error. Returns the value of - // “[object Object]”. - // If “[object Object]” returns a [Promise], then [Page.EvalOnSelector] would wait for the promise to resolve and - // return its value. - // - // Deprecated: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests. Use [Locator.Evaluate], other [Locator] helper methods or web-first assertions instead. - // - // 1. selector: A selector to query for. - // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 3. arg: Optional argument to pass to “[object Object]”. - EvalOnSelector(selector string, expression string, arg interface{}, options ...PageEvalOnSelectorOptions) (interface{}, error) - - // The method finds all elements matching the specified selector within the page and passes an array of matched - // elements as a first argument to “[object Object]”. Returns the result of “[object Object]” invocation. - // If “[object Object]” returns a [Promise], then [Page.EvalOnSelectorAll] would wait for the promise to resolve and - // return its value. - // - // Deprecated: In most cases, [Locator.EvaluateAll], other [Locator] helper methods and web-first assertions do a better job. - // - // 1. selector: A selector to query for. - // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 3. arg: Optional argument to pass to “[object Object]”. - EvalOnSelectorAll(selector string, expression string, arg ...interface{}) (interface{}, error) - - // Returns the value of the “[object Object]” invocation. - // If the function passed to the [Page.Evaluate] returns a [Promise], then [Page.Evaluate] would wait for the promise - // to resolve and return its value. - // If the function passed to the [Page.Evaluate] returns a non-[Serializable] value, then [Page.Evaluate] resolves to - // `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`: - // `-0`, `NaN`, `Infinity`, `-Infinity`. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - Evaluate(expression string, arg ...interface{}) (interface{}, error) - - // Returns the value of the “[object Object]” invocation as a [JSHandle]. - // The only difference between [Page.Evaluate] and [Page.EvaluateHandle] is that [Page.EvaluateHandle] returns - // [JSHandle]. - // If the function passed to the [Page.EvaluateHandle] returns a [Promise], then [Page.EvaluateHandle] would wait for - // the promise to resolve and return its value. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - EvaluateHandle(expression string, arg ...interface{}) (JSHandle, error) - - // The method adds a function called “[object Object]” on the `window` object of every frame in this page. When - // called, the function executes “[object Object]” and returns a [Promise] which resolves to the return value of - // “[object Object]”. If the “[object Object]” returns a [Promise], it will be awaited. - // The first argument of the “[object Object]” function contains information about the caller: `{ browserContext: - // BrowserContext, page: Page, frame: Frame }`. - // See [BrowserContext.ExposeBinding] for the context-wide version. - // **NOTE** Functions installed via [Page.ExposeBinding] survive navigations. - // - // 1. name: Name of the function on the window object. - // 2. binding: Callback function that will be called in the Playwright's context. - ExposeBinding(name string, binding BindingCallFunction, handle ...bool) error - - // The method adds a function called “[object Object]” on the `window` object of every frame in the page. When called, - // the function executes “[object Object]” and returns a [Promise] which resolves to the return value of - // “[object Object]”. - // If the “[object Object]” returns a [Promise], it will be awaited. - // See [BrowserContext.ExposeFunction] for context-wide exposed function. - // **NOTE** Functions installed via [Page.ExposeFunction] survive navigations. - // - // 1. name: Name of the function on the window object - // 2. binding: Callback function which will be called in Playwright's context. - ExposeFunction(name string, binding ExposedFunction) error - - // This method waits for an element matching “[object Object]”, waits for [actionability] checks, - // focuses the element, fills it and triggers an `input` event after filling. Note that you can pass an empty string - // to clear the input field. - // If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an - // error. However, if the element is inside the `<label>` element that has an associated - // [control], the control will be filled - // instead. - // To send fine-grained keyboard events, use [Locator.PressSequentially]. - // - // Deprecated: Use locator-based [Locator.Fill] instead. Read more about [locators]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. value: Value to fill for the `<input>`, `<textarea>` or `[contenteditable]` element. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - Fill(selector string, value string, options ...PageFillOptions) error - - // This method fetches an element with “[object Object]” and focuses it. If there's no element matching - // “[object Object]”, the method waits until a matching element appears in the DOM. - // - // Deprecated: Use locator-based [Locator.Focus] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [locators]: https://playwright.dev/docs/locators - Focus(selector string, options ...PageFocusOptions) error - - // Returns frame matching the specified criteria. Either `name` or `url` must be specified. - Frame(options ...PageFrameOptions) Frame - - // When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements - // in that iframe. - // - // selector: A selector to use when resolving DOM element. - FrameLocator(selector string) FrameLocator - - // An array of all frames attached to the page. - Frames() []Frame - - // Returns element attribute value. - // - // Deprecated: Use locator-based [Locator.GetAttribute] instead. Read more about [locators]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. name: Attribute name to get the value for. - // - // [locators]: https://playwright.dev/docs/locators - GetAttribute(selector string, name string, options ...PageGetAttributeOptions) (string, error) - - // Allows locating elements by their alt text. - // - // text: Text to locate the element for. - GetByAltText(text interface{}, options ...PageGetByAltTextOptions) Locator - - // Allows locating input elements by the text of the associated `<label>` or `aria-labelledby` element, or by the - // `aria-label` attribute. - // - // text: Text to locate the element for. - GetByLabel(text interface{}, options ...PageGetByLabelOptions) Locator - - // Allows locating input elements by the placeholder text. - // - // text: Text to locate the element for. - GetByPlaceholder(text interface{}, options ...PageGetByPlaceholderOptions) Locator - - // Allows locating elements by their [ARIA role], - // [ARIA attributes] and - // [accessible name]. - // - // # Details - // - // Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback - // about the ARIA guidelines. - // Many html elements have an implicitly [defined role] - // that is recognized by the role selector. You can find all the - // [supported roles here]. ARIA guidelines **do not recommend** - // duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values. - // - // role: Required aria role. - // - // [ARIA role]: https://www.w3.org/TR/wai-aria-1.2/#roles - // [ARIA attributes]: https://www.w3.org/TR/wai-aria-1.2/#aria-attributes - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - // [defined role]: https://w3c.github.io/html-aam/#html-element-role-mappings - // [supported roles here]: https://www.w3.org/TR/wai-aria-1.2/#role_definitions - GetByRole(role AriaRole, options ...PageGetByRoleOptions) Locator - - // Locate element by the test id. - // - // # Details - // - // By default, the `data-testid` attribute is used as a test id. Use [Selectors.SetTestIdAttribute] to configure a - // different test id attribute if necessary. - // - // testId: Id to locate the element by. - GetByTestId(testId interface{}) Locator - - // Allows locating elements that contain given text. - // See also [Locator.Filter] that allows to match by another criteria, like an accessible role, and then filter by the - // text content. - // - // # Details - // - // Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into - // one, turns line breaks into spaces and ignores leading and trailing whitespace. - // Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For - // example, locating by text `"Log in"` matches `<input type=button value="Log in">`. - // - // text: Text to locate the element for. - GetByText(text interface{}, options ...PageGetByTextOptions) Locator - - // Allows locating elements by their title attribute. - // - // text: Text to locate the element for. - GetByTitle(text interface{}, options ...PageGetByTitleOptions) Locator - - // Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of - // the last redirect. If cannot go back, returns `null`. - // Navigate to the previous page in history. - GoBack(options ...PageGoBackOptions) (Response, error) - - // Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of - // the last redirect. If cannot go forward, returns `null`. - // Navigate to the next page in history. - GoForward(options ...PageGoForwardOptions) (Response, error) - - // Request the page to perform garbage collection. Note that there is no guarantee that all unreachable objects will - // be collected. - // This is useful to help detect memory leaks. For example, if your page has a large object `suspect` that might be - // leaked, you can check that it does not leak by using a - // [`WeakRef`]. - // - // [`WeakRef`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef - RequestGC() error - - // Returns the main resource response. In case of multiple redirects, the navigation will resolve with the first - // non-redirect response. - // The method will throw an error if: - // - there's an SSL error (e.g. in case of self-signed certificates). - // - target URL is invalid. - // - the “[object Object]” is exceeded during navigation. - // - the remote server does not respond or is unreachable. - // - the main resource failed to load. - // The method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 - // "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling - // [Response.Status]. - // **NOTE** The method either throws an error or returns a main resource response. The only exceptions are navigation - // to `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`. - // **NOTE** Headless mode doesn't support navigation to a PDF document. See the - // [upstream issue]. - // - // url: URL to navigate page to. The url should include scheme, e.g. `https://`. When a “[object Object]” via the context - // options was provided and the passed URL is a path, it gets merged via the - // [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. - // - // [upstream issue]: https://bugs.chromium.org/p/chromium/issues/detail?id=761295 - Goto(url string, options ...PageGotoOptions) (Response, error) - - // This method hovers over an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Mouse] to hover over the center of the element, or the specified “[object Object]”. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Hover] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Hover(selector string, options ...PageHoverOptions) error - - // Returns `element.innerHTML`. - // - // Deprecated: Use locator-based [Locator.InnerHTML] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [locators]: https://playwright.dev/docs/locators - InnerHTML(selector string, options ...PageInnerHTMLOptions) (string, error) - - // Returns `element.innerText`. - // - // Deprecated: Use locator-based [Locator.InnerText] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [locators]: https://playwright.dev/docs/locators - InnerText(selector string, options ...PageInnerTextOptions) (string, error) - - // Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element. - // Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated - // [control], returns the value of the - // control. - // - // Deprecated: Use locator-based [Locator.InputValue] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - InputValue(selector string, options ...PageInputValueOptions) (string, error) - - // Returns whether the element is checked. Throws if the element is not a checkbox or radio input. - // - // Deprecated: Use locator-based [Locator.IsChecked] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [locators]: https://playwright.dev/docs/locators - IsChecked(selector string, options ...PageIsCheckedOptions) (bool, error) - - // Indicates that the page has been closed. - IsClosed() bool - - // Returns whether the element is disabled, the opposite of [enabled]. - // - // Deprecated: Use locator-based [Locator.IsDisabled] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [enabled]: https://playwright.dev/docs/actionability#enabled - // [locators]: https://playwright.dev/docs/locators - IsDisabled(selector string, options ...PageIsDisabledOptions) (bool, error) - - // Returns whether the element is [editable]. - // - // Deprecated: Use locator-based [Locator.IsEditable] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [editable]: https://playwright.dev/docs/actionability#editable - // [locators]: https://playwright.dev/docs/locators - IsEditable(selector string, options ...PageIsEditableOptions) (bool, error) - - // Returns whether the element is [enabled]. - // - // Deprecated: Use locator-based [Locator.IsEnabled] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [enabled]: https://playwright.dev/docs/actionability#enabled - // [locators]: https://playwright.dev/docs/locators - IsEnabled(selector string, options ...PageIsEnabledOptions) (bool, error) - - // Returns whether the element is hidden, the opposite of [visible]. “[object Object]” - // that does not match any elements is considered hidden. - // - // Deprecated: Use locator-based [Locator.IsHidden] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [visible]: https://playwright.dev/docs/actionability#visible - // [locators]: https://playwright.dev/docs/locators - IsHidden(selector string, options ...PageIsHiddenOptions) (bool, error) - - // Returns whether the element is [visible]. “[object Object]” that does not match any - // elements is considered not visible. - // - // Deprecated: Use locator-based [Locator.IsVisible] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [visible]: https://playwright.dev/docs/actionability#visible - // [locators]: https://playwright.dev/docs/locators - IsVisible(selector string, options ...PageIsVisibleOptions) (bool, error) - - Keyboard() Keyboard - - // The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved - // to the element immediately before performing an action, so a series of actions on the same locator can in fact be - // performed on different DOM elements. That would happen if the DOM structure between those actions has changed. - // [Learn more about locators]. - // - // selector: A selector to use when resolving DOM element. - // - // [Learn more about locators]: https://playwright.dev/docs/locators - Locator(selector string, options ...PageLocatorOptions) Locator - - // The page's main frame. Page is guaranteed to have a main frame which persists during navigations. - MainFrame() Frame - - Mouse() Mouse - - // Returns the opener for popup pages and `null` for others. If the opener has been closed already the returns `null`. - Opener() (Page, error) - - // Pauses script execution. Playwright will stop executing the script and wait for the user to either press 'Resume' - // button in the page overlay or to call `playwright.resume()` in the DevTools console. - // User can inspect selectors or perform manual steps while paused. Resume will continue running the original script - // from the place it was paused. - // **NOTE** This method requires Playwright to be started in a headed mode, with a falsy “[object Object]” option. - Pause() error - - // Returns the PDF buffer. - // `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call - // [Page.EmulateMedia] before calling `page.pdf()`: - // **NOTE** By default, `page.pdf()` generates a pdf with modified colors for printing. Use the - // [`-webkit-print-color-adjust`] - // property to force rendering of exact colors. - // - // [`-webkit-print-color-adjust`]: https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust - PDF(options ...PagePdfOptions) ([]byte, error) - - // Focuses the element, and then uses [Keyboard.Down] and [Keyboard.Up]. - // “[object Object]” can specify the intended - // [keyboardEvent.Key] value or a single character - // to generate the text for. A superset of the “[object Object]” values can be found - // [here]. Examples of the keys are: - // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, - // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, - // etc. - // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, - // `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS. - // Holding down `Shift` will type the text that corresponds to the “[object Object]” in the upper case. - // If “[object Object]” is a single character, it is case-sensitive, so the values `a` and `A` will generate different - // respective texts. - // Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When - // specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. - // - // Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. - // - // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key - // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values - // [locators]: https://playwright.dev/docs/locators - Press(selector string, key string, options ...PagePressOptions) error - - // The method finds an element matching the specified selector within the page. If no elements match the selector, the - // return value resolves to `null`. To wait for an element on the page, use [Locator.WaitFor]. - // - // Deprecated: Use locator-based [Page.Locator] instead. Read more about [locators]. - // - // selector: A selector to query for. - // - // [locators]: https://playwright.dev/docs/locators - QuerySelector(selector string, options ...PageQuerySelectorOptions) (ElementHandle, error) - - // The method finds all elements matching the specified selector within the page. If no elements match the selector, - // the return value resolves to `[]`. - // - // Deprecated: Use locator-based [Page.Locator] instead. Read more about [locators]. - // - // selector: A selector to query for. - // - // [locators]: https://playwright.dev/docs/locators - QuerySelectorAll(selector string) ([]ElementHandle, error) - - // When testing a web page, sometimes unexpected overlays like a "Sign up" dialog appear and block actions you want to - // automate, e.g. clicking a button. These overlays don't always show up in the same way or at the same time, making - // them tricky to handle in automated tests. - // This method lets you set up a special function, called a handler, that activates when it detects that overlay is - // visible. The handler's job is to remove the overlay, allowing your test to continue as if the overlay wasn't there. - // Things to keep in mind: - // - When an overlay is shown predictably, we recommend explicitly waiting for it in your test and dismissing it as - // a part of your normal test flow, instead of using [Page.AddLocatorHandler]. - // - Playwright checks for the overlay every time before executing or retrying an action that requires an - // [actionability check], or before performing an auto-waiting assertion check. When overlay - // is visible, Playwright calls the handler first, and then proceeds with the action/assertion. Note that the - // handler is only called when you perform an action/assertion - if the overlay becomes visible but you don't - // perform any actions, the handler will not be triggered. - // - After executing the handler, Playwright will ensure that overlay that triggered the handler is not visible - // anymore. You can opt-out of this behavior with “[object Object]”. - // - The execution time of the handler counts towards the timeout of the action/assertion that executed the handler. - // If your handler takes too long, it might cause timeouts. - // - You can register multiple handlers. However, only a single handler will be running at a time. Make sure the - // actions within a handler don't depend on another handler. - // **NOTE** Running the handler will alter your page state mid-test. For example it will change the currently focused - // element and move the mouse. Make sure that actions that run after the handler are self-contained and do not rely on - // the focus and mouse state being unchanged. - // For example, consider a test that calls [Locator.Focus] followed by [Keyboard.Press]. If your handler clicks a - // button between these two actions, the focused element most likely will be wrong, and key press will happen on the - // unexpected element. Use [Locator.Press] instead to avoid this problem. - // Another example is a series of mouse actions, where [Mouse.Move] is followed by [Mouse.Down]. Again, when the - // handler runs between these two actions, the mouse position will be wrong during the mouse down. Prefer - // self-contained actions like [Locator.Click] that do not rely on the state being unchanged by a handler. - // - // 1. locator: Locator that triggers the handler. - // 2. handler: Function that should be run once “[object Object]” appears. This function should get rid of the element that blocks - // actions like click. - // - // [actionability check]: https://playwright.dev/docs/actionability - AddLocatorHandler(locator Locator, handler func(Locator), options ...PageAddLocatorHandlerOptions) error - - // Removes all locator handlers added by [Page.AddLocatorHandler] for a specific locator. - // - // locator: Locator passed to [Page.AddLocatorHandler]. - RemoveLocatorHandler(locator Locator) error - - // This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the - // main resource response. In case of multiple redirects, the navigation will resolve with the response of the last - // redirect. - Reload(options ...PageReloadOptions) (Response, error) - - // API testing helper associated with this page. This method returns the same instance as [BrowserContext.Request] on - // the page's context. See [BrowserContext.Request] for more details. - Request() APIRequestContext - - // Routing provides the capability to modify network requests that are made by a page. - // Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or - // aborted. - // **NOTE** The handler will only be called for the first url if the response is a redirect. - // **NOTE** [Page.Route] will not intercept requests intercepted by Service Worker. See - // [this] issue. We recommend disabling Service Workers when - // using request interception by setting “[object Object]” to `block`. - // **NOTE** [Page.Route] will not intercept the first request of a popup page. Use [BrowserContext.Route] instead. - // - // 1. url: A glob pattern, regex pattern, or predicate that receives a [URL] to match during routing. If “[object Object]” is - // set in the context options and the provided URL is a string that does not start with `*`, it is resolved using the - // [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. - // 2. handler: handler function to route the request. - // - // [this]: https://github.com/microsoft/playwright/issues/1090 - Route(url interface{}, handler routeHandler, times ...int) error - - // If specified the network requests that are made in the page will be served from the HAR file. Read more about - // [Replaying from HAR]. - // Playwright will not serve requests intercepted by Service Worker from the HAR file. See - // [this] issue. We recommend disabling Service Workers when - // using request interception by setting “[object Object]” to `block`. - // - // har: Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a - // relative path, then it is resolved relative to the current working directory. - // - // [Replaying from HAR]: https://playwright.dev/docs/mock#replaying-from-har - // [this]: https://github.com/microsoft/playwright/issues/1090 - RouteFromHAR(har string, options ...PageRouteFromHAROptions) error - - // This method allows to modify websocket connections that are made by the page. - // Note that only `WebSocket`s created after this method was called will be routed. It is recommended to call this - // method before navigating the page. - // - // 1. url: Only WebSockets with the url matching this pattern will be routed. A string pattern can be relative to the - // “[object Object]” context option. - // 2. handler: Handler function to route the WebSocket. - RouteWebSocket(url interface{}, handler func(WebSocketRoute)) error - - // Returns the buffer with the captured screenshot. - Screenshot(options ...PageScreenshotOptions) ([]byte, error) - - // This method waits for an element matching “[object Object]”, waits for [actionability] checks, - // waits until all specified options are present in the `<select>` element and selects these options. - // If the target element is not a `<select>` element, this method throws an error. However, if the element is inside - // the `<label>` element that has an associated - // [control], the control will be used - // instead. - // Returns the array of option values that have been successfully selected. - // Triggers a `change` and `input` event once all the provided options have been selected. - // - // Deprecated: Use locator-based [Locator.SelectOption] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - SelectOption(selector string, values SelectOptionValues, options ...PageSelectOptionOptions) ([]string, error) - - // This method checks or unchecks an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. - // 3. If the element already has the right checked state, this method returns immediately. - // 4. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 5. Scroll the element into view if needed. - // 6. Use [Page.Mouse] to click in the center of the element. - // 7. Ensure that the element is now checked or unchecked. If not, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.SetChecked] instead. Read more about [locators]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. checked: Whether to check or uncheck the checkbox. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - SetChecked(selector string, checked bool, options ...PageSetCheckedOptions) error - - // This method internally calls [document.Write()], - // inheriting all its specific characteristics and behaviors. - // - // html: HTML markup to assign to the page. - // - // [document.Write()]: https://developer.mozilla.org/en-US/docs/Web/API/Document/write - SetContent(html string, options ...PageSetContentOptions) error - - // This setting will change the default maximum navigation time for the following methods and related shortcuts: - // - [Page.GoBack] - // - [Page.GoForward] - // - [Page.Goto] - // - [Page.Reload] - // - [Page.SetContent] - // - [Page.ExpectNavigation] - // - [Page.WaitForURL] - // **NOTE** [Page.SetDefaultNavigationTimeout] takes priority over [Page.SetDefaultTimeout], - // [BrowserContext.SetDefaultTimeout] and [BrowserContext.SetDefaultNavigationTimeout]. - // - // timeout: Maximum navigation time in milliseconds - SetDefaultNavigationTimeout(timeout float64) - - // This setting will change the default maximum time for all the methods accepting “[object Object]” option. - // **NOTE** [Page.SetDefaultNavigationTimeout] takes priority over [Page.SetDefaultTimeout]. - // - // timeout: Maximum time in milliseconds. Pass `0` to disable timeout. - SetDefaultTimeout(timeout float64) - - // The extra HTTP headers will be sent with every request the page initiates. - // **NOTE** [Page.SetExtraHTTPHeaders] does not guarantee the order of headers in the outgoing requests. - // - // headers: An object containing additional HTTP headers to be sent with every request. All header values must be strings. - SetExtraHTTPHeaders(headers map[string]string) error - - // Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then - // they are resolved relative to the current working directory. For empty array, clears the selected files. For inputs - // with a `[webkitdirectory]` attribute, only a single directory path is supported. - // This method expects “[object Object]” to point to an - // [input element]. However, if the element is inside - // the `<label>` element that has an associated - // [control], targets the control instead. - // - // Deprecated: Use locator-based [Locator.SetInputFiles] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [input element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input - // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control - // [locators]: https://playwright.dev/docs/locators - SetInputFiles(selector string, files interface{}, options ...PageSetInputFilesOptions) error - - // In the case of multiple pages in a single browser, each page can have its own viewport size. However, - // [Browser.NewContext] allows to set viewport size (and more) for all pages in the context at once. - // [Page.SetViewportSize] will resize the page. A lot of websites don't expect phones to change size, so you should - // set the viewport size before navigating to the page. [Page.SetViewportSize] will also reset `screen` size, use - // [Browser.NewContext] with `screen` and `viewport` parameters if you need better control of these properties. - // - // 1. width: Page width in pixels. - // 2. height: Page height in pixels. - SetViewportSize(width int, height int) error - - // This method taps an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 3. Scroll the element into view if needed. - // 4. Use [Page.Touchscreen] to tap the center of the element, or the specified “[object Object]”. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // **NOTE** [Page.Tap] the method will throw if “[object Object]” option of the browser context is false. - // - // Deprecated: Use locator-based [Locator.Tap] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Tap(selector string, options ...PageTapOptions) error - - // Returns `element.textContent`. - // - // Deprecated: Use locator-based [Locator.TextContent] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [locators]: https://playwright.dev/docs/locators - TextContent(selector string, options ...PageTextContentOptions) (string, error) - - // Returns the page's title. - Title() (string, error) - - Touchscreen() Touchscreen - - // Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `page.type` can be used to - // send fine-grained keyboard events. To fill values in form fields, use [Page.Fill]. - // To press a special key, like `Control` or `ArrowDown`, use [Keyboard.Press]. - // - // Deprecated: In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [Locator.PressSequentially]. - // - // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // 2. text: A text to type into a focused element. - Type(selector string, text string, options ...PageTypeOptions) error - - // This method unchecks an element matching “[object Object]” by performing the following steps: - // 1. Find an element matching “[object Object]”. If there is none, wait until a matching element is attached to - // the DOM. - // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is - // already unchecked, this method returns immediately. - // 3. Wait for [actionability] checks on the matched element, unless “[object Object]” option - // is set. If the element is detached during the checks, the whole action is retried. - // 4. Scroll the element into view if needed. - // 5. Use [Page.Mouse] to click in the center of the element. - // 6. Ensure that the element is now unchecked. If not, this method throws. - // When all steps combined have not finished during the specified “[object Object]”, this method throws a - // [TimeoutError]. Passing zero timeout disables this. - // - // Deprecated: Use locator-based [Locator.Uncheck] instead. Read more about [locators]. - // - // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be - // used. - // - // [actionability]: https://playwright.dev/docs/actionability - // [locators]: https://playwright.dev/docs/locators - Uncheck(selector string, options ...PageUncheckOptions) error - - // Removes all routes created with [Page.Route] and [Page.RouteFromHAR]. - UnrouteAll(options ...PageUnrouteAllOptions) error - - // Removes a route created with [Page.Route]. When “[object Object]” is not specified, removes all routes for the - // “[object Object]”. - // - // 1. url: A glob pattern, regex pattern or predicate receiving [URL] to match while routing. - // 2. handler: Optional handler function to route the request. - Unroute(url interface{}, handler ...routeHandler) error - - URL() string - - // Video object associated with this page. - Video() Video - - ViewportSize() *Size - - // Performs action and waits for a [ConsoleMessage] to be logged by in the page. If predicate is provided, it passes - // [ConsoleMessage] value into the `predicate` function and waits for `predicate(message)` to return a truthy value. - // Will throw an error if the page is closed before the [Page.OnConsole] event is fired. - ExpectConsoleMessage(cb func() error, options ...PageExpectConsoleMessageOptions) (ConsoleMessage, error) - - // Performs action and waits for a new [Download]. If predicate is provided, it passes [Download] value into the - // `predicate` function and waits for `predicate(download)` to return a truthy value. Will throw an error if the page - // is closed before the download event is fired. - ExpectDownload(cb func() error, options ...PageExpectDownloadOptions) (Download, error) - - // Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy - // value. Will throw an error if the page is closed before the event is fired. Returns the event data value. - // - // event: Event name, same one typically passed into `*.on(event)`. - ExpectEvent(event string, cb func() error, options ...PageExpectEventOptions) (interface{}, error) - - // Performs action and waits for a new [FileChooser] to be created. If predicate is provided, it passes [FileChooser] - // value into the `predicate` function and waits for `predicate(fileChooser)` to return a truthy value. Will throw an - // error if the page is closed before the file chooser is opened. - ExpectFileChooser(cb func() error, options ...PageExpectFileChooserOptions) (FileChooser, error) - - // Returns when the “[object Object]” returns a truthy value. It resolves to a JSHandle of the truthy value. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - WaitForFunction(expression string, arg interface{}, options ...PageWaitForFunctionOptions) (JSHandle, error) - - // Returns when the required load state has been reached. - // This resolves when the page reaches a required load state, `load` by default. The navigation must have been - // committed when this method is called. If current document has already reached the required state, resolves - // immediately. - // **NOTE** Most of the time, this method is not needed because Playwright - // [auto-waits before every action]. - // - // [auto-waits before every action]: https://playwright.dev/docs/actionability - WaitForLoadState(options ...PageWaitForLoadStateOptions) error - - // Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the - // navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or - // navigation due to History API usage, the navigation will resolve with `null`. - // - // Deprecated: This method is inherently racy, please use [Page.WaitForURL] instead. - // - // [History API]: https://developer.mozilla.org/en-US/docs/Web/API/History_API - ExpectNavigation(cb func() error, options ...PageExpectNavigationOptions) (Response, error) - - // Performs action and waits for a popup [Page]. If predicate is provided, it passes [Popup] value into the - // `predicate` function and waits for `predicate(page)` to return a truthy value. Will throw an error if the page is - // closed before the popup event is fired. - ExpectPopup(cb func() error, options ...PageExpectPopupOptions) (Page, error) - - // Waits for the matching request and returns it. See [waiting for event] for more - // details about events. - // - // urlOrPredicate: Request URL string, regex or predicate receiving [Request] object. When a “[object Object]” via the context options - // was provided and the passed URL is a path, it gets merged via the - // [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. - // - // [waiting for event]: https://playwright.dev/docs/events#waiting-for-event - ExpectRequest(urlOrPredicate interface{}, cb func() error, options ...PageExpectRequestOptions) (Request, error) - - // Performs action and waits for a [Request] to finish loading. If predicate is provided, it passes [Request] value - // into the `predicate` function and waits for `predicate(request)` to return a truthy value. Will throw an error if - // the page is closed before the [Page.OnRequestFinished] event is fired. - ExpectRequestFinished(cb func() error, options ...PageExpectRequestFinishedOptions) (Request, error) - - // Returns the matched response. See [waiting for event] for more details about - // events. - // - // urlOrPredicate: Request URL string, regex or predicate receiving [Response] object. When a “[object Object]” via the context - // options was provided and the passed URL is a path, it gets merged via the - // [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. - // - // [waiting for event]: https://playwright.dev/docs/events#waiting-for-event - ExpectResponse(urlOrPredicate interface{}, cb func() error, options ...PageExpectResponseOptions) (Response, error) - - // Returns when element specified by selector satisfies “[object Object]” option. Returns `null` if waiting for - // `hidden` or `detached`. - // **NOTE** Playwright automatically waits for element to be ready before performing an action. Using [Locator] - // objects and web-first assertions makes the code wait-for-selector-free. - // Wait for the “[object Object]” to satisfy “[object Object]” option (either appear/disappear from dom, or become - // visible/hidden). If at the moment of calling the method “[object Object]” already satisfies the condition, the - // method will return immediately. If the selector doesn't satisfy the condition for the “[object Object]” - // milliseconds, the function will throw. - // - // Deprecated: Use web assertions that assert visibility or a locator-based [Locator.WaitFor] instead. Read more about [locators]. - // - // selector: A selector to query for. - // - // [locators]: https://playwright.dev/docs/locators - WaitForSelector(selector string, options ...PageWaitForSelectorOptions) (ElementHandle, error) - - // Waits for the given “[object Object]” in milliseconds. - // Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going - // to be flaky. Use signals such as network events, selectors becoming visible and others instead. - // - // Deprecated: Never wait for timeout in production. Tests that wait for time are inherently flaky. Use [Locator] actions and web assertions that wait automatically. - // - // timeout: A timeout to wait for - WaitForTimeout(timeout float64) - - // Waits for the main frame to navigate to the given URL. - // - // url: A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if - // the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly - // equal to the string. - WaitForURL(url interface{}, options ...PageWaitForURLOptions) error - - // Performs action and waits for a new [WebSocket]. If predicate is provided, it passes [WebSocket] value into the - // `predicate` function and waits for `predicate(webSocket)` to return a truthy value. Will throw an error if the page - // is closed before the WebSocket event is fired. - ExpectWebSocket(cb func() error, options ...PageExpectWebSocketOptions) (WebSocket, error) - - // Performs action and waits for a new [Worker]. If predicate is provided, it passes [Worker] value into the - // `predicate` function and waits for `predicate(worker)` to return a truthy value. Will throw an error if the page is - // closed before the worker event is fired. - ExpectWorker(cb func() error, options ...PageExpectWorkerOptions) (Worker, error) - - // This method returns all of the dedicated - // [WebWorkers] associated with the page. - // **NOTE** This does not contain ServiceWorkers - // - // [WebWorkers]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API - Workers() []Worker - - // **NOTE** In most cases, you should use [Page.ExpectEvent]. - // Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function - // and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is closed before the - // `event` is fired. - // - // event: Event name, same one typically passed into `*.on(event)`. - WaitForEvent(event string, options ...PageWaitForEventOptions) (interface{}, error) -} - -// The [PageAssertions] class provides assertion methods that can be used to make assertions about the [Page] state in -// the tests. -type PageAssertions interface { - // Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't - // contain `"error"`: - Not() PageAssertions - - // Ensures the page has the given title. - // - // titleOrRegExp: Expected title or RegExp. - ToHaveTitle(titleOrRegExp interface{}, options ...PageAssertionsToHaveTitleOptions) error - - // Ensures the page is navigated to the given URL. - // - // urlOrRegExp: Expected URL string or RegExp. - ToHaveURL(urlOrRegExp interface{}, options ...PageAssertionsToHaveURLOptions) error -} - -// Playwright gives you Web-First Assertions with convenience methods for creating assertions that will wait and retry -// until the expected condition is met. -// Consider the following example: -// Playwright will be re-testing the node with the selector `.status` until fetched Node has the `"Submitted"` text. -// It will be re-fetching the node and checking it over and over, until the condition is met or until the timeout is -// reached. You can pass this timeout as an option. -// By default, the timeout for assertions is set to 5 seconds. -type PlaywrightAssertions interface { - // Creates a [APIResponseAssertions] object for the given [APIResponse]. - // - // response: [APIResponse] object to use for assertions. - APIResponse(response APIResponse) APIResponseAssertions - - // Creates a [LocatorAssertions] object for the given [Locator]. - // - // locator: [Locator] object to use for assertions. - Locator(locator Locator) LocatorAssertions - - // Creates a [PageAssertions] object for the given [Page]. - // - // page: [Page] object to use for assertions. - Page(page Page) PageAssertions -} - -// Whenever the page sends a request for a network resource the following sequence of events are emitted by [Page]: -// - [Page.OnRequest] emitted when the request is issued by the page. -// - [Page.OnResponse] emitted when/if the response status and headers are received for the request. -// - [Page.OnRequestFinished] emitted when the response body is downloaded and the request is complete. -// -// If request fails at some point, then instead of `requestfinished` event (and possibly instead of 'response' -// event), the [Page.OnRequestFailed] event is emitted. -// **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request -// will complete with `requestfinished` event. -// If request gets a 'redirect' response, the request is successfully finished with the `requestfinished` event, and a -// new request is issued to a redirected url. -type Request interface { - // An object with all the request HTTP headers associated with this request. The header names are lower-cased. - AllHeaders() (map[string]string, error) - - // The method returns `null` unless this request has failed, as reported by `requestfailed` event. - Failure() error - - // Returns the [Frame] that initiated this request. - // - // # Details - // - // Note that in some cases the frame is not available, and this method will throw. - // - When request originates in the Service Worker. You can use `request.serviceWorker()` to check that. - // - When navigation request is issued before the corresponding frame is created. You can use - // [Request.IsNavigationRequest] to check that. - // Here is an example that handles all the cases: - Frame() Frame - - // An object with the request HTTP headers. The header names are lower-cased. Note that this method does not return - // security-related headers, including cookie-related ones. You can use [Request.AllHeaders] for complete list of - // headers that include `cookie` information. - Headers() map[string]string - - // An array with all the request HTTP headers associated with this request. Unlike [Request.AllHeaders], header names - // are NOT lower-cased. Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times. - HeadersArray() ([]NameValue, error) - - // Returns the value of the header matching the name. The name is case-insensitive. - // - // name: Name of the header. - HeaderValue(name string) (string, error) - - // Whether this request is driving frame's navigation. - // Some navigation requests are issued before the corresponding frame is created, and therefore do not have - // [Request.Frame] available. - IsNavigationRequest() bool - - // Request's method (GET, POST, etc.) - Method() string - - // Request's post body, if any. - PostData() (string, error) - - // Request's post body in a binary form, if any. - PostDataBuffer() ([]byte, error) - - // Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any. - // When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned. - // Otherwise it will be parsed as JSON. - PostDataJSON(v interface{}) error - - // Request that was redirected by the server to this one, if any. - // When the server responds with a redirect, Playwright creates a new [Request] object. The two requests are connected - // by `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to - // construct the whole redirect chain by repeatedly calling `redirectedFrom()`. - RedirectedFrom() Request - - // New request issued by the browser if the server responded with redirect. - RedirectedTo() Request - - // Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the - // following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, - // `eventsource`, `websocket`, `manifest`, `other`. - ResourceType() string - - // Returns the matching [Response] object, or `null` if the response was not received due to error. - Response() (Response, error) - - // Returns resource size information for given request. - Sizes() (*RequestSizesResult, error) - - // Returns resource timing information for given request. Most of the timing values become available upon the - // response, `responseEnd` becomes available when request finishes. Find more information at - // [Resource Timing API]. - // - // [Resource Timing API]: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming - Timing() *RequestTiming - - // URL of the request. - URL() string -} - -// [Response] class represents responses which are received by page. -type Response interface { - // An object with all the response HTTP headers associated with this response. - AllHeaders() (map[string]string, error) - - // Returns the buffer with response body. - Body() ([]byte, error) - - // Waits for this response to finish, returns always `null`. - Finished() error - - // Returns the [Frame] that initiated this response. - Frame() Frame - - // Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via - // [FetchEvent.RespondWith]. - // - // [FetchEvent.RespondWith]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/respondWith) - FromServiceWorker() bool - - // An object with the response HTTP headers. The header names are lower-cased. Note that this method does not return - // security-related headers, including cookie-related ones. You can use [Response.AllHeaders] for complete list of - // headers that include `cookie` information. - Headers() map[string]string - - // An array with all the request HTTP headers associated with this response. Unlike [Response.AllHeaders], header - // names are NOT lower-cased. Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times. - HeadersArray() ([]NameValue, error) - - // Returns the value of the header matching the name. The name is case-insensitive. If multiple headers have the same - // name (except `set-cookie`), they are returned as a list separated by `, `. For `set-cookie`, the `\n` separator is - // used. If no headers are found, `null` is returned. - // - // name: Name of the header. - HeaderValue(name string) (string, error) - - // Returns all values of the headers matching the name, for example `set-cookie`. The name is case-insensitive. - // - // name: Name of the header. - HeaderValues(name string) ([]string, error) - - // Returns the JSON representation of response body. - // This method will throw if the response body is not parsable via `JSON.parse`. - JSON(v interface{}) error - - // Contains a boolean stating whether the response was successful (status in the range 200-299) or not. - Ok() bool - - // Returns the matching [Request] object. - Request() Request - - // Returns SSL and other security information. - SecurityDetails() (*ResponseSecurityDetailsResult, error) - - // Returns the IP address and port of the server. - ServerAddr() (*ResponseServerAddrResult, error) - - // Contains the status code of the response (e.g., 200 for a success). - Status() int - - // Contains the status text of the response (e.g. usually an "OK" for a success). - StatusText() string - - // Returns the text representation of response body. - Text() (string, error) - - // Contains the URL of the response. - URL() string -} - -// Whenever a network route is set up with [Page.Route] or [BrowserContext.Route], the `Route` object allows to handle -// the route. -// Learn more about [networking]. -// -// [networking]: https://playwright.dev/docs/network -type Route interface { - // Aborts the route's request. - Abort(errorCode ...string) error - - // Sends route's request to the network with optional overrides. - // - // # Details - // - // The “[object Object]” option applies to both the routed request and any redirects it initiates. However, - // “[object Object]”, “[object Object]”, and “[object Object]” only apply to the original request and are not carried - // over to redirected requests. - // [Route.Continue] will immediately send the request to the network, other matching handlers won't be invoked. Use - // [Route.Fallback] If you want next matching handler in the chain to be invoked. - // **NOTE** The `Cookie` header cannot be overridden using this method. If a value is provided, it will be ignored, - // and the cookie will be loaded from the browser's cookie store. To set custom cookies, use - // [BrowserContext.AddCookies]. - Continue(options ...RouteContinueOptions) error - - // Continues route's request with optional overrides. The method is similar to [Route.Continue] with the difference - // that other matching handlers will be invoked before sending the request. - Fallback(options ...RouteFallbackOptions) error - - // Performs the request and fetches result without fulfilling it, so that the response could be modified and then - // fulfilled. - // - // # Details - // - // Note that “[object Object]” option will apply to the fetched request as well as any redirects initiated by it. If - // you want to only apply “[object Object]” to the original request, but not to redirects, look into [Route.Continue] - // instead. - Fetch(options ...RouteFetchOptions) (APIResponse, error) - - // Fulfills route's request with given response. - Fulfill(options ...RouteFulfillOptions) error - - // A request to be routed. - Request() Request -} - -// Selectors can be used to install custom selector engines. See [extensibility] for more -// information. -// -// [extensibility]: https://playwright.dev/docs/extensibility -type Selectors interface { - // Selectors must be registered before creating the page. - // - // 1. name: Name that is used in selectors as a prefix, e.g. `{name: 'foo'}` enables `foo=myselectorbody` selectors. May only - // contain `[a-zA-Z0-9_]` characters. - // 2. script: Script that evaluates to a selector engine instance. The script is evaluated in the page context. - Register(name string, script Script, options ...SelectorsRegisterOptions) error - - // Defines custom attribute name to be used in [Page.GetByTestId]. `data-testid` is used by default. - // - // attributeName: Test id attribute name. - SetTestIdAttribute(attributeName string) -} - -// The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on -// the touchscreen can only be used in browser contexts that have been initialized with `hasTouch` set to true. -// This class is limited to emulating tap gestures. For examples of other gestures simulated by manually dispatching -// touch events, see the [emulating legacy touch events] page. -// -// [emulating legacy touch events]: https://playwright.dev/docs/touch-events -type Touchscreen interface { - // Dispatches a `touchstart` and `touchend` event with a single touch at the position - // (“[object Object]”,“[object Object]”). - // **NOTE** [Page.Tap] the method will throw if “[object Object]” option of the browser context is false. - // - // 1. x: X coordinate relative to the main frame's viewport in CSS pixels. - // 2. y: Y coordinate relative to the main frame's viewport in CSS pixels. - Tap(x int, y int) error -} - -// API for collecting and saving Playwright traces. Playwright traces can be opened in -// [Trace Viewer] after Playwright script runs. -// Start recording a trace before performing actions. At the end, stop tracing and save it to a file. -// -// [Trace Viewer]: https://playwright.dev/docs/trace-viewer -type Tracing interface { - // Start tracing. - Start(options ...TracingStartOptions) error - - // Start a new trace chunk. If you'd like to record multiple traces on the same [BrowserContext], use [Tracing.Start] - // once, and then create multiple trace chunks with [Tracing.StartChunk] and [Tracing.StopChunk]. - StartChunk(options ...TracingStartChunkOptions) error - - // **NOTE** Use `test.step` instead when available. - // Creates a new group within the trace, assigning any subsequent API calls to this group, until [Tracing.GroupEnd] is - // called. Groups can be nested and will be visible in the trace viewer. - // - // name: Group name shown in the trace viewer. - Group(name string, options ...TracingGroupOptions) error - - // Closes the last group created by [Tracing.Group]. - GroupEnd() error - - // Stop tracing. - Stop(path ...string) error - - // Stop the trace chunk. See [Tracing.StartChunk] for more details about multiple trace chunks. - StopChunk(path ...string) error -} - -// When browser context is created with the `recordVideo` option, each page has a video object associated with it. -type Video interface { - // Deletes the video file. Will wait for the video to finish if necessary. - Delete() error - - // Returns the file system path this video will be recorded to. The video is guaranteed to be written to the - // filesystem upon closing the browser context. This method throws when connected remotely. - Path() (string, error) - - // Saves the video to a user-specified path. It is safe to call this method while the video is still in progress, or - // after the page has closed. This method waits until the page is closed and the video is fully saved. - // - // path: Path where the video should be saved. - SaveAs(path string) error -} - -// [WebError] class represents an unhandled exception thrown in the page. It is dispatched via the -// [BrowserContext.OnWebError] event. -type WebError interface { - // The page that produced this unhandled exception, if any. - Page() Page - - // Unhandled error that was thrown. - Error() error -} - -// The [WebSocket] class represents WebSocket connections within a page. It provides the ability to inspect and -// manipulate the data being transmitted and received. -// If you want to intercept or modify WebSocket frames, consider using [WebSocketRoute]. -type WebSocket interface { - // Fired when the websocket closes. - OnClose(fn func(WebSocket)) - - // Fired when the websocket receives a frame. - OnFrameReceived(fn func([]byte)) - - // Fired when the websocket sends a frame. - OnFrameSent(fn func([]byte)) - - // Fired when the websocket has an error. - OnSocketError(fn func(string)) - - // Indicates that the web socket has been closed. - IsClosed() bool - - // Contains the URL of the WebSocket. - URL() string - - // Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy - // value. Will throw an error if the webSocket is closed before the event is fired. Returns the event data value. - // - // event: Event name, same one would pass into `webSocket.on(event)`. - ExpectEvent(event string, cb func() error, options ...WebSocketExpectEventOptions) (interface{}, error) - - // **NOTE** In most cases, you should use [WebSocket.ExpectEvent]. - // Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function - // and waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is closed before the - // `event` is fired. - // - // event: Event name, same one typically passed into `*.on(event)`. - WaitForEvent(event string, options ...WebSocketWaitForEventOptions) (interface{}, error) -} - -// Whenever a [`WebSocket`] route is set up with -// [Page.RouteWebSocket] or [BrowserContext.RouteWebSocket], the `WebSocketRoute` object allows to handle the -// WebSocket, like an actual server would do. -// **Mocking** -// By default, the routed WebSocket will not connect to the server. This way, you can mock entire communcation over -// the WebSocket. Here is an example that responds to a `"request"` with a `"response"`. -// Since we do not call [WebSocketRoute.ConnectToServer] inside the WebSocket route handler, Playwright assumes that -// WebSocket will be mocked, and opens the WebSocket inside the page automatically. -// Here is another example that handles JSON messages: -// **Intercepting** -// Alternatively, you may want to connect to the actual server, but intercept messages in-between and modify or block -// them. Calling [WebSocketRoute.ConnectToServer] returns a server-side `WebSocketRoute` instance that you can send -// messages to, or handle incoming messages. -// Below is an example that modifies some messages sent by the page to the server. Messages sent from the server to -// the page are left intact, relying on the default forwarding. -// After connecting to the server, all **messages are forwarded** between the page and the server by default. -// However, if you call [WebSocketRoute.OnMessage] on the original route, messages from the page to the server **will -// not be forwarded** anymore, but should instead be handled by the “[object Object]”. -// Similarly, calling [WebSocketRoute.OnMessage] on the server-side WebSocket will **stop forwarding messages** from -// the server to the page, and “[object Object]” should take care of them. -// The following example blocks some messages in both directions. Since it calls [WebSocketRoute.OnMessage] in both -// directions, there is no automatic forwarding at all. -// -// [`WebSocket`]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket -type WebSocketRoute interface { - // Closes one side of the WebSocket connection. - Close(options ...WebSocketRouteCloseOptions) - - // By default, routed WebSocket does not connect to the server, so you can mock entire WebSocket communication. This - // method connects to the actual WebSocket server, and returns the server-side [WebSocketRoute] instance, giving the - // ability to send and receive messages from the server. - // Once connected to the server: - // - Messages received from the server will be **automatically forwarded** to the WebSocket in the page, unless - // [WebSocketRoute.OnMessage] is called on the server-side `WebSocketRoute`. - // - Messages sent by the [`WebSocket.send()`] call - // in the page will be **automatically forwarded** to the server, unless [WebSocketRoute.OnMessage] is called on - // the original `WebSocketRoute`. - // See examples at the top for more details. - // - // [`WebSocket.send()`]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send - ConnectToServer() (WebSocketRoute, error) - - // Allows to handle [`WebSocket.close`]. - // By default, closing one side of the connection, either in the page or on the server, will close the other side. - // However, when [WebSocketRoute.OnClose] handler is set up, the default forwarding of closure is disabled, and - // handler should take care of it. - // - // handler: Function that will handle WebSocket closure. Received an optional - // [close code](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close#code) and an optional - // [close reason](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close#reason). - // - // [`WebSocket.close`]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close - OnClose(handler func(*int, *string)) - - // This method allows to handle messages that are sent by the WebSocket, either from the page or from the server. - // When called on the original WebSocket route, this method handles messages sent from the page. You can handle this - // messages by responding to them with [WebSocketRoute.Send], forwarding them to the server-side connection returned - // by [WebSocketRoute.ConnectToServer] or do something else. - // Once this method is called, messages are not automatically forwarded to the server or to the page - you should do - // that manually by calling [WebSocketRoute.Send]. See examples at the top for more details. - // Calling this method again will override the handler with a new one. - // - // handler: Function that will handle messages. - OnMessage(handler func(interface{})) - - // Sends a message to the WebSocket. When called on the original WebSocket, sends the message to the page. When called - // on the result of [WebSocketRoute.ConnectToServer], sends the message to the server. See examples at the top for - // more details. - // - // message: Message to send. - Send(message interface{}) - - // URL of the WebSocket created in the page. - URL() string -} - -// The Worker class represents a [WebWorker]. -// `worker` event is emitted on the page object to signal a worker creation. `close` event is emitted on the worker -// object when the worker is gone. -// -// [WebWorker]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API -type Worker interface { - // Emitted when this dedicated [WebWorker] is - // terminated. - // - // [WebWorker]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API - OnClose(fn func(Worker)) - - // Returns the return value of “[object Object]”. - // If the function passed to the [Worker.Evaluate] returns a [Promise], then [Worker.Evaluate] would wait for the - // promise to resolve and return its value. - // If the function passed to the [Worker.Evaluate] returns a non-[Serializable] value, then [Worker.Evaluate] returns - // `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`: - // `-0`, `NaN`, `Infinity`, `-Infinity`. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - Evaluate(expression string, arg ...interface{}) (interface{}, error) - - // Returns the return value of “[object Object]” as a [JSHandle]. - // The only difference between [Worker.Evaluate] and [Worker.EvaluateHandle] is that [Worker.EvaluateHandle] returns - // [JSHandle]. - // If the function passed to the [Worker.EvaluateHandle] returns a [Promise], then [Worker.EvaluateHandle] would wait - // for the promise to resolve and return its value. - // - // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the - // function is automatically invoked. - // 2. arg: Optional argument to pass to “[object Object]”. - EvaluateHandle(expression string, arg ...interface{}) (JSHandle, error) - - URL() string -} diff --git a/vendor/github.com/playwright-community/playwright-go/generated-structs.go b/vendor/github.com/playwright-community/playwright-go/generated-structs.go deleted file mode 100644 index 7a90f5a..0000000 --- a/vendor/github.com/playwright-community/playwright-go/generated-structs.go +++ /dev/null @@ -1,4364 +0,0 @@ -package playwright - -type APIRequestNewContextOptions struct { - // Methods like [APIRequestContext.Get] take the base URL into consideration by using the - // [`URL()`] constructor for building the corresponding URL. - // Examples: - // - baseURL: `http://localhost:3000` and sending request to `/bar.html` results in `http://localhost:3000/bar.html` - // - baseURL: `http://localhost:3000/foo/` and sending request to `./bar.html` results in - // `http://localhost:3000/foo/bar.html` - // - baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in - // `http://localhost:3000/bar.html` - // - // [`URL()`]: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL - BaseURL *string `json:"baseURL"` - // TLS Client Authentication allows the server to request a client certificate and verify it. - // - // # Details - // - // An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`, - // a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally, - // `passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided - // with an exact match to the request origin that the certificate is valid for. - // **NOTE** When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it - // work by replacing `localhost` with `local.playwright`. - ClientCertificates []ClientCertificate `json:"clientCertificates"` - // An object containing additional HTTP headers to be sent with every request. Defaults to none. - ExtraHttpHeaders map[string]string `json:"extraHTTPHeaders"` - // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status - // codes. - FailOnStatusCode *bool `json:"failOnStatusCode"` - // Credentials for [HTTP authentication]. If no - // origin is specified, the username and password are sent to any servers upon unauthorized responses. - // - // [HTTP authentication]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication - HttpCredentials *HttpCredentials `json:"httpCredentials"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is - // exceeded. Defaults to `20`. Pass `0` to not follow redirects. This can be overwritten for each request - // individually. - MaxRedirects *int `json:"maxRedirects"` - // Network proxy settings. - Proxy *Proxy `json:"proxy"` - // Populates context with given storage state. This option can be used to initialize context with logged-in - // information obtained via [BrowserContext.StorageState] or [APIRequestContext.StorageState]. Either a path to the - // file with saved storage, or the value returned by one of [BrowserContext.StorageState] or - // [APIRequestContext.StorageState] methods. - StorageState *StorageState `json:"storageState"` - // Populates context with given storage state. This option can be used to initialize context with logged-in - // information obtained via [BrowserContext.StorageState]. Path to the file with saved storage state. - StorageStatePath *string `json:"storageStatePath"` - // Maximum time in milliseconds to wait for the response. Defaults to `30000` (30 seconds). Pass `0` to disable - // timeout. - Timeout *float64 `json:"timeout"` - // Specific user agent to use in this context. - UserAgent *string `json:"userAgent"` -} - -type APIRequestContextDeleteOptions struct { - // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string - // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` - // header will be set to `application/octet-stream` if not explicitly set. - Data interface{} `json:"data"` - // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status - // codes. - FailOnStatusCode *bool `json:"failOnStatusCode"` - // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent - // as this request body. If this parameter is specified `content-type` header will be set to - // `application/x-www-form-urlencoded` unless explicitly provided. - Form interface{} `json:"form"` - // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by - // it. - Headers map[string]string `json:"headers"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is - // exceeded. Defaults to `20`. Pass `0` to not follow redirects. - MaxRedirects *int `json:"maxRedirects"` - // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not - // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. - MaxRetries *int `json:"maxRetries"` - // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this - // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless - // explicitly provided. File values can be passed either as - // [`fs.ReadStream`] or as file-like object containing file - // name, mime-type and its content. - // - // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream - Multipart interface{} `json:"multipart"` - // Query parameters to be sent with the URL. - Params map[string]interface{} `json:"params"` - // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - Timeout *float64 `json:"timeout"` -} - -type APIRequestContextDisposeOptions struct { - // The reason to be reported to the operations interrupted by the context disposal. - Reason *string `json:"reason"` -} - -type APIRequestContextFetchOptions struct { - // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string - // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` - // header will be set to `application/octet-stream` if not explicitly set. - Data interface{} `json:"data"` - // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status - // codes. - FailOnStatusCode *bool `json:"failOnStatusCode"` - // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent - // as this request body. If this parameter is specified `content-type` header will be set to - // `application/x-www-form-urlencoded` unless explicitly provided. - Form interface{} `json:"form"` - // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by - // it. - Headers map[string]string `json:"headers"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is - // exceeded. Defaults to `20`. Pass `0` to not follow redirects. - MaxRedirects *int `json:"maxRedirects"` - // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not - // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. - MaxRetries *int `json:"maxRetries"` - // If set changes the fetch method (e.g. [PUT] or - // [POST]. If not specified, GET method is used. - // - // [PUT]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT - // [POST]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) - Method *string `json:"method"` - // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this - // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless - // explicitly provided. File values can be passed either as - // [`fs.ReadStream`] or as file-like object containing file - // name, mime-type and its content. - // - // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream - Multipart interface{} `json:"multipart"` - // Query parameters to be sent with the URL. - Params map[string]interface{} `json:"params"` - // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - Timeout *float64 `json:"timeout"` -} - -type APIRequestContextGetOptions struct { - // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string - // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` - // header will be set to `application/octet-stream` if not explicitly set. - Data interface{} `json:"data"` - // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status - // codes. - FailOnStatusCode *bool `json:"failOnStatusCode"` - // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent - // as this request body. If this parameter is specified `content-type` header will be set to - // `application/x-www-form-urlencoded` unless explicitly provided. - Form interface{} `json:"form"` - // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by - // it. - Headers map[string]string `json:"headers"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is - // exceeded. Defaults to `20`. Pass `0` to not follow redirects. - MaxRedirects *int `json:"maxRedirects"` - // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not - // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. - MaxRetries *int `json:"maxRetries"` - // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this - // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless - // explicitly provided. File values can be passed either as - // [`fs.ReadStream`] or as file-like object containing file - // name, mime-type and its content. - // - // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream - Multipart interface{} `json:"multipart"` - // Query parameters to be sent with the URL. - Params map[string]interface{} `json:"params"` - // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - Timeout *float64 `json:"timeout"` -} - -type APIRequestContextHeadOptions struct { - // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string - // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` - // header will be set to `application/octet-stream` if not explicitly set. - Data interface{} `json:"data"` - // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status - // codes. - FailOnStatusCode *bool `json:"failOnStatusCode"` - // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent - // as this request body. If this parameter is specified `content-type` header will be set to - // `application/x-www-form-urlencoded` unless explicitly provided. - Form interface{} `json:"form"` - // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by - // it. - Headers map[string]string `json:"headers"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is - // exceeded. Defaults to `20`. Pass `0` to not follow redirects. - MaxRedirects *int `json:"maxRedirects"` - // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not - // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. - MaxRetries *int `json:"maxRetries"` - // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this - // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless - // explicitly provided. File values can be passed either as - // [`fs.ReadStream`] or as file-like object containing file - // name, mime-type and its content. - // - // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream - Multipart interface{} `json:"multipart"` - // Query parameters to be sent with the URL. - Params map[string]interface{} `json:"params"` - // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - Timeout *float64 `json:"timeout"` -} - -type APIRequestContextPatchOptions struct { - // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string - // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` - // header will be set to `application/octet-stream` if not explicitly set. - Data interface{} `json:"data"` - // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status - // codes. - FailOnStatusCode *bool `json:"failOnStatusCode"` - // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent - // as this request body. If this parameter is specified `content-type` header will be set to - // `application/x-www-form-urlencoded` unless explicitly provided. - Form interface{} `json:"form"` - // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by - // it. - Headers map[string]string `json:"headers"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is - // exceeded. Defaults to `20`. Pass `0` to not follow redirects. - MaxRedirects *int `json:"maxRedirects"` - // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not - // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. - MaxRetries *int `json:"maxRetries"` - // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this - // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless - // explicitly provided. File values can be passed either as - // [`fs.ReadStream`] or as file-like object containing file - // name, mime-type and its content. - // - // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream - Multipart interface{} `json:"multipart"` - // Query parameters to be sent with the URL. - Params map[string]interface{} `json:"params"` - // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - Timeout *float64 `json:"timeout"` -} - -type APIRequestContextPostOptions struct { - // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string - // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` - // header will be set to `application/octet-stream` if not explicitly set. - Data interface{} `json:"data"` - // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status - // codes. - FailOnStatusCode *bool `json:"failOnStatusCode"` - // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent - // as this request body. If this parameter is specified `content-type` header will be set to - // `application/x-www-form-urlencoded` unless explicitly provided. - Form interface{} `json:"form"` - // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by - // it. - Headers map[string]string `json:"headers"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is - // exceeded. Defaults to `20`. Pass `0` to not follow redirects. - MaxRedirects *int `json:"maxRedirects"` - // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not - // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. - MaxRetries *int `json:"maxRetries"` - // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this - // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless - // explicitly provided. File values can be passed either as - // [`fs.ReadStream`] or as file-like object containing file - // name, mime-type and its content. - // - // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream - Multipart interface{} `json:"multipart"` - // Query parameters to be sent with the URL. - Params map[string]interface{} `json:"params"` - // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - Timeout *float64 `json:"timeout"` -} - -type APIRequestContextPutOptions struct { - // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string - // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` - // header will be set to `application/octet-stream` if not explicitly set. - Data interface{} `json:"data"` - // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status - // codes. - FailOnStatusCode *bool `json:"failOnStatusCode"` - // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent - // as this request body. If this parameter is specified `content-type` header will be set to - // `application/x-www-form-urlencoded` unless explicitly provided. - Form interface{} `json:"form"` - // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by - // it. - Headers map[string]string `json:"headers"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is - // exceeded. Defaults to `20`. Pass `0` to not follow redirects. - MaxRedirects *int `json:"maxRedirects"` - // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not - // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. - MaxRetries *int `json:"maxRetries"` - // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this - // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless - // explicitly provided. File values can be passed either as - // [`fs.ReadStream`] or as file-like object containing file - // name, mime-type and its content. - // - // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream - Multipart interface{} `json:"multipart"` - // Query parameters to be sent with the URL. - Params map[string]interface{} `json:"params"` - // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - Timeout *float64 `json:"timeout"` -} - -type StorageState struct { - Cookies []Cookie `json:"cookies"` - Origins []Origin `json:"origins"` -} - -type NameValue struct { - // Name of the header. - Name string `json:"name"` - // Value of the header. - Value string `json:"value"` -} - -type BrowserCloseOptions struct { - // The reason to be reported to the operations interrupted by the browser closure. - Reason *string `json:"reason"` -} - -type BrowserNewContextOptions struct { - // Whether to automatically download all the attachments. Defaults to `true` where all the downloads are accepted. - AcceptDownloads *bool `json:"acceptDownloads"` - // When using [Page.Goto], [Page.Route], [Page.WaitForURL], [Page.ExpectRequest], or [Page.ExpectResponse] it takes - // the base URL in consideration by using the [`URL()`] - // constructor for building the corresponding URL. Unset by default. Examples: - // - baseURL: `http://localhost:3000` and navigating to `/bar.html` results in `http://localhost:3000/bar.html` - // - baseURL: `http://localhost:3000/foo/` and navigating to `./bar.html` results in - // `http://localhost:3000/foo/bar.html` - // - baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in - // `http://localhost:3000/bar.html` - // - // [`URL()`]: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL - BaseURL *string `json:"baseURL"` - // Toggles bypassing page's Content-Security-Policy. Defaults to `false`. - BypassCSP *bool `json:"bypassCSP"` - // TLS Client Authentication allows the server to request a client certificate and verify it. - // - // # Details - // - // An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`, - // a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally, - // `passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided - // with an exact match to the request origin that the certificate is valid for. - // **NOTE** When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it - // work by replacing `localhost` with `local.playwright`. - ClientCertificates []ClientCertificate `json:"clientCertificates"` - // Emulates [prefers-colors-scheme] - // media feature, supported values are `light` and `dark`. See [Page.EmulateMedia] for more details. Passing - // `no-override` resets emulation to system defaults. Defaults to `light`. - // - // [prefers-colors-scheme]: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme - ColorScheme *ColorScheme `json:"colorScheme"` - // Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about - // [emulating devices with device scale factor]. - // - // [emulating devices with device scale factor]: https://playwright.dev/docs/emulation#devices - DeviceScaleFactor *float64 `json:"deviceScaleFactor"` - // An object containing additional HTTP headers to be sent with every request. Defaults to none. - ExtraHttpHeaders map[string]string `json:"extraHTTPHeaders"` - // Emulates `forced-colors` media feature, supported values are `active`, `none`. See [Page.EmulateMedia] for - // more details. Passing `no-override` resets emulation to system defaults. Defaults to `none`. - ForcedColors *ForcedColors `json:"forcedColors"` - Geolocation *Geolocation `json:"geolocation"` - // Specifies if viewport supports touch events. Defaults to false. Learn more about - // [mobile emulation]. - // - // [mobile emulation]: https://playwright.dev/docs/emulation#devices - HasTouch *bool `json:"hasTouch"` - // Credentials for [HTTP authentication]. If no - // origin is specified, the username and password are sent to any servers upon unauthorized responses. - // - // [HTTP authentication]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication - HttpCredentials *HttpCredentials `json:"httpCredentials"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device, - // so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more - // about [mobile emulation]. - // - // [mobile emulation]: https://playwright.dev/docs/emulation#ismobile - IsMobile *bool `json:"isMobile"` - // Whether or not to enable JavaScript in the context. Defaults to `true`. Learn more about - // [disabling JavaScript]. - // - // [disabling JavaScript]: https://playwright.dev/docs/emulation#javascript-enabled - JavaScriptEnabled *bool `json:"javaScriptEnabled"` - // Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, - // `Accept-Language` request header value as well as number and date formatting rules. Defaults to the system default - // locale. Learn more about emulation in our [emulation guide]. - // - // [emulation guide]: https://playwright.dev/docs/emulation#locale--timezone - Locale *string `json:"locale"` - // Does not enforce fixed viewport, allows resizing window in the headed mode. - NoViewport *bool `json:"noViewport"` - // Whether to emulate network being offline. Defaults to `false`. Learn more about - // [network emulation]. - // - // [network emulation]: https://playwright.dev/docs/emulation#offline - Offline *bool `json:"offline"` - // A list of permissions to grant to all pages in this context. See [BrowserContext.GrantPermissions] for more - // details. Defaults to none. - Permissions []string `json:"permissions"` - // Network proxy settings to use with this context. Defaults to none. - Proxy *Proxy `json:"proxy"` - // Optional setting to control resource content management. If `omit` is specified, content is not persisted. If - // `attach` is specified, resources are persisted as separate files and all of these files are archived along with the - // HAR file. Defaults to `embed`, which stores content inline the HAR file as per HAR specification. - RecordHarContent *HarContentPolicy `json:"recordHarContent"` - // When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, - // cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`. - RecordHarMode *HarMode `json:"recordHarMode"` - // Optional setting to control whether to omit request content from the HAR. Defaults to `false`. - RecordHarOmitContent *bool `json:"recordHarOmitContent"` - // Enables [HAR] recording for all pages into the specified HAR file - // on the filesystem. If not specified, the HAR is not recorded. Make sure to call [BrowserContext.Close] for the HAR - // to be saved. - // - // [HAR]: http://www.softwareishard.com/blog/har-12-spec - RecordHarPath *string `json:"recordHarPath"` - RecordHarURLFilter interface{} `json:"recordHarUrlFilter"` - // Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. - // Make sure to await [BrowserContext.Close] for videos to be saved. - RecordVideo *RecordVideo `json:"recordVideo"` - // Emulates `prefers-reduced-motion` media feature, supported values are `reduce`, `no-preference`. See - // [Page.EmulateMedia] for more details. Passing `no-override` resets emulation to system defaults. Defaults to - // `no-preference`. - ReducedMotion *ReducedMotion `json:"reducedMotion"` - // Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the - // “[object Object]” is set. - Screen *Size `json:"screen"` - // Whether to allow sites to register Service workers. Defaults to `allow`. - // - `allow`: [Service Workers] can be - // registered. - // - `block`: Playwright will block all registration of Service Workers. - // - // [Service Workers]: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API - ServiceWorkers *ServiceWorkerPolicy `json:"serviceWorkers"` - // Learn more about [storage state and auth]. - // Populates context with given storage state. This option can be used to initialize context with logged-in - // information obtained via [BrowserContext.StorageState]. - // - // [storage state and auth]: https://playwright.dev/docs/auth - StorageState *OptionalStorageState `json:"storageState"` - // Populates context with given storage state. This option can be used to initialize context with logged-in - // information obtained via [BrowserContext.StorageState]. Path to the file with saved storage state. - StorageStatePath *string `json:"storageStatePath"` - // If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on - // selectors that imply single target DOM element will throw when more than one element matches the selector. This - // option does not affect any Locator APIs (Locators are always strict). Defaults to `false`. See [Locator] to learn - // more about the strict mode. - StrictSelectors *bool `json:"strictSelectors"` - // Changes the timezone of the context. See - // [ICU's metaZones.txt] - // for a list of supported timezone IDs. Defaults to the system timezone. - // - // [ICU's metaZones.txt]: https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1 - TimezoneId *string `json:"timezoneId"` - // Specific user agent to use in this context. - UserAgent *string `json:"userAgent"` - // Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed - // viewport. Learn more about [viewport emulation]. - // - // [viewport emulation]: https://playwright.dev/docs/emulation#viewport - Viewport *Size `json:"viewport"` -} - -type BrowserNewPageOptions struct { - // Whether to automatically download all the attachments. Defaults to `true` where all the downloads are accepted. - AcceptDownloads *bool `json:"acceptDownloads"` - // When using [Page.Goto], [Page.Route], [Page.WaitForURL], [Page.ExpectRequest], or [Page.ExpectResponse] it takes - // the base URL in consideration by using the [`URL()`] - // constructor for building the corresponding URL. Unset by default. Examples: - // - baseURL: `http://localhost:3000` and navigating to `/bar.html` results in `http://localhost:3000/bar.html` - // - baseURL: `http://localhost:3000/foo/` and navigating to `./bar.html` results in - // `http://localhost:3000/foo/bar.html` - // - baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in - // `http://localhost:3000/bar.html` - // - // [`URL()`]: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL - BaseURL *string `json:"baseURL"` - // Toggles bypassing page's Content-Security-Policy. Defaults to `false`. - BypassCSP *bool `json:"bypassCSP"` - // TLS Client Authentication allows the server to request a client certificate and verify it. - // - // # Details - // - // An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`, - // a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally, - // `passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided - // with an exact match to the request origin that the certificate is valid for. - // **NOTE** When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it - // work by replacing `localhost` with `local.playwright`. - ClientCertificates []ClientCertificate `json:"clientCertificates"` - // Emulates [prefers-colors-scheme] - // media feature, supported values are `light` and `dark`. See [Page.EmulateMedia] for more details. Passing - // `no-override` resets emulation to system defaults. Defaults to `light`. - // - // [prefers-colors-scheme]: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme - ColorScheme *ColorScheme `json:"colorScheme"` - // Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about - // [emulating devices with device scale factor]. - // - // [emulating devices with device scale factor]: https://playwright.dev/docs/emulation#devices - DeviceScaleFactor *float64 `json:"deviceScaleFactor"` - // An object containing additional HTTP headers to be sent with every request. Defaults to none. - ExtraHttpHeaders map[string]string `json:"extraHTTPHeaders"` - // Emulates `forced-colors` media feature, supported values are `active`, `none`. See [Page.EmulateMedia] for - // more details. Passing `no-override` resets emulation to system defaults. Defaults to `none`. - ForcedColors *ForcedColors `json:"forcedColors"` - Geolocation *Geolocation `json:"geolocation"` - // Specifies if viewport supports touch events. Defaults to false. Learn more about - // [mobile emulation]. - // - // [mobile emulation]: https://playwright.dev/docs/emulation#devices - HasTouch *bool `json:"hasTouch"` - // Credentials for [HTTP authentication]. If no - // origin is specified, the username and password are sent to any servers upon unauthorized responses. - // - // [HTTP authentication]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication - HttpCredentials *HttpCredentials `json:"httpCredentials"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device, - // so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more - // about [mobile emulation]. - // - // [mobile emulation]: https://playwright.dev/docs/emulation#ismobile - IsMobile *bool `json:"isMobile"` - // Whether or not to enable JavaScript in the context. Defaults to `true`. Learn more about - // [disabling JavaScript]. - // - // [disabling JavaScript]: https://playwright.dev/docs/emulation#javascript-enabled - JavaScriptEnabled *bool `json:"javaScriptEnabled"` - // Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, - // `Accept-Language` request header value as well as number and date formatting rules. Defaults to the system default - // locale. Learn more about emulation in our [emulation guide]. - // - // [emulation guide]: https://playwright.dev/docs/emulation#locale--timezone - Locale *string `json:"locale"` - // Does not enforce fixed viewport, allows resizing window in the headed mode. - NoViewport *bool `json:"noViewport"` - // Whether to emulate network being offline. Defaults to `false`. Learn more about - // [network emulation]. - // - // [network emulation]: https://playwright.dev/docs/emulation#offline - Offline *bool `json:"offline"` - // A list of permissions to grant to all pages in this context. See [BrowserContext.GrantPermissions] for more - // details. Defaults to none. - Permissions []string `json:"permissions"` - // Network proxy settings to use with this context. Defaults to none. - Proxy *Proxy `json:"proxy"` - // Optional setting to control resource content management. If `omit` is specified, content is not persisted. If - // `attach` is specified, resources are persisted as separate files and all of these files are archived along with the - // HAR file. Defaults to `embed`, which stores content inline the HAR file as per HAR specification. - RecordHarContent *HarContentPolicy `json:"recordHarContent"` - // When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, - // cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`. - RecordHarMode *HarMode `json:"recordHarMode"` - // Optional setting to control whether to omit request content from the HAR. Defaults to `false`. - RecordHarOmitContent *bool `json:"recordHarOmitContent"` - // Enables [HAR] recording for all pages into the specified HAR file - // on the filesystem. If not specified, the HAR is not recorded. Make sure to call [BrowserContext.Close] for the HAR - // to be saved. - // - // [HAR]: http://www.softwareishard.com/blog/har-12-spec - RecordHarPath *string `json:"recordHarPath"` - RecordHarURLFilter interface{} `json:"recordHarUrlFilter"` - // Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. - // Make sure to await [BrowserContext.Close] for videos to be saved. - RecordVideo *RecordVideo `json:"recordVideo"` - // Emulates `prefers-reduced-motion` media feature, supported values are `reduce`, `no-preference`. See - // [Page.EmulateMedia] for more details. Passing `no-override` resets emulation to system defaults. Defaults to - // `no-preference`. - ReducedMotion *ReducedMotion `json:"reducedMotion"` - // Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the - // “[object Object]” is set. - Screen *Size `json:"screen"` - // Whether to allow sites to register Service workers. Defaults to `allow`. - // - `allow`: [Service Workers] can be - // registered. - // - `block`: Playwright will block all registration of Service Workers. - // - // [Service Workers]: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API - ServiceWorkers *ServiceWorkerPolicy `json:"serviceWorkers"` - // Learn more about [storage state and auth]. - // Populates context with given storage state. This option can be used to initialize context with logged-in - // information obtained via [BrowserContext.StorageState]. - // - // [storage state and auth]: https://playwright.dev/docs/auth - StorageState *OptionalStorageState `json:"storageState"` - // Populates context with given storage state. This option can be used to initialize context with logged-in - // information obtained via [BrowserContext.StorageState]. Path to the file with saved storage state. - StorageStatePath *string `json:"storageStatePath"` - // If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on - // selectors that imply single target DOM element will throw when more than one element matches the selector. This - // option does not affect any Locator APIs (Locators are always strict). Defaults to `false`. See [Locator] to learn - // more about the strict mode. - StrictSelectors *bool `json:"strictSelectors"` - // Changes the timezone of the context. See - // [ICU's metaZones.txt] - // for a list of supported timezone IDs. Defaults to the system timezone. - // - // [ICU's metaZones.txt]: https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1 - TimezoneId *string `json:"timezoneId"` - // Specific user agent to use in this context. - UserAgent *string `json:"userAgent"` - // Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed - // viewport. Learn more about [viewport emulation]. - // - // [viewport emulation]: https://playwright.dev/docs/emulation#viewport - Viewport *Size `json:"viewport"` -} - -type BrowserStartTracingOptions struct { - // specify custom categories to use instead of default. - Categories []string `json:"categories"` - // Optional, if specified, tracing includes screenshots of the given page. - Page Page `json:"page"` - // A path to write the trace file to. - Path *string `json:"path"` - // captures screenshots in the trace. - Screenshots *bool `json:"screenshots"` -} - -type OptionalCookie struct { - Name string `json:"name"` - Value string `json:"value"` - // Either url or domain / path are required. Optional. - URL *string `json:"url"` - // For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com". Either url - // or domain / path are required. Optional. - Domain *string `json:"domain"` - // Either url or domain / path are required Optional. - Path *string `json:"path"` - // Unix time in seconds. Optional. - Expires *float64 `json:"expires"` - // Optional. - HttpOnly *bool `json:"httpOnly"` - // Optional. - Secure *bool `json:"secure"` - // Optional. - SameSite *SameSiteAttribute `json:"sameSite"` -} - -type Script struct { - // Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working - // directory. Optional. - Path *string `json:"path"` - // Raw script content. Optional. - Content *string `json:"content"` -} - -type BrowserContextClearCookiesOptions struct { - // Only removes cookies with the given domain. - Domain interface{} `json:"domain"` - // Only removes cookies with the given name. - Name interface{} `json:"name"` - // Only removes cookies with the given path. - Path interface{} `json:"path"` -} - -type BrowserContextCloseOptions struct { - // The reason to be reported to the operations interrupted by the context closure. - Reason *string `json:"reason"` -} - -type Cookie struct { - Name string `json:"name"` - Value string `json:"value"` - Domain string `json:"domain"` - Path string `json:"path"` - // Unix time in seconds. - Expires float64 `json:"expires"` - HttpOnly bool `json:"httpOnly"` - Secure bool `json:"secure"` - SameSite *SameSiteAttribute `json:"sameSite"` -} - -type BrowserContextGrantPermissionsOptions struct { - // The [origin] to grant permissions to, e.g. "https://example.com". - Origin *string `json:"origin"` -} - -type BrowserContextRouteFromHAROptions struct { - // - If set to 'abort' any request not found in the HAR file will be aborted. - // - If set to 'fallback' falls through to the next route handler in the handler chain. - // Defaults to abort. - NotFound *HarNotFound `json:"notFound"` - // If specified, updates the given HAR with the actual network information instead of serving from file. The file is - // written to disk when [BrowserContext.Close] is called. - Update *bool `json:"update"` - // Optional setting to control resource content management. If `attach` is specified, resources are persisted as - // separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file. - UpdateContent *RouteFromHarUpdateContentPolicy `json:"updateContent"` - // When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, - // cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to - // `minimal`. - UpdateMode *HarMode `json:"updateMode"` - // A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the - // pattern will be served from the HAR file. If not specified, all requests are served from the HAR file. - URL interface{} `json:"url"` -} - -type Geolocation struct { - // Latitude between -90 and 90. - Latitude float64 `json:"latitude"` - // Longitude between -180 and 180. - Longitude float64 `json:"longitude"` - // Non-negative accuracy value. Defaults to `0`. - Accuracy *float64 `json:"accuracy"` -} - -type BrowserContextUnrouteAllOptions struct { - // Specifies whether to wait for already running handlers and what to do if they throw errors: - // - `default` - do not wait for current handler calls (if any) to finish, if unrouted handler throws, it may - // result in unhandled error - // - `wait` - wait for current handler calls (if any) to finish - // - `ignoreErrors` - do not wait for current handler calls (if any) to finish, all errors thrown by the handlers - // after unrouting are silently caught - Behavior *UnrouteBehavior `json:"behavior"` -} - -type BrowserContextExpectConsoleMessageOptions struct { - // Receives the [ConsoleMessage] object and resolves to truthy value when the waiting should resolve. - Predicate func(ConsoleMessage) bool `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type BrowserContextExpectEventOptions struct { - // Receives the event data and resolves to truthy value when the waiting should resolve. - Predicate interface{} `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type BrowserContextExpectPageOptions struct { - // Receives the [Page] object and resolves to truthy value when the waiting should resolve. - Predicate func(Page) bool `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type BrowserContextWaitForEventOptions struct { - // Receives the event data and resolves to truthy value when the waiting should resolve. - Predicate interface{} `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type BrowserTypeConnectOptions struct { - // This option exposes network available on the connecting client to the browser being connected to. Consists of a - // list of rules separated by comma. - // Available rules: - // 1. Hostname pattern, for example: `example.com`, `*.org:99`, `x.*.y.com`, `*foo.org`. - // 2. IP literal, for example: `127.0.0.1`, `0.0.0.0:99`, `[::1]`, `[0:0::1]:99`. - // 3. `<loopback>` that matches local loopback interfaces: `localhost`, `*.localhost`, `127.0.0.1`, `[::1]`. - // Some common examples: - // 4. `"*"` to expose all network. - // 5. `"<loopback>"` to expose localhost network. - // 6. `"*.test.internal-domain,*.staging.internal-domain,<loopback>"` to expose test/staging deployments and - // localhost. - ExposeNetwork *string `json:"exposeNetwork"` - // Additional HTTP headers to be sent with web socket connect request. Optional. - Headers map[string]string `json:"headers"` - // Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going - // on. Defaults to 0. - SlowMo *float64 `json:"slowMo"` - // Maximum time in milliseconds to wait for the connection to be established. Defaults to `0` (no timeout). - Timeout *float64 `json:"timeout"` -} - -type BrowserTypeConnectOverCDPOptions struct { - // Additional HTTP headers to be sent with connect request. Optional. - Headers map[string]string `json:"headers"` - // Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going - // on. Defaults to 0. - SlowMo *float64 `json:"slowMo"` - // Maximum time in milliseconds to wait for the connection to be established. Defaults to `30000` (30 seconds). Pass - // `0` to disable timeout. - Timeout *float64 `json:"timeout"` -} - -type BrowserTypeLaunchOptions struct { - // **NOTE** Use custom browser args at your own risk, as some of them may break Playwright functionality. - // Additional arguments to pass to the browser instance. The list of Chromium flags can be found - // [here]. - // - // [here]: https://peter.sh/experiments/chromium-command-line-switches/ - Args []string `json:"args"` - // Browser distribution channel. - // Use "chromium" to [opt in to new headless mode]. - // Use "chrome", "chrome-beta", "chrome-dev", "chrome-canary", "msedge", "msedge-beta", "msedge-dev", or - // "msedge-canary" to use branded [Google Chrome and Microsoft Edge]. - // - // [opt in to new headless mode]: https://playwright.dev/docs/browsers#chromium-new-headless-mode - // [Google Chrome and Microsoft Edge]: https://playwright.dev/docs/browsers#google-chrome--microsoft-edge - Channel *string `json:"channel"` - // Enable Chromium sandboxing. Defaults to `false`. - ChromiumSandbox *bool `json:"chromiumSandbox"` - // **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the - // “[object Object]” option will be set `false`. - // - // Deprecated: Use [debugging tools] instead. - // - // [debugging tools]: https://playwright.dev/docs/debug - Devtools *bool `json:"devtools"` - // If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and - // is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were - // created in is closed. - DownloadsPath *string `json:"downloadsPath"` - // Specify environment variables that will be visible to the browser. Defaults to `process.env`. - Env map[string]string `json:"env"` - // Path to a browser executable to run instead of the bundled one. If “[object Object]” is a relative path, then it is - // resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, - // Firefox or WebKit, use at your own risk. - ExecutablePath *string `json:"executablePath"` - // Firefox user preferences. Learn more about the Firefox user preferences at - // [`about:config`]. - // - // [`about:config`]: https://support.mozilla.org/en-US/kb/about-config-editor-firefox - FirefoxUserPrefs map[string]interface{} `json:"firefoxUserPrefs"` - // Close the browser process on SIGHUP. Defaults to `true`. - HandleSIGHUP *bool `json:"handleSIGHUP"` - // Close the browser process on Ctrl-C. Defaults to `true`. - HandleSIGINT *bool `json:"handleSIGINT"` - // Close the browser process on SIGTERM. Defaults to `true`. - HandleSIGTERM *bool `json:"handleSIGTERM"` - // Whether to run browser in headless mode. More details for - // [Chromium] and - // [Firefox]. Defaults to `true` unless the - // “[object Object]” option is `true`. - // - // [Chromium]: https://developers.google.com/web/updates/2017/04/headless-chrome - // [Firefox]: https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/ - Headless *bool `json:"headless"` - // If `true`, Playwright does not pass its own configurations args and only uses the ones from “[object Object]”. - // Dangerous option; use with care. Defaults to `false`. - IgnoreAllDefaultArgs *bool `json:"ignoreAllDefaultArgs"` - // If `true`, Playwright does not pass its own configurations args and only uses the ones from “[object Object]”. - // Dangerous option; use with care. - IgnoreDefaultArgs []string `json:"ignoreDefaultArgs"` - // Network proxy settings. - Proxy *Proxy `json:"proxy"` - // Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going - // on. - SlowMo *float64 `json:"slowMo"` - // Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` - // to disable timeout. - Timeout *float64 `json:"timeout"` - // If specified, traces are saved into this directory. - TracesDir *string `json:"tracesDir"` -} - -type BrowserTypeLaunchPersistentContextOptions struct { - // Whether to automatically download all the attachments. Defaults to `true` where all the downloads are accepted. - AcceptDownloads *bool `json:"acceptDownloads"` - // **NOTE** Use custom browser args at your own risk, as some of them may break Playwright functionality. - // Additional arguments to pass to the browser instance. The list of Chromium flags can be found - // [here]. - // - // [here]: https://peter.sh/experiments/chromium-command-line-switches/ - Args []string `json:"args"` - // When using [Page.Goto], [Page.Route], [Page.WaitForURL], [Page.ExpectRequest], or [Page.ExpectResponse] it takes - // the base URL in consideration by using the [`URL()`] - // constructor for building the corresponding URL. Unset by default. Examples: - // - baseURL: `http://localhost:3000` and navigating to `/bar.html` results in `http://localhost:3000/bar.html` - // - baseURL: `http://localhost:3000/foo/` and navigating to `./bar.html` results in - // `http://localhost:3000/foo/bar.html` - // - baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in - // `http://localhost:3000/bar.html` - // - // [`URL()`]: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL - BaseURL *string `json:"baseURL"` - // Toggles bypassing page's Content-Security-Policy. Defaults to `false`. - BypassCSP *bool `json:"bypassCSP"` - // Browser distribution channel. - // Use "chromium" to [opt in to new headless mode]. - // Use "chrome", "chrome-beta", "chrome-dev", "chrome-canary", "msedge", "msedge-beta", "msedge-dev", or - // "msedge-canary" to use branded [Google Chrome and Microsoft Edge]. - // - // [opt in to new headless mode]: https://playwright.dev/docs/browsers#chromium-new-headless-mode - // [Google Chrome and Microsoft Edge]: https://playwright.dev/docs/browsers#google-chrome--microsoft-edge - Channel *string `json:"channel"` - // Enable Chromium sandboxing. Defaults to `false`. - ChromiumSandbox *bool `json:"chromiumSandbox"` - // TLS Client Authentication allows the server to request a client certificate and verify it. - // - // # Details - // - // An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`, - // a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally, - // `passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided - // with an exact match to the request origin that the certificate is valid for. - // **NOTE** When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it - // work by replacing `localhost` with `local.playwright`. - ClientCertificates []ClientCertificate `json:"clientCertificates"` - // Emulates [prefers-colors-scheme] - // media feature, supported values are `light` and `dark`. See [Page.EmulateMedia] for more details. Passing - // `no-override` resets emulation to system defaults. Defaults to `light`. - // - // [prefers-colors-scheme]: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme - ColorScheme *ColorScheme `json:"colorScheme"` - // Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about - // [emulating devices with device scale factor]. - // - // [emulating devices with device scale factor]: https://playwright.dev/docs/emulation#devices - DeviceScaleFactor *float64 `json:"deviceScaleFactor"` - // **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the - // “[object Object]” option will be set `false`. - // - // Deprecated: Use [debugging tools] instead. - // - // [debugging tools]: https://playwright.dev/docs/debug - Devtools *bool `json:"devtools"` - // If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and - // is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were - // created in is closed. - DownloadsPath *string `json:"downloadsPath"` - // Specify environment variables that will be visible to the browser. Defaults to `process.env`. - Env map[string]string `json:"env"` - // Path to a browser executable to run instead of the bundled one. If “[object Object]” is a relative path, then it is - // resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, - // Firefox or WebKit, use at your own risk. - ExecutablePath *string `json:"executablePath"` - // An object containing additional HTTP headers to be sent with every request. Defaults to none. - ExtraHttpHeaders map[string]string `json:"extraHTTPHeaders"` - // Firefox user preferences. Learn more about the Firefox user preferences at - // [`about:config`]. - // - // [`about:config`]: https://support.mozilla.org/en-US/kb/about-config-editor-firefox - FirefoxUserPrefs map[string]interface{} `json:"firefoxUserPrefs"` - // Emulates `forced-colors` media feature, supported values are `active`, `none`. See [Page.EmulateMedia] for - // more details. Passing `no-override` resets emulation to system defaults. Defaults to `none`. - ForcedColors *ForcedColors `json:"forcedColors"` - Geolocation *Geolocation `json:"geolocation"` - // Close the browser process on SIGHUP. Defaults to `true`. - HandleSIGHUP *bool `json:"handleSIGHUP"` - // Close the browser process on Ctrl-C. Defaults to `true`. - HandleSIGINT *bool `json:"handleSIGINT"` - // Close the browser process on SIGTERM. Defaults to `true`. - HandleSIGTERM *bool `json:"handleSIGTERM"` - // Specifies if viewport supports touch events. Defaults to false. Learn more about - // [mobile emulation]. - // - // [mobile emulation]: https://playwright.dev/docs/emulation#devices - HasTouch *bool `json:"hasTouch"` - // Whether to run browser in headless mode. More details for - // [Chromium] and - // [Firefox]. Defaults to `true` unless the - // “[object Object]” option is `true`. - // - // [Chromium]: https://developers.google.com/web/updates/2017/04/headless-chrome - // [Firefox]: https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/ - Headless *bool `json:"headless"` - // Credentials for [HTTP authentication]. If no - // origin is specified, the username and password are sent to any servers upon unauthorized responses. - // - // [HTTP authentication]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication - HttpCredentials *HttpCredentials `json:"httpCredentials"` - // If `true`, Playwright does not pass its own configurations args and only uses the ones from “[object Object]”. - // Dangerous option; use with care. Defaults to `false`. - IgnoreAllDefaultArgs *bool `json:"ignoreAllDefaultArgs"` - // If `true`, Playwright does not pass its own configurations args and only uses the ones from “[object Object]”. - // Dangerous option; use with care. - IgnoreDefaultArgs []string `json:"ignoreDefaultArgs"` - // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. - IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` - // Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device, - // so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more - // about [mobile emulation]. - // - // [mobile emulation]: https://playwright.dev/docs/emulation#ismobile - IsMobile *bool `json:"isMobile"` - // Whether or not to enable JavaScript in the context. Defaults to `true`. Learn more about - // [disabling JavaScript]. - // - // [disabling JavaScript]: https://playwright.dev/docs/emulation#javascript-enabled - JavaScriptEnabled *bool `json:"javaScriptEnabled"` - // Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, - // `Accept-Language` request header value as well as number and date formatting rules. Defaults to the system default - // locale. Learn more about emulation in our [emulation guide]. - // - // [emulation guide]: https://playwright.dev/docs/emulation#locale--timezone - Locale *string `json:"locale"` - // Does not enforce fixed viewport, allows resizing window in the headed mode. - NoViewport *bool `json:"noViewport"` - // Whether to emulate network being offline. Defaults to `false`. Learn more about - // [network emulation]. - // - // [network emulation]: https://playwright.dev/docs/emulation#offline - Offline *bool `json:"offline"` - // A list of permissions to grant to all pages in this context. See [BrowserContext.GrantPermissions] for more - // details. Defaults to none. - Permissions []string `json:"permissions"` - // Network proxy settings. - Proxy *Proxy `json:"proxy"` - // Optional setting to control resource content management. If `omit` is specified, content is not persisted. If - // `attach` is specified, resources are persisted as separate files and all of these files are archived along with the - // HAR file. Defaults to `embed`, which stores content inline the HAR file as per HAR specification. - RecordHarContent *HarContentPolicy `json:"recordHarContent"` - // When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, - // cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`. - RecordHarMode *HarMode `json:"recordHarMode"` - // Optional setting to control whether to omit request content from the HAR. Defaults to `false`. - RecordHarOmitContent *bool `json:"recordHarOmitContent"` - // Enables [HAR] recording for all pages into the specified HAR file - // on the filesystem. If not specified, the HAR is not recorded. Make sure to call [BrowserContext.Close] for the HAR - // to be saved. - // - // [HAR]: http://www.softwareishard.com/blog/har-12-spec - RecordHarPath *string `json:"recordHarPath"` - RecordHarURLFilter interface{} `json:"recordHarUrlFilter"` - // Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. - // Make sure to await [BrowserContext.Close] for videos to be saved. - RecordVideo *RecordVideo `json:"recordVideo"` - // Emulates `prefers-reduced-motion` media feature, supported values are `reduce`, `no-preference`. See - // [Page.EmulateMedia] for more details. Passing `no-override` resets emulation to system defaults. Defaults to - // `no-preference`. - ReducedMotion *ReducedMotion `json:"reducedMotion"` - // Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the - // “[object Object]” is set. - Screen *Size `json:"screen"` - // Whether to allow sites to register Service workers. Defaults to `allow`. - // - `allow`: [Service Workers] can be - // registered. - // - `block`: Playwright will block all registration of Service Workers. - // - // [Service Workers]: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API - ServiceWorkers *ServiceWorkerPolicy `json:"serviceWorkers"` - // Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going - // on. - SlowMo *float64 `json:"slowMo"` - // If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on - // selectors that imply single target DOM element will throw when more than one element matches the selector. This - // option does not affect any Locator APIs (Locators are always strict). Defaults to `false`. See [Locator] to learn - // more about the strict mode. - StrictSelectors *bool `json:"strictSelectors"` - // Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` - // to disable timeout. - Timeout *float64 `json:"timeout"` - // Changes the timezone of the context. See - // [ICU's metaZones.txt] - // for a list of supported timezone IDs. Defaults to the system timezone. - // - // [ICU's metaZones.txt]: https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1 - TimezoneId *string `json:"timezoneId"` - // If specified, traces are saved into this directory. - TracesDir *string `json:"tracesDir"` - // Specific user agent to use in this context. - UserAgent *string `json:"userAgent"` - // Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed - // viewport. Learn more about [viewport emulation]. - // - // [viewport emulation]: https://playwright.dev/docs/emulation#viewport - Viewport *Size `json:"viewport"` -} - -type ClockInstallOptions struct { - // Time to initialize with, current system time by default. - Time interface{} `json:"time"` -} - -type ConsoleMessageLocation struct { - // URL of the resource. - URL string `json:"url"` - // 0-based line number in the resource. - LineNumber int `json:"lineNumber"` - // 0-based column number in the resource. - ColumnNumber int `json:"columnNumber"` -} - -type Rect struct { - // the x coordinate of the element in pixels. - X float64 `json:"x"` - // the y coordinate of the element in pixels. - Y float64 `json:"y"` - // the width of the element in pixels. - Width float64 `json:"width"` - // the height of the element in pixels. - Height float64 `json:"height"` -} - -type ElementHandleCheckOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type ElementHandleClickOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // defaults to 1. See [UIEvent.Detail]. - ClickCount *int `json:"clickCount"` - // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You - // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as - // navigating to inaccessible pages. Defaults to `false`. - // - // Deprecated: This option will default to `true` in the future. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type ElementHandleDblclickOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type ElementHandleFillOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type ElementHandleHoverOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type ElementHandleInputValueOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type ElementHandlePressOptions struct { - // Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You - // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as - // navigating to inaccessible pages. Defaults to `false`. - // - // Deprecated: This option will default to `true` in the future. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type ElementHandleScreenshotOptions struct { - // When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different - // treatment depending on their duration: - // - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event. - // - infinite animations are canceled to initial state, and then played over after the screenshot. - // Defaults to `"allow"` that leaves animations untouched. - Animations *ScreenshotAnimations `json:"animations"` - // When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be - // changed. Defaults to `"hide"`. - Caret *ScreenshotCaret `json:"caret"` - // Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink - // box `#FF00FF` (customized by “[object Object]”) that completely covers its bounding box. The mask is also applied - // to invisible elements, see [Matching only visible elements] to - // disable that. - // - // [Matching only visible elements]: https://playwright.dev/docs/locators#matching-only-visible-elements - Mask []Locator `json:"mask"` - // Specify the color of the overlay box for masked elements, in - // [CSS color format]. Default color is pink `#FF00FF`. - // - // [CSS color format]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value - MaskColor *string `json:"maskColor"` - // Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. - // Defaults to `false`. - OmitBackground *bool `json:"omitBackground"` - // The file path to save the image to. The screenshot type will be inferred from file extension. If “[object Object]” - // is a relative path, then it is resolved relative to the current working directory. If no path is provided, the - // image won't be saved to the disk. - Path *string `json:"path"` - // The quality of the image, between 0-100. Not applicable to `png` images. - Quality *int `json:"quality"` - // When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this - // will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so - // screenshots of high-dpi devices will be twice as large or even larger. - // Defaults to `"device"`. - Scale *ScreenshotScale `json:"scale"` - // Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make - // elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces - // the Shadow DOM and applies to the inner frames. - Style *string `json:"style"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // Specify screenshot type, defaults to `png`. - Type *ScreenshotType `json:"type"` -} - -type ElementHandleScrollIntoViewIfNeededOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type ElementHandleSelectOptionOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type ElementHandleSelectTextOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type ElementHandleSetCheckedOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type ElementHandleSetInputFilesOptions struct { - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type ElementHandleTapOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type ElementHandleTypeOptions struct { - // Time to wait between key presses in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type ElementHandleUncheckOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type ElementHandleWaitForElementStateOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type ElementHandleWaitForSelectorOptions struct { - // Defaults to `visible`. Can be either: - // - `attached` - wait for element to be present in DOM. - // - `detached` - wait for element to not be present in DOM. - // - `visible` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element - // without any content or with `display:none` has an empty bounding box and is not considered visible. - // - `hidden` - wait for element to be either detached from DOM, or have an empty bounding box or - // `visibility:hidden`. This is opposite to the `visible` option. - State *WaitForSelectorState `json:"state"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FileChooserSetFilesOptions struct { - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameAddScriptTagOptions struct { - // Raw JavaScript content to be injected into frame. - Content *string `json:"content"` - // Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative - // to the current working directory. - Path *string `json:"path"` - // Script type. Use 'module' in order to load a JavaScript ES6 module. See - // [script] for more details. - // - // [script]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script - Type *string `json:"type"` - // URL of a script to be added. - URL *string `json:"url"` -} - -type FrameAddStyleTagOptions struct { - // Raw CSS content to be injected into frame. - Content *string `json:"content"` - // Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the - // current working directory. - Path *string `json:"path"` - // URL of the `<link>` tag. - URL *string `json:"url"` -} - -type FrameCheckOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type FrameClickOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // defaults to 1. See [UIEvent.Detail]. - ClickCount *int `json:"clickCount"` - // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You - // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as - // navigating to inaccessible pages. Defaults to `false`. - // - // Deprecated: This option will default to `true` in the future. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type FrameDblclickOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type FrameDispatchEventOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameDragAndDropOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not - // specified, some visible point of the element is used. - SourcePosition *Position `json:"sourcePosition"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Drops on the target element at this point relative to the top-left corner of the element's padding box. If not - // specified, some visible point of the element is used. - TargetPosition *Position `json:"targetPosition"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type FrameEvalOnSelectorOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` -} - -type FrameFillOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameFocusOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameGetAttributeOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameGetByAltTextOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type FrameGetByLabelOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type FrameGetByPlaceholderOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type FrameGetByRoleOptions struct { - // An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls. - // Learn more about [`aria-checked`]. - // - // [`aria-checked`]: https://www.w3.org/TR/wai-aria-1.2/#aria-checked - Checked *bool `json:"checked"` - // An attribute that is usually set by `aria-disabled` or `disabled`. - // **NOTE** Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about - // [`aria-disabled`]. - // - // [`aria-disabled`]: https://www.w3.org/TR/wai-aria-1.2/#aria-disabled - Disabled *bool `json:"disabled"` - // Whether “[object Object]” is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when - // “[object Object]” is a regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` - // An attribute that is usually set by `aria-expanded`. - // Learn more about [`aria-expanded`]. - // - // [`aria-expanded`]: https://www.w3.org/TR/wai-aria-1.2/#aria-expanded - Expanded *bool `json:"expanded"` - // Option that controls whether hidden elements are matched. By default, only non-hidden elements, as - // [defined by ARIA], are matched by role selector. - // Learn more about [`aria-hidden`]. - // - // [defined by ARIA]: https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion - // [`aria-hidden`]: https://www.w3.org/TR/wai-aria-1.2/#aria-hidden - IncludeHidden *bool `json:"includeHidden"` - // A number attribute that is usually present for roles `heading`, `listitem`, `row`, `treeitem`, with default values - // for `<h1>-<h6>` elements. - // Learn more about [`aria-level`]. - // - // [`aria-level`]: https://www.w3.org/TR/wai-aria-1.2/#aria-level - Level *int `json:"level"` - // Option to match the [accessible name]. By default, matching is - // case-insensitive and searches for a substring, use “[object Object]” to control this behavior. - // Learn more about [accessible name]. - // - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - Name interface{} `json:"name"` - // An attribute that is usually set by `aria-pressed`. - // Learn more about [`aria-pressed`]. - // - // [`aria-pressed`]: https://www.w3.org/TR/wai-aria-1.2/#aria-pressed - Pressed *bool `json:"pressed"` - // An attribute that is usually set by `aria-selected`. - // Learn more about [`aria-selected`]. - // - // [`aria-selected`]: https://www.w3.org/TR/wai-aria-1.2/#aria-selected - Selected *bool `json:"selected"` -} - -type FrameGetByTextOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type FrameGetByTitleOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type FrameGotoOptions struct { - // Referer header value. If provided it will take preference over the referer header value set by - // [Page.SetExtraHTTPHeaders]. - Referer *string `json:"referer"` - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type FrameHoverOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type FrameInnerHTMLOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameInnerTextOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameInputValueOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameIsCheckedOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameIsDisabledOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameIsEditableOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameIsEnabledOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameIsHiddenOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // - // Deprecated: This option is ignored. [Frame.IsHidden] does not wait for the element to become hidden and returns immediately. - Timeout *float64 `json:"timeout"` -} - -type FrameIsVisibleOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // - // Deprecated: This option is ignored. [Frame.IsVisible] does not wait for the element to become visible and returns immediately. - Timeout *float64 `json:"timeout"` -} - -type FrameLocatorOptions struct { - // Narrows down the results of the method to those which contain elements matching this relative locator. For example, - // `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`. - // Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not - // the document root. For example, you can find `content` that has `div` in - // `<article><content><div>Playwright</div></content></article>`. However, looking for `content` that has `article - // div` will fail, because the inner locator must be relative and should not use any elements outside the `content`. - // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. - Has Locator `json:"has"` - // Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the - // outer one. For example, `article` that does not have `div` matches `<article><span>Playwright</span></article>`. - // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. - HasNot Locator `json:"hasNot"` - // Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. - // When passed a [string], matching is case-insensitive and searches for a substring. - HasNotText interface{} `json:"hasNotText"` - // Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When - // passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches - // `<article><div>Playwright</div></article>`. - HasText interface{} `json:"hasText"` -} - -type FramePressOptions struct { - // Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You - // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as - // navigating to inaccessible pages. Defaults to `false`. - // - // Deprecated: This option will default to `true` in the future. - NoWaitAfter *bool `json:"noWaitAfter"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameQuerySelectorOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` -} - -type FrameSelectOptionOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameSetCheckedOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type FrameSetContentOptions struct { - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type FrameSetInputFilesOptions struct { - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameTapOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type FrameTextContentOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameTypeOptions struct { - // Time to wait between key presses in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameUncheckOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type FrameWaitForFunctionOptions struct { - // If “[object Object]” is `raf`, then “[object Object]” is constantly executed in `requestAnimationFrame` callback. - // If “[object Object]” is a number, then it is treated as an interval in milliseconds at which the function would be - // executed. Defaults to `raf`. - Polling interface{} `json:"polling"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameWaitForLoadStateOptions struct { - // Optional load state to wait for, defaults to `load`. If the state has been already reached while loading current - // document, the method resolves immediately. Can be one of: - // - `load` - wait for the `load` event to be fired. - // - `domcontentloaded` - wait for the `DOMContentLoaded` event to be fired. - // - `networkidle` - **DISCOURAGED** wait until there are no network connections for at least `500` ms. Don't use - // this method for testing, rely on web assertions to assess readiness instead. - State *LoadState `json:"state"` - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameExpectNavigationOptions struct { - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if - // the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly - // equal to the string. - URL interface{} `json:"url"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type FrameWaitForSelectorOptions struct { - // Defaults to `visible`. Can be either: - // - `attached` - wait for element to be present in DOM. - // - `detached` - wait for element to not be present in DOM. - // - `visible` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element - // without any content or with `display:none` has an empty bounding box and is not considered visible. - // - `hidden` - wait for element to be either detached from DOM, or have an empty bounding box or - // `visibility:hidden`. This is opposite to the `visible` option. - State *WaitForSelectorState `json:"state"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type FrameWaitForURLOptions struct { - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type FrameLocatorGetByAltTextOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type FrameLocatorGetByLabelOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type FrameLocatorGetByPlaceholderOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type FrameLocatorGetByRoleOptions struct { - // An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls. - // Learn more about [`aria-checked`]. - // - // [`aria-checked`]: https://www.w3.org/TR/wai-aria-1.2/#aria-checked - Checked *bool `json:"checked"` - // An attribute that is usually set by `aria-disabled` or `disabled`. - // **NOTE** Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about - // [`aria-disabled`]. - // - // [`aria-disabled`]: https://www.w3.org/TR/wai-aria-1.2/#aria-disabled - Disabled *bool `json:"disabled"` - // Whether “[object Object]” is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when - // “[object Object]” is a regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` - // An attribute that is usually set by `aria-expanded`. - // Learn more about [`aria-expanded`]. - // - // [`aria-expanded`]: https://www.w3.org/TR/wai-aria-1.2/#aria-expanded - Expanded *bool `json:"expanded"` - // Option that controls whether hidden elements are matched. By default, only non-hidden elements, as - // [defined by ARIA], are matched by role selector. - // Learn more about [`aria-hidden`]. - // - // [defined by ARIA]: https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion - // [`aria-hidden`]: https://www.w3.org/TR/wai-aria-1.2/#aria-hidden - IncludeHidden *bool `json:"includeHidden"` - // A number attribute that is usually present for roles `heading`, `listitem`, `row`, `treeitem`, with default values - // for `<h1>-<h6>` elements. - // Learn more about [`aria-level`]. - // - // [`aria-level`]: https://www.w3.org/TR/wai-aria-1.2/#aria-level - Level *int `json:"level"` - // Option to match the [accessible name]. By default, matching is - // case-insensitive and searches for a substring, use “[object Object]” to control this behavior. - // Learn more about [accessible name]. - // - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - Name interface{} `json:"name"` - // An attribute that is usually set by `aria-pressed`. - // Learn more about [`aria-pressed`]. - // - // [`aria-pressed`]: https://www.w3.org/TR/wai-aria-1.2/#aria-pressed - Pressed *bool `json:"pressed"` - // An attribute that is usually set by `aria-selected`. - // Learn more about [`aria-selected`]. - // - // [`aria-selected`]: https://www.w3.org/TR/wai-aria-1.2/#aria-selected - Selected *bool `json:"selected"` -} - -type FrameLocatorGetByTextOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type FrameLocatorGetByTitleOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type FrameLocatorLocatorOptions struct { - // Narrows down the results of the method to those which contain elements matching this relative locator. For example, - // `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`. - // Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not - // the document root. For example, you can find `content` that has `div` in - // `<article><content><div>Playwright</div></content></article>`. However, looking for `content` that has `article - // div` will fail, because the inner locator must be relative and should not use any elements outside the `content`. - // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. - Has Locator `json:"has"` - // Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the - // outer one. For example, `article` that does not have `div` matches `<article><span>Playwright</span></article>`. - // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. - HasNot Locator `json:"hasNot"` - // Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. - // When passed a [string], matching is case-insensitive and searches for a substring. - HasNotText interface{} `json:"hasNotText"` - // Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When - // passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches - // `<article><div>Playwright</div></article>`. - HasText interface{} `json:"hasText"` -} - -type KeyboardPressOptions struct { - // Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` -} - -type KeyboardTypeOptions struct { - // Time to wait between key presses in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` -} - -type LocatorAriaSnapshotOptions struct { - // Generate symbolic reference for each element. One can use `aria-ref=<ref>` locator immediately after capturing the - // snapshot to perform actions on the element. - Ref *bool `json:"ref"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorBlurOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorBoundingBoxOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorCheckOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type LocatorClearOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorClickOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // defaults to 1. See [UIEvent.Detail]. - ClickCount *int `json:"clickCount"` - // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You - // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as - // navigating to inaccessible pages. Defaults to `false`. - // - // Deprecated: This option will default to `true` in the future. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type LocatorDblclickOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type LocatorDispatchEventOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorDragToOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not - // specified, some visible point of the element is used. - SourcePosition *Position `json:"sourcePosition"` - // Drops on the target element at this point relative to the top-left corner of the element's padding box. If not - // specified, some visible point of the element is used. - TargetPosition *Position `json:"targetPosition"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type LocatorElementHandleOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorEvaluateOptions struct { - // Maximum time in milliseconds to wait for the locator before evaluating. Note that after locator is resolved, - // evaluation itself is not limited by the timeout. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - Timeout *float64 `json:"timeout"` -} - -type LocatorEvaluateHandleOptions struct { - // Maximum time in milliseconds to wait for the locator before evaluating. Note that after locator is resolved, - // evaluation itself is not limited by the timeout. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - Timeout *float64 `json:"timeout"` -} - -type LocatorFillOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorFilterOptions struct { - // Narrows down the results of the method to those which contain elements matching this relative locator. For example, - // `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`. - // Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not - // the document root. For example, you can find `content` that has `div` in - // `<article><content><div>Playwright</div></content></article>`. However, looking for `content` that has `article - // div` will fail, because the inner locator must be relative and should not use any elements outside the `content`. - // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. - Has Locator `json:"has"` - // Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the - // outer one. For example, `article` that does not have `div` matches `<article><span>Playwright</span></article>`. - // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. - HasNot Locator `json:"hasNot"` - // Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. - // When passed a [string], matching is case-insensitive and searches for a substring. - HasNotText interface{} `json:"hasNotText"` - // Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When - // passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches - // `<article><div>Playwright</div></article>`. - HasText interface{} `json:"hasText"` - // Only matches visible or invisible elements. - Visible *bool `json:"visible"` -} - -type LocatorFocusOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorGetAttributeOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorGetByAltTextOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type LocatorGetByLabelOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type LocatorGetByPlaceholderOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type LocatorGetByRoleOptions struct { - // An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls. - // Learn more about [`aria-checked`]. - // - // [`aria-checked`]: https://www.w3.org/TR/wai-aria-1.2/#aria-checked - Checked *bool `json:"checked"` - // An attribute that is usually set by `aria-disabled` or `disabled`. - // **NOTE** Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about - // [`aria-disabled`]. - // - // [`aria-disabled`]: https://www.w3.org/TR/wai-aria-1.2/#aria-disabled - Disabled *bool `json:"disabled"` - // Whether “[object Object]” is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when - // “[object Object]” is a regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` - // An attribute that is usually set by `aria-expanded`. - // Learn more about [`aria-expanded`]. - // - // [`aria-expanded`]: https://www.w3.org/TR/wai-aria-1.2/#aria-expanded - Expanded *bool `json:"expanded"` - // Option that controls whether hidden elements are matched. By default, only non-hidden elements, as - // [defined by ARIA], are matched by role selector. - // Learn more about [`aria-hidden`]. - // - // [defined by ARIA]: https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion - // [`aria-hidden`]: https://www.w3.org/TR/wai-aria-1.2/#aria-hidden - IncludeHidden *bool `json:"includeHidden"` - // A number attribute that is usually present for roles `heading`, `listitem`, `row`, `treeitem`, with default values - // for `<h1>-<h6>` elements. - // Learn more about [`aria-level`]. - // - // [`aria-level`]: https://www.w3.org/TR/wai-aria-1.2/#aria-level - Level *int `json:"level"` - // Option to match the [accessible name]. By default, matching is - // case-insensitive and searches for a substring, use “[object Object]” to control this behavior. - // Learn more about [accessible name]. - // - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - Name interface{} `json:"name"` - // An attribute that is usually set by `aria-pressed`. - // Learn more about [`aria-pressed`]. - // - // [`aria-pressed`]: https://www.w3.org/TR/wai-aria-1.2/#aria-pressed - Pressed *bool `json:"pressed"` - // An attribute that is usually set by `aria-selected`. - // Learn more about [`aria-selected`]. - // - // [`aria-selected`]: https://www.w3.org/TR/wai-aria-1.2/#aria-selected - Selected *bool `json:"selected"` -} - -type LocatorGetByTextOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type LocatorGetByTitleOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type LocatorHoverOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type LocatorInnerHTMLOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorInnerTextOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorInputValueOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorIsCheckedOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorIsDisabledOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorIsEditableOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorIsEnabledOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorIsHiddenOptions struct { - // - // Deprecated: This option is ignored. [Locator.IsHidden] does not wait for the element to become hidden and returns immediately. - Timeout *float64 `json:"timeout"` -} - -type LocatorIsVisibleOptions struct { - // - // Deprecated: This option is ignored. [Locator.IsVisible] does not wait for the element to become visible and returns immediately. - Timeout *float64 `json:"timeout"` -} - -type LocatorLocatorOptions struct { - // Narrows down the results of the method to those which contain elements matching this relative locator. For example, - // `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`. - // Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not - // the document root. For example, you can find `content` that has `div` in - // `<article><content><div>Playwright</div></content></article>`. However, looking for `content` that has `article - // div` will fail, because the inner locator must be relative and should not use any elements outside the `content`. - // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. - Has Locator `json:"has"` - // Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the - // outer one. For example, `article` that does not have `div` matches `<article><span>Playwright</span></article>`. - // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. - HasNot Locator `json:"hasNot"` - // Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. - // When passed a [string], matching is case-insensitive and searches for a substring. - HasNotText interface{} `json:"hasNotText"` - // Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When - // passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches - // `<article><div>Playwright</div></article>`. - HasText interface{} `json:"hasText"` -} - -type LocatorPressOptions struct { - // Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You - // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as - // navigating to inaccessible pages. Defaults to `false`. - // - // Deprecated: This option will default to `true` in the future. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorPressSequentiallyOptions struct { - // Time to wait between key presses in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorScreenshotOptions struct { - // When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different - // treatment depending on their duration: - // - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event. - // - infinite animations are canceled to initial state, and then played over after the screenshot. - // Defaults to `"allow"` that leaves animations untouched. - Animations *ScreenshotAnimations `json:"animations"` - // When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be - // changed. Defaults to `"hide"`. - Caret *ScreenshotCaret `json:"caret"` - // Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink - // box `#FF00FF` (customized by “[object Object]”) that completely covers its bounding box. The mask is also applied - // to invisible elements, see [Matching only visible elements] to - // disable that. - // - // [Matching only visible elements]: https://playwright.dev/docs/locators#matching-only-visible-elements - Mask []Locator `json:"mask"` - // Specify the color of the overlay box for masked elements, in - // [CSS color format]. Default color is pink `#FF00FF`. - // - // [CSS color format]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value - MaskColor *string `json:"maskColor"` - // Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. - // Defaults to `false`. - OmitBackground *bool `json:"omitBackground"` - // The file path to save the image to. The screenshot type will be inferred from file extension. If “[object Object]” - // is a relative path, then it is resolved relative to the current working directory. If no path is provided, the - // image won't be saved to the disk. - Path *string `json:"path"` - // The quality of the image, between 0-100. Not applicable to `png` images. - Quality *int `json:"quality"` - // When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this - // will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so - // screenshots of high-dpi devices will be twice as large or even larger. - // Defaults to `"device"`. - Scale *ScreenshotScale `json:"scale"` - // Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make - // elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces - // the Shadow DOM and applies to the inner frames. - Style *string `json:"style"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // Specify screenshot type, defaults to `png`. - Type *ScreenshotType `json:"type"` -} - -type LocatorScrollIntoViewIfNeededOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorSelectOptionOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorSelectTextOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorSetCheckedOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type LocatorSetInputFilesOptions struct { - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorTapOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type LocatorTextContentOptions struct { - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorTypeOptions struct { - // Time to wait between key presses in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorUncheckOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type LocatorWaitForOptions struct { - // Defaults to `visible`. Can be either: - // - `attached` - wait for element to be present in DOM. - // - `detached` - wait for element to not be present in DOM. - // - `visible` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element - // without any content or with `display:none` has an empty bounding box and is not considered visible. - // - `hidden` - wait for element to be either detached from DOM, or have an empty bounding box or - // `visibility:hidden`. This is opposite to the `visible` option. - State *WaitForSelectorState `json:"state"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToBeAttachedOptions struct { - Attached *bool `json:"attached"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToBeCheckedOptions struct { - // Provides state to assert for. Asserts for input to be checked by default. This option can't be used when - // “[object Object]” is set to true. - Checked *bool `json:"checked"` - // Asserts that the element is in the indeterminate (mixed) state. Only supported for checkboxes and radio buttons. - // This option can't be true when “[object Object]” is provided. - Indeterminate *bool `json:"indeterminate"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToBeDisabledOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToBeEditableOptions struct { - Editable *bool `json:"editable"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToBeEmptyOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToBeEnabledOptions struct { - Enabled *bool `json:"enabled"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToBeFocusedOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToBeHiddenOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToBeInViewportOptions struct { - // The minimal ratio of the element to intersect viewport. If equals to `0`, then element should intersect viewport at - // any positive ratio. Defaults to `0`. - Ratio *float64 `json:"ratio"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToBeVisibleOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` - Visible *bool `json:"visible"` -} - -type LocatorAssertionsToContainClassOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToContainTextOptions struct { - // Whether to perform case-insensitive match. “[object Object]” option takes precedence over the corresponding regular - // expression flag if specified. - IgnoreCase *bool `json:"ignoreCase"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` - // Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text. - UseInnerText *bool `json:"useInnerText"` -} - -type LocatorAssertionsToHaveAccessibleDescriptionOptions struct { - // Whether to perform case-insensitive match. “[object Object]” option takes precedence over the corresponding regular - // expression flag if specified. - IgnoreCase *bool `json:"ignoreCase"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveAccessibleErrorMessageOptions struct { - // Whether to perform case-insensitive match. “[object Object]” option takes precedence over the corresponding regular - // expression flag if specified. - IgnoreCase *bool `json:"ignoreCase"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveAccessibleNameOptions struct { - // Whether to perform case-insensitive match. “[object Object]” option takes precedence over the corresponding regular - // expression flag if specified. - IgnoreCase *bool `json:"ignoreCase"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveAttributeOptions struct { - // Whether to perform case-insensitive match. “[object Object]” option takes precedence over the corresponding regular - // expression flag if specified. - IgnoreCase *bool `json:"ignoreCase"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveClassOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveCountOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveCSSOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveIdOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveJSPropertyOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveRoleOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveTextOptions struct { - // Whether to perform case-insensitive match. “[object Object]” option takes precedence over the corresponding regular - // expression flag if specified. - IgnoreCase *bool `json:"ignoreCase"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` - // Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text. - UseInnerText *bool `json:"useInnerText"` -} - -type LocatorAssertionsToHaveValueOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToHaveValuesOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type LocatorAssertionsToMatchAriaSnapshotOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type MouseClickOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // defaults to 1. See [UIEvent.Detail]. - ClickCount *int `json:"clickCount"` - // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` -} - -type MouseDblclickOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` -} - -type MouseDownOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // defaults to 1. See [UIEvent.Detail]. - ClickCount *int `json:"clickCount"` -} - -type MouseMoveOptions struct { - // Defaults to 1. Sends intermediate `mousemove` events. - Steps *int `json:"steps"` -} - -type MouseUpOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // defaults to 1. See [UIEvent.Detail]. - ClickCount *int `json:"clickCount"` -} - -type PageAddScriptTagOptions struct { - // Raw JavaScript content to be injected into frame. - Content *string `json:"content"` - // Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative - // to the current working directory. - Path *string `json:"path"` - // Script type. Use 'module' in order to load a JavaScript ES6 module. See - // [script] for more details. - // - // [script]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script - Type *string `json:"type"` - // URL of a script to be added. - URL *string `json:"url"` -} - -type PageAddStyleTagOptions struct { - // Raw CSS content to be injected into frame. - Content *string `json:"content"` - // Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the - // current working directory. - Path *string `json:"path"` - // URL of the `<link>` tag. - URL *string `json:"url"` -} - -type PageCheckOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type PageClickOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // defaults to 1. See [UIEvent.Detail]. - ClickCount *int `json:"clickCount"` - // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You - // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as - // navigating to inaccessible pages. Defaults to `false`. - // - // Deprecated: This option will default to `true` in the future. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type PageCloseOptions struct { - // The reason to be reported to the operations interrupted by the page closure. - Reason *string `json:"reason"` - // Defaults to `false`. Whether to run the - // [before unload] page handlers. - // - // [before unload]: https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload - RunBeforeUnload *bool `json:"runBeforeUnload"` -} - -type PageDblclickOptions struct { - // Defaults to `left`. - Button *MouseButton `json:"button"` - // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type PageDispatchEventOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageDragAndDropOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not - // specified, some visible point of the element is used. - SourcePosition *Position `json:"sourcePosition"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Drops on the target element at this point relative to the top-left corner of the element's padding box. If not - // specified, some visible point of the element is used. - TargetPosition *Position `json:"targetPosition"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type PageEmulateMediaOptions struct { - // Emulates [prefers-colors-scheme] - // media feature, supported values are `light` and `dark`. Passing `no-override` disables color scheme - // emulation. `no-preference` is deprecated. - // - // [prefers-colors-scheme]: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme - ColorScheme *ColorScheme `json:"colorScheme"` - // Emulates `prefers-contrast` media feature, supported values are `no-preference`, `more`. Passing - // `no-override` disables contrast emulation. - Contrast *Contrast `json:"contrast"` - // Emulates `forced-colors` media feature, supported values are `active` and `none`. Passing `no-override` - // disables forced colors emulation. - ForcedColors *ForcedColors `json:"forcedColors"` - // Changes the CSS media type of the page. The only allowed values are `screen`, `print` and `no-override`. - // Passing `no-override` disables CSS media emulation. - Media *Media `json:"media"` - // Emulates `prefers-reduced-motion` media feature, supported values are `reduce`, `no-preference`. Passing - // `no-override` disables reduced motion emulation. - ReducedMotion *ReducedMotion `json:"reducedMotion"` -} - -type PageEvalOnSelectorOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` -} - -type PageFillOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageFocusOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageFrameOptions struct { - // Frame name specified in the `iframe`'s `name` attribute. Optional. - Name *string `json:"name"` - // A glob pattern, regex pattern or predicate receiving frame's `url` as a [URL] object. Optional. - URL interface{} `json:"url"` -} - -type PageGetAttributeOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageGetByAltTextOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type PageGetByLabelOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type PageGetByPlaceholderOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type PageGetByRoleOptions struct { - // An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls. - // Learn more about [`aria-checked`]. - // - // [`aria-checked`]: https://www.w3.org/TR/wai-aria-1.2/#aria-checked - Checked *bool `json:"checked"` - // An attribute that is usually set by `aria-disabled` or `disabled`. - // **NOTE** Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about - // [`aria-disabled`]. - // - // [`aria-disabled`]: https://www.w3.org/TR/wai-aria-1.2/#aria-disabled - Disabled *bool `json:"disabled"` - // Whether “[object Object]” is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when - // “[object Object]” is a regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` - // An attribute that is usually set by `aria-expanded`. - // Learn more about [`aria-expanded`]. - // - // [`aria-expanded`]: https://www.w3.org/TR/wai-aria-1.2/#aria-expanded - Expanded *bool `json:"expanded"` - // Option that controls whether hidden elements are matched. By default, only non-hidden elements, as - // [defined by ARIA], are matched by role selector. - // Learn more about [`aria-hidden`]. - // - // [defined by ARIA]: https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion - // [`aria-hidden`]: https://www.w3.org/TR/wai-aria-1.2/#aria-hidden - IncludeHidden *bool `json:"includeHidden"` - // A number attribute that is usually present for roles `heading`, `listitem`, `row`, `treeitem`, with default values - // for `<h1>-<h6>` elements. - // Learn more about [`aria-level`]. - // - // [`aria-level`]: https://www.w3.org/TR/wai-aria-1.2/#aria-level - Level *int `json:"level"` - // Option to match the [accessible name]. By default, matching is - // case-insensitive and searches for a substring, use “[object Object]” to control this behavior. - // Learn more about [accessible name]. - // - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name - Name interface{} `json:"name"` - // An attribute that is usually set by `aria-pressed`. - // Learn more about [`aria-pressed`]. - // - // [`aria-pressed`]: https://www.w3.org/TR/wai-aria-1.2/#aria-pressed - Pressed *bool `json:"pressed"` - // An attribute that is usually set by `aria-selected`. - // Learn more about [`aria-selected`]. - // - // [`aria-selected`]: https://www.w3.org/TR/wai-aria-1.2/#aria-selected - Selected *bool `json:"selected"` -} - -type PageGetByTextOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type PageGetByTitleOptions struct { - // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - // regular expression. Note that exact match still trims whitespace. - Exact *bool `json:"exact"` -} - -type PageGoBackOptions struct { - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type PageGoForwardOptions struct { - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type PageGotoOptions struct { - // Referer header value. If provided it will take preference over the referer header value set by - // [Page.SetExtraHTTPHeaders]. - Referer *string `json:"referer"` - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type PageHoverOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type PageInnerHTMLOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageInnerTextOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageInputValueOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageIsCheckedOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageIsDisabledOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageIsEditableOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageIsEnabledOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageIsHiddenOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // - // Deprecated: This option is ignored. [Page.IsHidden] does not wait for the element to become hidden and returns immediately. - Timeout *float64 `json:"timeout"` -} - -type PageIsVisibleOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // - // Deprecated: This option is ignored. [Page.IsVisible] does not wait for the element to become visible and returns immediately. - Timeout *float64 `json:"timeout"` -} - -type PageLocatorOptions struct { - // Narrows down the results of the method to those which contain elements matching this relative locator. For example, - // `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`. - // Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not - // the document root. For example, you can find `content` that has `div` in - // `<article><content><div>Playwright</div></content></article>`. However, looking for `content` that has `article - // div` will fail, because the inner locator must be relative and should not use any elements outside the `content`. - // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. - Has Locator `json:"has"` - // Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the - // outer one. For example, `article` that does not have `div` matches `<article><span>Playwright</span></article>`. - // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. - HasNot Locator `json:"hasNot"` - // Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. - // When passed a [string], matching is case-insensitive and searches for a substring. - HasNotText interface{} `json:"hasNotText"` - // Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When - // passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches - // `<article><div>Playwright</div></article>`. - HasText interface{} `json:"hasText"` -} - -type PagePdfOptions struct { - // Display header and footer. Defaults to `false`. - DisplayHeaderFooter *bool `json:"displayHeaderFooter"` - // HTML template for the print footer. Should use the same format as the “[object Object]”. - FooterTemplate *string `json:"footerTemplate"` - // Paper format. If set, takes priority over “[object Object]” or “[object Object]” options. Defaults to 'Letter'. - Format *string `json:"format"` - // HTML template for the print header. Should be valid HTML markup with following classes used to inject printing - // values into them: - // - `date` formatted print date - // - `title` document title - // - `url` document location - // - `pageNumber` current page number - // - `totalPages` total pages in the document - HeaderTemplate *string `json:"headerTemplate"` - // Paper height, accepts values labeled with units. - Height *string `json:"height"` - // Paper orientation. Defaults to `false`. - Landscape *bool `json:"landscape"` - // Paper margins, defaults to none. - Margin *Margin `json:"margin"` - // Whether or not to embed the document outline into the PDF. Defaults to `false`. - Outline *bool `json:"outline"` - // Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages. - PageRanges *string `json:"pageRanges"` - // The file path to save the PDF to. If “[object Object]” is a relative path, then it is resolved relative to the - // current working directory. If no path is provided, the PDF won't be saved to the disk. - Path *string `json:"path"` - // Give any CSS `@page` size declared in the page priority over what is declared in “[object Object]” and - // “[object Object]” or “[object Object]” options. Defaults to `false`, which will scale the content to fit the paper - // size. - PreferCSSPageSize *bool `json:"preferCSSPageSize"` - // Print background graphics. Defaults to `false`. - PrintBackground *bool `json:"printBackground"` - // Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2. - Scale *float64 `json:"scale"` - // Whether or not to generate tagged (accessible) PDF. Defaults to `false`. - Tagged *bool `json:"tagged"` - // Paper width, accepts values labeled with units. - Width *string `json:"width"` -} - -type PagePressOptions struct { - // Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You - // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as - // navigating to inaccessible pages. Defaults to `false`. - // - // Deprecated: This option will default to `true` in the future. - NoWaitAfter *bool `json:"noWaitAfter"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageQuerySelectorOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` -} - -type PageAddLocatorHandlerOptions struct { - // By default, after calling the handler Playwright will wait until the overlay becomes hidden, and only then - // Playwright will continue with the action/assertion that triggered the handler. This option allows to opt-out of - // this behavior, so that overlay can stay visible after the handler has run. - NoWaitAfter *bool `json:"noWaitAfter"` - // Specifies the maximum number of times this handler should be called. Unlimited by default. - Times *int `json:"times"` -} - -type PageReloadOptions struct { - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type PageRouteFromHAROptions struct { - // - If set to 'abort' any request not found in the HAR file will be aborted. - // - If set to 'fallback' missing requests will be sent to the network. - // Defaults to abort. - NotFound *HarNotFound `json:"notFound"` - // If specified, updates the given HAR with the actual network information instead of serving from file. The file is - // written to disk when [BrowserContext.Close] is called. - Update *bool `json:"update"` - // Optional setting to control resource content management. If `attach` is specified, resources are persisted as - // separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file. - UpdateContent *RouteFromHarUpdateContentPolicy `json:"updateContent"` - // When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, - // cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to - // `minimal`. - UpdateMode *HarMode `json:"updateMode"` - // A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the - // pattern will be served from the HAR file. If not specified, all requests are served from the HAR file. - URL interface{} `json:"url"` -} - -type PageScreenshotOptions struct { - // When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different - // treatment depending on their duration: - // - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event. - // - infinite animations are canceled to initial state, and then played over after the screenshot. - // Defaults to `"allow"` that leaves animations untouched. - Animations *ScreenshotAnimations `json:"animations"` - // When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be - // changed. Defaults to `"hide"`. - Caret *ScreenshotCaret `json:"caret"` - // An object which specifies clipping of the resulting image. - Clip *Rect `json:"clip"` - // When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to - // `false`. - FullPage *bool `json:"fullPage"` - // Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink - // box `#FF00FF` (customized by “[object Object]”) that completely covers its bounding box. The mask is also applied - // to invisible elements, see [Matching only visible elements] to - // disable that. - // - // [Matching only visible elements]: https://playwright.dev/docs/locators#matching-only-visible-elements - Mask []Locator `json:"mask"` - // Specify the color of the overlay box for masked elements, in - // [CSS color format]. Default color is pink `#FF00FF`. - // - // [CSS color format]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value - MaskColor *string `json:"maskColor"` - // Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. - // Defaults to `false`. - OmitBackground *bool `json:"omitBackground"` - // The file path to save the image to. The screenshot type will be inferred from file extension. If “[object Object]” - // is a relative path, then it is resolved relative to the current working directory. If no path is provided, the - // image won't be saved to the disk. - Path *string `json:"path"` - // The quality of the image, between 0-100. Not applicable to `png` images. - Quality *int `json:"quality"` - // When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this - // will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so - // screenshots of high-dpi devices will be twice as large or even larger. - // Defaults to `"device"`. - Scale *ScreenshotScale `json:"scale"` - // Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make - // elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces - // the Shadow DOM and applies to the inner frames. - Style *string `json:"style"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // Specify screenshot type, defaults to `png`. - Type *ScreenshotType `json:"type"` -} - -type PageSelectOptionOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageSetCheckedOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type PageSetContentOptions struct { - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type PageSetInputFilesOptions struct { - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageTapOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores - // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to - // "Control" on Windows and Linux and to "Meta" on macOS. - Modifiers []KeyboardModifier `json:"modifiers"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard - // `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys - // are pressed. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type PageTextContentOptions struct { - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageTypeOptions struct { - // Time to wait between key presses in milliseconds. Defaults to 0. - Delay *float64 `json:"delay"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageUncheckOptions struct { - // Whether to bypass the [actionability] checks. Defaults to `false`. - // - // [actionability]: https://playwright.dev/docs/actionability - Force *bool `json:"force"` - // This option has no effect. - // - // Deprecated: This option has no effect. - NoWaitAfter *bool `json:"noWaitAfter"` - // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of - // the element. - Position *Position `json:"position"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When set, this method only performs the [actionability] checks and skips the action. Defaults - // to `false`. Useful to wait until the element is ready for the action without performing it. - // - // [actionability]: https://playwright.dev/docs/actionability - Trial *bool `json:"trial"` -} - -type PageUnrouteAllOptions struct { - // Specifies whether to wait for already running handlers and what to do if they throw errors: - // - `default` - do not wait for current handler calls (if any) to finish, if unrouted handler throws, it may - // result in unhandled error - // - `wait` - wait for current handler calls (if any) to finish - // - `ignoreErrors` - do not wait for current handler calls (if any) to finish, all errors thrown by the handlers - // after unrouting are silently caught - Behavior *UnrouteBehavior `json:"behavior"` -} - -type Size struct { - // page width in pixels. - Width int `json:"width"` - // page height in pixels. - Height int `json:"height"` -} - -type PageExpectConsoleMessageOptions struct { - // Receives the [ConsoleMessage] object and resolves to truthy value when the waiting should resolve. - Predicate func(ConsoleMessage) bool `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type PageExpectDownloadOptions struct { - // Receives the [Download] object and resolves to truthy value when the waiting should resolve. - Predicate func(Download) bool `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type PageExpectEventOptions struct { - // Receives the event data and resolves to truthy value when the waiting should resolve. - Predicate interface{} `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type PageExpectFileChooserOptions struct { - // Receives the [FileChooser] object and resolves to truthy value when the waiting should resolve. - Predicate func(FileChooser) bool `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type PageWaitForFunctionOptions struct { - // If “[object Object]” is `raf`, then “[object Object]” is constantly executed in `requestAnimationFrame` callback. - // If “[object Object]” is a number, then it is treated as an interval in milliseconds at which the function would be - // executed. Defaults to `raf`. - Polling interface{} `json:"polling"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageWaitForLoadStateOptions struct { - // Optional load state to wait for, defaults to `load`. If the state has been already reached while loading current - // document, the method resolves immediately. Can be one of: - // - `load` - wait for the `load` event to be fired. - // - `domcontentloaded` - wait for the `DOMContentLoaded` event to be fired. - // - `networkidle` - **DISCOURAGED** wait until there are no network connections for at least `500` ms. Don't use - // this method for testing, rely on web assertions to assess readiness instead. - State *LoadState `json:"state"` - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageExpectNavigationOptions struct { - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if - // the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly - // equal to the string. - URL interface{} `json:"url"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type PageExpectPopupOptions struct { - // Receives the [Page] object and resolves to truthy value when the waiting should resolve. - Predicate func(Page) bool `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type PageExpectRequestOptions struct { - // Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can - // be changed by using the [Page.SetDefaultTimeout] method. - Timeout *float64 `json:"timeout"` -} - -type PageExpectRequestFinishedOptions struct { - // Receives the [Request] object and resolves to truthy value when the waiting should resolve. - Predicate func(Request) bool `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type PageExpectResponseOptions struct { - // Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageWaitForSelectorOptions struct { - // Defaults to `visible`. Can be either: - // - `attached` - wait for element to be present in DOM. - // - `detached` - wait for element to not be present in DOM. - // - `visible` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element - // without any content or with `display:none` has an empty bounding box and is not considered visible. - // - `hidden` - wait for element to be either detached from DOM, or have an empty bounding box or - // `visibility:hidden`. This is opposite to the `visible` option. - State *WaitForSelectorState `json:"state"` - // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one - // element, the call throws an exception. - Strict *bool `json:"strict"` - // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` -} - -type PageWaitForURLOptions struct { - // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can - // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], - // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. - Timeout *float64 `json:"timeout"` - // When to consider operation succeeded, defaults to `load`. Events can be either: - // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. - // - `load` - consider operation to be finished when the `load` event is fired. - // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for - // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. - // - `commit` - consider operation to be finished when network response is received and the document started - // loading. - WaitUntil *WaitUntilState `json:"waitUntil"` -} - -type PageExpectWebSocketOptions struct { - // Receives the [WebSocket] object and resolves to truthy value when the waiting should resolve. - Predicate func(WebSocket) bool `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type PageExpectWorkerOptions struct { - // Receives the [Worker] object and resolves to truthy value when the waiting should resolve. - Predicate func(Worker) bool `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type PageWaitForEventOptions struct { - // Receives the event data and resolves to truthy value when the waiting should resolve. - Predicate interface{} `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type PageAssertionsToHaveTitleOptions struct { - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type PageAssertionsToHaveURLOptions struct { - // Whether to perform case-insensitive match. “[object Object]” option takes precedence over the corresponding regular - // expression parameter if specified. A provided predicate ignores this flag. - IgnoreCase *bool `json:"ignoreCase"` - // Time to retry the assertion for in milliseconds. Defaults to `5000`. - Timeout *float64 `json:"timeout"` -} - -type RequestSizesResult struct { - // Size of the request body (POST data payload) in bytes. Set to 0 if there was no body. - RequestBodySize int `json:"requestBodySize"` - // Total number of bytes from the start of the HTTP request message until (and including) the double CRLF before the - // body. - RequestHeadersSize int `json:"requestHeadersSize"` - // Size of the received response body (encoded) in bytes. - ResponseBodySize int `json:"responseBodySize"` - // Total number of bytes from the start of the HTTP response message until (and including) the double CRLF before the - // body. - ResponseHeadersSize int `json:"responseHeadersSize"` -} - -type RequestTiming struct { - // Request start time in milliseconds elapsed since January 1, 1970 00:00:00 UTC - StartTime float64 `json:"startTime"` - // Time immediately before the browser starts the domain name lookup for the resource. The value is given in - // milliseconds relative to `startTime`, -1 if not available. - DomainLookupStart float64 `json:"domainLookupStart"` - // Time immediately after the browser starts the domain name lookup for the resource. The value is given in - // milliseconds relative to `startTime`, -1 if not available. - DomainLookupEnd float64 `json:"domainLookupEnd"` - // Time immediately before the user agent starts establishing the connection to the server to retrieve the resource. - // The value is given in milliseconds relative to `startTime`, -1 if not available. - ConnectStart float64 `json:"connectStart"` - // Time immediately before the browser starts the handshake process to secure the current connection. The value is - // given in milliseconds relative to `startTime`, -1 if not available. - SecureConnectionStart float64 `json:"secureConnectionStart"` - // Time immediately before the user agent starts establishing the connection to the server to retrieve the resource. - // The value is given in milliseconds relative to `startTime`, -1 if not available. - ConnectEnd float64 `json:"connectEnd"` - // Time immediately before the browser starts requesting the resource from the server, cache, or local resource. The - // value is given in milliseconds relative to `startTime`, -1 if not available. - RequestStart float64 `json:"requestStart"` - // Time immediately after the browser receives the first byte of the response from the server, cache, or local - // resource. The value is given in milliseconds relative to `startTime`, -1 if not available. - ResponseStart float64 `json:"responseStart"` - // Time immediately after the browser receives the last byte of the resource or immediately before the transport - // connection is closed, whichever comes first. The value is given in milliseconds relative to `startTime`, -1 if not - // available. - ResponseEnd float64 `json:"responseEnd"` -} - -type ResponseSecurityDetailsResult struct { - // Common Name component of the Issuer field. from the certificate. This should only be used for informational - // purposes. Optional. - Issuer *string `json:"issuer"` - // The specific TLS protocol used. (e.g. `TLS 1.3`). Optional. - Protocol *string `json:"protocol"` - // Common Name component of the Subject field from the certificate. This should only be used for informational - // purposes. Optional. - SubjectName *string `json:"subjectName"` - // Unix timestamp (in seconds) specifying when this cert becomes valid. Optional. - ValidFrom *float64 `json:"validFrom"` - // Unix timestamp (in seconds) specifying when this cert becomes invalid. Optional. - ValidTo *float64 `json:"validTo"` -} - -type ResponseServerAddrResult struct { - // IPv4 or IPV6 address of the server. - IpAddress string `json:"ipAddress"` - Port int `json:"port"` -} - -type RouteContinueOptions struct { - // If set changes the request HTTP headers. Header values will be converted to a string. - Headers map[string]string `json:"headers"` - // If set changes the request method (e.g. GET or POST). - Method *string `json:"method"` - // If set changes the post data of request. - PostData interface{} `json:"postData"` - // If set changes the request URL. New URL must have same protocol as original one. - URL *string `json:"url"` -} - -type RouteFallbackOptions struct { - // If set changes the request HTTP headers. Header values will be converted to a string. - Headers map[string]string `json:"headers"` - // If set changes the request method (e.g. GET or POST). - Method *string `json:"method"` - // If set changes the post data of request. - PostData interface{} `json:"postData"` - // If set changes the request URL. New URL must have same protocol as original one. Changing the URL won't affect the - // route matching, all the routes are matched using the original request URL. - URL *string `json:"url"` -} - -type RouteFetchOptions struct { - // If set changes the request HTTP headers. Header values will be converted to a string. - Headers map[string]string `json:"headers"` - // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is - // exceeded. Defaults to `20`. Pass `0` to not follow redirects. - MaxRedirects *int `json:"maxRedirects"` - // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not - // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. - MaxRetries *int `json:"maxRetries"` - // If set changes the request method (e.g. GET or POST). - Method *string `json:"method"` - // If set changes the post data of request. - PostData interface{} `json:"postData"` - // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - Timeout *float64 `json:"timeout"` - // If set changes the request URL. New URL must have same protocol as original one. - URL *string `json:"url"` -} - -type RouteFulfillOptions struct { - // Response body. - Body interface{} `json:"body"` - // If set, equals to setting `Content-Type` response header. - ContentType *string `json:"contentType"` - // Response headers. Header values will be converted to a string. - Headers map[string]string `json:"headers"` - // File path to respond with. The content type will be inferred from file extension. If `path` is a relative path, - // then it is resolved relative to the current working directory. - Path *string `json:"path"` - // [APIResponse] to fulfill route's request with. Individual fields of the response (such as headers) can be - // overridden using fulfill options. - Response APIResponse `json:"response"` - // Response status code, defaults to `200`. - Status *int `json:"status"` -} - -type SelectorsRegisterOptions struct { - // Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same - // DOM, but not any JavaScript objects from the frame's scripts. Defaults to `false`. Note that running as a content - // script is not guaranteed when this engine is used together with other registered engines. - ContentScript *bool `json:"contentScript"` -} - -type TracingStartOptions struct { - // If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the - // “[object Object]” directory specified in [BrowserType.Launch]. To specify the final trace zip file name, you need - // to pass `path` option to [Tracing.Stop] instead. - Name *string `json:"name"` - // Whether to capture screenshots during tracing. Screenshots are used to build a timeline preview. - Screenshots *bool `json:"screenshots"` - // If this option is true tracing will - // - capture DOM snapshot on every action - // - record network activity - Snapshots *bool `json:"snapshots"` - // Whether to include source files for trace actions. - Sources *bool `json:"sources"` - // Trace name to be shown in the Trace Viewer. - Title *string `json:"title"` -} - -type TracingStartChunkOptions struct { - // If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the - // “[object Object]” directory specified in [BrowserType.Launch]. To specify the final trace zip file name, you need - // to pass `path` option to [Tracing.StopChunk] instead. - Name *string `json:"name"` - // Trace name to be shown in the Trace Viewer. - Title *string `json:"title"` -} - -type TracingGroupOptions struct { - // Specifies a custom location for the group to be shown in the trace viewer. Defaults to the location of the - // [Tracing.Group] call. - Location *TracingGroupOptionsLocation `json:"location"` -} - -type WebSocketExpectEventOptions struct { - // Receives the event data and resolves to truthy value when the waiting should resolve. - Predicate interface{} `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type WebSocketWaitForEventOptions struct { - // Receives the event data and resolves to truthy value when the waiting should resolve. - Predicate interface{} `json:"predicate"` - // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The - // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. - Timeout *float64 `json:"timeout"` -} - -type WebSocketRouteCloseOptions struct { - // Optional [close code]. - // - // [close code]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close#code - Code *int `json:"code"` - // Optional [close reason]. - // - // [close reason]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close#reason - Reason *string `json:"reason"` -} - -type ClientCertificate struct { - // Exact origin that the certificate is valid for. Origin includes `https` protocol, a hostname and optionally a port. - Origin string `json:"origin"` - // Path to the file with the certificate in PEM format. - CertPath *string `json:"certPath"` - // Direct value of the certificate in PEM format. - Cert []byte `json:"cert"` - // Path to the file with the private key in PEM format. - KeyPath *string `json:"keyPath"` - // Direct value of the private key in PEM format. - Key []byte `json:"key"` - // Path to the PFX or PKCS12 encoded private key and certificate chain. - PfxPath *string `json:"pfxPath"` - // Direct value of the PFX or PKCS12 encoded private key and certificate chain. - Pfx []byte `json:"pfx"` - // Passphrase for the private key (PEM or PFX). - Passphrase *string `json:"passphrase"` -} - -type HttpCredentials struct { - Username string `json:"username"` - Password string `json:"password"` - // Restrain sending http credentials on specific origin (scheme://host:port). - Origin *string `json:"origin"` - // This option only applies to the requests sent from corresponding [APIRequestContext] and does not affect requests - // sent from the browser. `always` - `Authorization` header with basic authentication credentials will be sent with - // the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response with - // `WWW-Authenticate` header is received. Defaults to `unauthorized`. - Send *HttpCredentialsSend `json:"send"` -} - -type Proxy struct { - // Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example `http://myproxy.com:3128` or - // `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy. - Server string `json:"server"` - // Optional comma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`. - Bypass *string `json:"bypass"` - // Optional username to use if HTTP proxy requires authentication. - Username *string `json:"username"` - // Optional password to use if HTTP proxy requires authentication. - Password *string `json:"password"` -} - -type Origin struct { - Origin string `json:"origin"` - LocalStorage []NameValue `json:"localStorage"` -} - -type RecordVideo struct { - // Path to the directory to put videos into. - Dir string `json:"dir"` - // Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to - // fit into 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of - // each page will be scaled down if necessary to fit the specified size. - Size *Size `json:"size"` -} - -type OptionalStorageState struct { - // Cookies to set for context - Cookies []OptionalCookie `json:"cookies"` - // localStorage to set for context - Origins []Origin `json:"origins"` -} - -type Position struct { - X float64 `json:"x"` - Y float64 `json:"y"` -} - -type Margin struct { - // Top margin, accepts values labeled with units. Defaults to `0`. - Top *string `json:"top"` - // Right margin, accepts values labeled with units. Defaults to `0`. - Right *string `json:"right"` - // Bottom margin, accepts values labeled with units. Defaults to `0`. - Bottom *string `json:"bottom"` - // Left margin, accepts values labeled with units. Defaults to `0`. - Left *string `json:"left"` -} - -type TracingGroupOptionsLocation struct { - File string `json:"file"` - Line *int `json:"line"` - Column *int `json:"column"` -} diff --git a/vendor/github.com/playwright-community/playwright-go/glob.go b/vendor/github.com/playwright-community/playwright-go/glob.go deleted file mode 100644 index 77deba3..0000000 --- a/vendor/github.com/playwright-community/playwright-go/glob.go +++ /dev/null @@ -1,170 +0,0 @@ -package playwright - -import ( - "net/url" - "regexp" - "strconv" - "strings" -) - -var escapedChars = map[rune]bool{ - '$': true, - '^': true, - '+': true, - '.': true, - '*': true, - '(': true, - ')': true, - '|': true, - '\\': true, - '?': true, - '{': true, - '}': true, - '[': true, - ']': true, -} - -func globMustToRegex(glob string) *regexp.Regexp { - tokens := []string{"^"} - inGroup := false - - for i := 0; i < len(glob); i++ { - c := rune(glob[i]) - if c == '\\' && i+1 < len(glob) { - char := rune(glob[i+1]) - if _, ok := escapedChars[char]; ok { - tokens = append(tokens, "\\"+string(char)) - } else { - tokens = append(tokens, string(char)) - } - i++ - } else if c == '*' { - beforeDeep := rune(0) - if i > 0 { - beforeDeep = rune(glob[i-1]) - } - starCount := 1 - for i+1 < len(glob) && glob[i+1] == '*' { - starCount++ - i++ - } - afterDeep := rune(0) - if i+1 < len(glob) { - afterDeep = rune(glob[i+1]) - } - isDeep := starCount > 1 && (beforeDeep == '/' || beforeDeep == 0) && (afterDeep == '/' || afterDeep == 0) - if isDeep { - tokens = append(tokens, "((?:[^/]*(?:/|$))*)") - i++ - } else { - tokens = append(tokens, "([^/]*)") - } - } else { - switch c { - case '{': - inGroup = true - tokens = append(tokens, "(") - case '}': - inGroup = false - tokens = append(tokens, ")") - case ',': - if inGroup { - tokens = append(tokens, "|") - } else { - tokens = append(tokens, "\\"+string(c)) - } - default: - if _, ok := escapedChars[c]; ok { - tokens = append(tokens, "\\"+string(c)) - } else { - tokens = append(tokens, string(c)) - } - } - } - } - - tokens = append(tokens, "$") - return regexp.MustCompile(strings.Join(tokens, "")) -} - -func resolveGlobToRegex(baseURL *string, glob string, isWebSocketUrl bool) *regexp.Regexp { - if isWebSocketUrl { - baseURL = toWebSocketBaseURL(baseURL) - } - glob = resolveGlobBase(baseURL, glob) - return globMustToRegex(glob) -} - -func resolveGlobBase(baseURL *string, match string) string { - if strings.HasPrefix(match, "*") { - return match - } - - tokenMap := make(map[string]string) - mapToken := func(original string, replacement string) string { - if len(original) == 0 { - return "" - } - tokenMap[replacement] = original - return replacement - } - // Escaped `\\?` behaves the same as `?` in our glob patterns. - match = strings.ReplaceAll(match, `\\?`, "?") - // Glob symbols may be escaped in the URL and some of them such as ? affect resolution, - // so we replace them with safe components first. - relativePath := strings.Split(match, "/") - for i, token := range relativePath { - if token == "." || token == ".." || token == "" { - continue - } - // Handle special case of http*://, note that the new schema has to be - // a web schema so that slashes are properly inserted after domain. - if i == 0 && strings.HasSuffix(token, ":") { - relativePath[i] = mapToken(token, "http:") - } else { - questionIndex := strings.Index(token, "?") - if questionIndex == -1 { - relativePath[i] = mapToken(token, "$_"+strconv.Itoa(i)+"_$") - } else { - newPrefix := mapToken(token[:questionIndex], "$_"+strconv.Itoa(i)+"_$") - newSuffix := mapToken(token[questionIndex:], "?$"+strconv.Itoa(i)+"_$") - relativePath[i] = newPrefix + newSuffix - } - } - } - resolved := constructURLBasedOnBaseURL(baseURL, strings.Join(relativePath, "/")) - for token, original := range tokenMap { - resolved = strings.ReplaceAll(resolved, token, original) - } - return resolved -} - -func constructURLBasedOnBaseURL(baseURL *string, givenURL string) string { - u, err := url.Parse(givenURL) - if err != nil { - return givenURL - } - if baseURL != nil { - base, err := url.Parse(*baseURL) - if err != nil { - return givenURL - } - u = base.ResolveReference(u) - } - if u.Path == "" { // In Node.js, new URL('http://localhost') returns 'http://localhost/'. - u.Path = "/" - } - return u.String() -} - -func toWebSocketBaseURL(baseURL *string) *string { - if baseURL == nil { - return nil - } - - // Allow http(s) baseURL to match ws(s) urls. - re := regexp.MustCompile(`(?m)^http(s?://)`) - wsBaseURL := re.ReplaceAllString(*baseURL, "ws$1") - - return &wsBaseURL -} diff --git a/vendor/github.com/playwright-community/playwright-go/har_router.go b/vendor/github.com/playwright-community/playwright-go/har_router.go deleted file mode 100644 index 0c95d53..0000000 --- a/vendor/github.com/playwright-community/playwright-go/har_router.go +++ /dev/null @@ -1,110 +0,0 @@ -package playwright - -import ( - "errors" -) - -type harRouter struct { - localUtils *localUtilsImpl - harId string - notFoundAction HarNotFound - urlOrPredicate interface{} - err error -} - -func (r *harRouter) addContextRoute(context BrowserContext) error { - if r.err != nil { - return r.err - } - err := context.Route(r.urlOrPredicate, func(route Route) { - err := r.handle(route) - if err != nil { - logger.Error("Error handling context route", "error", err) - } - }) - if err != nil { - return err - } - return r.err -} - -func (r *harRouter) addPageRoute(page Page) error { - if r.err != nil { - return r.err - } - err := page.Route(r.urlOrPredicate, func(route Route) { - err := r.handle(route) - if err != nil { - logger.Error("Error handling page route", "error", err) - } - }) - if err != nil { - return err - } - return r.err -} - -func (r *harRouter) dispose() { - go r.localUtils.HarClose(r.harId) -} - -func (r *harRouter) handle(route Route) error { - if r.err != nil { - return r.err - } - request := route.Request() - postData, err := request.PostDataBuffer() - if err != nil { - return err - } - response, err := r.localUtils.HarLookup(harLookupOptions{ - HarId: r.harId, - URL: request.URL(), - Method: request.Method(), - Headers: request.Headers(), - IsNavigationRequest: request.IsNavigationRequest(), - PostData: postData, - }) - if err != nil { - return err - } - switch response.Action { - case "redirect": - if response.RedirectURL == nil { - return errors.New("redirect url is null") - } - return route.(*routeImpl).redirectedNavigationRequest(*response.RedirectURL) - case "fulfill": - if response.Body == nil { - return errors.New("fulfill body is null") - } - return route.Fulfill(RouteFulfillOptions{ - Body: *response.Body, - Status: response.Status, - Headers: deserializeNameAndValueToMap(response.Headers), - }) - case "error": - logger.Error("har action error", "error", *response.Message) - fallthrough - case "noentry": - } - if r.notFoundAction == *HarNotFoundAbort { - return route.Abort() - } - return route.Fallback() -} - -func newHarRouter(localUtils *localUtilsImpl, file string, notFoundAction HarNotFound, urlOrPredicate interface{}) *harRouter { - harId, err := localUtils.HarOpen(file) - var url interface{} = "**/*" - if urlOrPredicate != nil { - url = urlOrPredicate - } - return &harRouter{ - localUtils: localUtils, - harId: harId, - notFoundAction: notFoundAction, - urlOrPredicate: url, - err: err, - } -} diff --git a/vendor/github.com/playwright-community/playwright-go/helpers.go b/vendor/github.com/playwright-community/playwright-go/helpers.go deleted file mode 100644 index b2244f1..0000000 --- a/vendor/github.com/playwright-community/playwright-go/helpers.go +++ /dev/null @@ -1,628 +0,0 @@ -package playwright - -import ( - "errors" - "fmt" - "reflect" - "regexp" - "strings" - "sync" - "sync/atomic" - - mapset "github.com/deckarep/golang-set/v2" -) - -type ( - routeHandler = func(Route) -) - -func skipFieldSerialization(val reflect.Value) bool { - typ := val.Type() - return (typ.Kind() == reflect.Ptr || - typ.Kind() == reflect.Interface || - typ.Kind() == reflect.Map || - typ.Kind() == reflect.Slice) && val.IsNil() || (val.Kind() == reflect.Interface && val.Elem().Kind() == reflect.Ptr && val.Elem().IsNil()) -} - -func transformStructValues(in interface{}) interface{} { - v := reflect.ValueOf(in) - if v.Kind() == reflect.Ptr { - v = v.Elem() - } - if _, ok := in.(*channel); ok { - return in - } - if v.Kind() == reflect.Map || v.Kind() == reflect.Struct { - return transformStructIntoMapIfNeeded(in) - } - if v.Kind() == reflect.Slice { - outSlice := []interface{}{} - for i := 0; i < v.Len(); i++ { - if !skipFieldSerialization(v.Index(i)) { - outSlice = append(outSlice, transformStructValues(v.Index(i).Interface())) - } - } - return outSlice - } - if v.Interface() == Null() || (v.Kind() == reflect.String && v.String() == Null().(string)) { - return "null" - } - return in -} - -func transformStructIntoMapIfNeeded(inStruct interface{}) map[string]interface{} { - out := make(map[string]interface{}) - v := reflect.ValueOf(inStruct) - if v.Kind() == reflect.Ptr { - v = v.Elem() - } - typ := v.Type() - if v.Kind() == reflect.Struct { - // Merge into the base map by the JSON struct tag - for i := 0; i < v.NumField(); i++ { - fi := typ.Field(i) - // Skip the values when the field is a pointer (like *string) and nil. - if fi.IsExported() && !skipFieldSerialization(v.Field(i)) { - // We use the JSON struct fields for getting the original names - // out of the field. - tagv := fi.Tag.Get("json") - key := strings.Split(tagv, ",")[0] - if key == "" { - key = fi.Name - } - out[key] = transformStructValues(v.Field(i).Interface()) - } - } - } else if v.Kind() == reflect.Map { - // Merge into the base map - for _, key := range v.MapKeys() { - if !skipFieldSerialization(v.MapIndex(key)) { - out[key.String()] = transformStructValues(v.MapIndex(key).Interface()) - } - } - } - return out -} - -// transformOptions handles the parameter data transformation -func transformOptions(options ...interface{}) map[string]interface{} { - var base map[string]interface{} - var option interface{} - // Case 1: No options are given - if len(options) == 0 { - return make(map[string]interface{}) - } - if len(options) == 1 { - // Case 2: a single value (either struct or map) is given. - base = make(map[string]interface{}) - option = options[0] - } else if len(options) == 2 { - // Case 3: two values are given. The first one needs to be transformed - // to a map, the sencond one will be then get merged into the first - // base map. - if reflect.ValueOf(options[0]).Kind() != reflect.Map { - base = transformOptions(options[0]) - } else { - base = transformStructIntoMapIfNeeded(options[0]) - } - option = options[1] - } - v := reflect.ValueOf(option) - if v.Kind() == reflect.Slice { - if v.Len() == 0 { - return base - } - option = v.Index(0).Interface() - } - - if option == nil { - return base - } - v = reflect.ValueOf(option) - - if v.Kind() == reflect.Ptr { - v = v.Elem() - } - - optionMap := transformStructIntoMapIfNeeded(v.Interface()) - for key, value := range optionMap { - base[key] = value - } - return base -} - -func remapValue(inMapValue reflect.Value, outStructValue reflect.Value) { - switch outStructValue.Type().Kind() { - case reflect.Bool: - outStructValue.SetBool(inMapValue.Bool()) - case reflect.String: - outStructValue.SetString(inMapValue.String()) - case reflect.Float64: - outStructValue.SetFloat(inMapValue.Float()) - case reflect.Int: - outStructValue.SetInt(int64(inMapValue.Float())) - case reflect.Slice: - outStructValue.Set(reflect.MakeSlice(outStructValue.Type(), inMapValue.Len(), inMapValue.Cap())) - for i := 0; i < inMapValue.Len(); i++ { - remapValue(inMapValue.Index(i).Elem(), outStructValue.Index(i)) - } - case reflect.Struct: - structTyp := outStructValue.Type() - for i := 0; i < outStructValue.NumField(); i++ { - fi := structTyp.Field(i) - key := strings.Split(fi.Tag.Get("json"), ",")[0] - structField := outStructValue.Field(i) - structFieldDeref := outStructValue.Field(i) - if structField.Type().Kind() == reflect.Ptr { - structField.Set(reflect.New(structField.Type().Elem())) - structFieldDeref = structField.Elem() - } - for _, e := range inMapValue.MapKeys() { - if key == e.String() { - value := inMapValue.MapIndex(e) - remapValue(value.Elem(), structFieldDeref) - } - } - } - default: - panic(inMapValue.Interface()) - } -} - -func remapMapToStruct(inputMap interface{}, outStruct interface{}) { - remapValue(reflect.ValueOf(inputMap), reflect.ValueOf(outStruct).Elem()) -} - -type urlMatcher struct { - raw interface{} - pattern *regexp.Regexp - matchFn func(url string) bool -} - -func newURLMatcher(urlOrPredicate interface{}, baseURL *string, isWsUrl ...bool) *urlMatcher { - switch v := urlOrPredicate.(type) { - case *regexp.Regexp: - return &urlMatcher{pattern: v, raw: urlOrPredicate} - case string: - return &urlMatcher{ - pattern: resolveGlobToRegex(baseURL, v, len(isWsUrl) > 0 && isWsUrl[0]), - raw: urlOrPredicate, - } - } - fn, ok := urlOrPredicate.(func(string) bool) - if ok { - return &urlMatcher{ - matchFn: fn, - raw: urlOrPredicate, - } - } - panic(fmt.Errorf("invalid urlOrPredicate: %v", urlOrPredicate)) -} - -func (u *urlMatcher) Matches(url string) bool { - if u.matchFn != nil { - return u.matchFn(url) - } - if u.pattern != nil { - return u.pattern.MatchString(url) - } - return false -} - -// SameWith compares String() if urlOrPredicate is *regexp.Regexp -func (u *urlMatcher) SameWith(urlOrPredicate interface{}) bool { - switch v := urlOrPredicate.(type) { - case *regexp.Regexp: - return u.pattern.String() == v.String() - default: - return u.raw == urlOrPredicate - } -} - -type routeHandlerInvocation struct { - route Route - complete chan bool -} - -type routeHandlerEntry struct { - matcher *urlMatcher - handler routeHandler - times int - count int32 - ignoreErrors *atomic.Bool - activeInvocations mapset.Set[*routeHandlerInvocation] -} - -func (r *routeHandlerEntry) Matches(url string) bool { - return r.matcher.Matches(url) -} - -func (r *routeHandlerEntry) Handle(route Route) chan bool { - handlerInvocation := &routeHandlerInvocation{ - route: route, - complete: make(chan bool, 1), - } - r.activeInvocations.Add(handlerInvocation) - - defer func() { - handlerInvocation.complete <- true - r.activeInvocations.Remove(handlerInvocation) - }() - defer func() { - // If the handler was stopped (without waiting for completion), we ignore all exceptions. - if r.ignoreErrors.Load() { - _ = recover() - route.(*routeImpl).reportHandled(false) - } else { - e := recover() - if e != nil { - err, ok := e.(error) - if ok && errors.Is(err, ErrTargetClosed) { - panic(fmt.Errorf("\"%w\" while running route callback.\nConsider awaiting `page.UnrouteAll(playwright.PageUnrouteAllOptions{Behavior: playwright.UnrouteBehaviorIgnoreErrors})`\nbefore the end of the test to ignore remaining routes in flight.", err)) - } - panic(e) - } - } - }() - - return r.handleInternal(route) -} - -func (r *routeHandlerEntry) Stop(behavior string) { - // When a handler is manually unrouted or its page/context is closed we either - // - wait for the current handler invocations to finish - // - or do not wait, if the user opted out of it, but swallow all exceptions - // that happen after the unroute/close. - if behavior == string(*UnrouteBehaviorIgnoreErrors) { - r.ignoreErrors.Store(true) - } else { - wg := &sync.WaitGroup{} - r.activeInvocations.Each(func(activation *routeHandlerInvocation) bool { - if !activation.route.(*routeImpl).didThrow { - wg.Add(1) - go func(complete chan bool) { - <-complete - wg.Done() - }(activation.complete) - } - return false - }) - wg.Wait() - } -} - -func (r *routeHandlerEntry) handleInternal(route Route) chan bool { - handled := route.(*routeImpl).startHandling() - atomic.AddInt32(&r.count, 1) - r.handler(route) - return handled -} - -func (r *routeHandlerEntry) WillExceed() bool { - if r.times == 0 { - return false - } - return int(atomic.LoadInt32(&r.count)+1) >= r.times -} - -func newRouteHandlerEntry(matcher *urlMatcher, handler routeHandler, times ...int) *routeHandlerEntry { - n := 0 - if len(times) > 0 { - n = times[0] - } - return &routeHandlerEntry{ - matcher: matcher, - handler: handler, - times: n, - count: 0, - ignoreErrors: &atomic.Bool{}, - activeInvocations: mapset.NewSet[*routeHandlerInvocation](), - } -} - -func prepareInterceptionPatterns(handlers []*routeHandlerEntry) []map[string]interface{} { - patterns := []map[string]interface{}{} - all := false - for _, h := range handlers { - switch h.matcher.raw.(type) { - case *regexp.Regexp: - pattern, flags := convertRegexp(h.matcher.raw.(*regexp.Regexp)) - patterns = append(patterns, map[string]interface{}{ - "regexSource": pattern, - "regexFlags": flags, - }) - case string: - patterns = append(patterns, map[string]interface{}{ - "glob": h.matcher.raw.(string), - }) - default: - all = true - } - } - if all { - return []map[string]interface{}{ - { - "glob": "**/*", - }, - } - } - return patterns -} - -const defaultTimeout = 30 * 1000 - -type timeoutSettings struct { - sync.RWMutex - parent *timeoutSettings - defaultTimeout *float64 - defaultNavigationTimeout *float64 -} - -func (t *timeoutSettings) SetDefaultTimeout(timeout *float64) { - t.Lock() - defer t.Unlock() - t.defaultTimeout = timeout -} - -func (t *timeoutSettings) DefaultTimeout() *float64 { - t.RLock() - defer t.RUnlock() - return t.defaultTimeout -} - -func (t *timeoutSettings) Timeout(timeout ...float64) float64 { - t.RLock() - defer t.RUnlock() - if len(timeout) == 1 { - return timeout[0] - } - if t.defaultTimeout != nil { - return *t.defaultTimeout - } - if t.parent != nil { - return t.parent.Timeout() - } - return defaultTimeout -} - -func (t *timeoutSettings) DefaultNavigationTimeout() *float64 { - t.RLock() - defer t.RUnlock() - return t.defaultNavigationTimeout -} - -func (t *timeoutSettings) SetDefaultNavigationTimeout(navigationTimeout *float64) { - t.Lock() - defer t.Unlock() - t.defaultNavigationTimeout = navigationTimeout -} - -func (t *timeoutSettings) NavigationTimeout() float64 { - t.RLock() - defer t.RUnlock() - if t.defaultNavigationTimeout != nil { - return *t.defaultNavigationTimeout - } - if t.parent != nil { - return t.parent.NavigationTimeout() - } - return defaultTimeout -} - -func newTimeoutSettings(parent *timeoutSettings) *timeoutSettings { - return &timeoutSettings{ - parent: parent, - defaultTimeout: nil, - defaultNavigationTimeout: nil, - } -} - -// SelectOptionValues is the option struct for ElementHandle.Select() etc. -type SelectOptionValues struct { - ValuesOrLabels *[]string - Values *[]string - Indexes *[]int - Labels *[]string - Elements *[]ElementHandle -} - -func convertSelectOptionSet(values SelectOptionValues) map[string]interface{} { - out := make(map[string]interface{}) - if values == (SelectOptionValues{}) { - return out - } - - var o []map[string]interface{} - if values.ValuesOrLabels != nil { - for _, v := range *values.ValuesOrLabels { - m := map[string]interface{}{"valueOrLabel": v} - o = append(o, m) - } - } - if values.Values != nil { - for _, v := range *values.Values { - m := map[string]interface{}{"value": v} - o = append(o, m) - } - } - if values.Indexes != nil { - for _, i := range *values.Indexes { - m := map[string]interface{}{"index": i} - o = append(o, m) - } - } - if values.Labels != nil { - for _, l := range *values.Labels { - m := map[string]interface{}{"label": l} - o = append(o, m) - } - } - if o != nil { - out["options"] = o - } - - var e []*channel - if values.Elements != nil { - for _, eh := range *values.Elements { - e = append(e, eh.(*elementHandleImpl).channel) - } - } - if e != nil { - out["elements"] = e - } - - return out -} - -func unroute(inRoutes []*routeHandlerEntry, url interface{}, handlers ...routeHandler) ([]*routeHandlerEntry, []*routeHandlerEntry, error) { - var handler routeHandler - if len(handlers) == 1 { - handler = handlers[0] - } - handlerPtr := reflect.ValueOf(handler).Pointer() - - removed := make([]*routeHandlerEntry, 0) - remaining := make([]*routeHandlerEntry, 0) - - for _, route := range inRoutes { - routeHandlerPtr := reflect.ValueOf(route.handler).Pointer() - // note: compare regex expression if url is a regexp, not pointer - if !route.matcher.SameWith(url) || - (handler != nil && routeHandlerPtr != handlerPtr) { - remaining = append(remaining, route) - } else { - removed = append(removed, route) - } - } - - return removed, remaining, nil -} - -func serializeMapToNameAndValue(headers map[string]string) []map[string]string { - serialized := make([]map[string]string, 0) - for name, value := range headers { - serialized = append(serialized, map[string]string{ - "name": name, - "value": value, - }) - } - return serialized -} - -// assignStructFields assigns fields from src to dest, -// -// omitExtra determines whether to omit src's extra fields -func assignStructFields(dest, src interface{}, omitExtra bool) error { - destValue := reflect.ValueOf(dest) - if destValue.Kind() != reflect.Ptr || destValue.IsNil() { - return fmt.Errorf("dest must be a non-nil pointer") - } - destValue = destValue.Elem() - if destValue.Kind() != reflect.Struct { - return fmt.Errorf("dest must be a struct") - } - - srcValue := reflect.ValueOf(src) - if srcValue.Kind() == reflect.Ptr { - srcValue = srcValue.Elem() - } - if srcValue.Kind() != reflect.Struct { - return fmt.Errorf("src must be a struct") - } - - for i := 0; i < destValue.NumField(); i++ { - destField := destValue.Field(i) - destFieldType := destField.Type() - destFieldName := destValue.Type().Field(i).Name - - if srcField := srcValue.FieldByName(destFieldName); srcField.IsValid() && srcField.Type() != destFieldType { - return fmt.Errorf("mismatched field type for field %s", destFieldName) - } else if srcField.IsValid() { - destField.Set(srcField) - } - } - - if !omitExtra { - for i := 0; i < srcValue.NumField(); i++ { - srcFieldName := srcValue.Type().Field(i).Name - - if destField := destValue.FieldByName(srcFieldName); !destField.IsValid() { - return fmt.Errorf("extra field %s in src", srcFieldName) - } - } - } - - return nil -} - -func deserializeNameAndValueToMap(headersArray []map[string]string) map[string]string { - unserialized := make(map[string]string) - for _, item := range headersArray { - unserialized[item["name"]] = item["value"] - } - return unserialized -} - -type recordHarOptions struct { - Path string `json:"path"` - Content *HarContentPolicy `json:"content,omitempty"` - Mode *HarMode `json:"mode,omitempty"` - UrlGlob *string `json:"urlGlob,omitempty"` - UrlRegexSource *string `json:"urlRegexSource,omitempty"` - UrlRegexFlags *string `json:"urlRegexFlags,omitempty"` -} - -type recordHarInputOptions struct { - Path string - URL interface{} - Mode *HarMode - Content *HarContentPolicy - OmitContent *bool -} - -type harRecordingMetadata struct { - Path string - Content *HarContentPolicy -} - -func prepareRecordHarOptions(option recordHarInputOptions) recordHarOptions { - out := recordHarOptions{ - Path: option.Path, - } - if option.URL != nil { - switch option.URL.(type) { - case *regexp.Regexp: - pattern, flags := convertRegexp(option.URL.(*regexp.Regexp)) - out.UrlRegexSource = String(pattern) - out.UrlRegexFlags = String(flags) - case string: - out.UrlGlob = String(option.URL.(string)) - } - } - if option.Mode != nil { - out.Mode = option.Mode - } - if option.Content != nil { - out.Content = option.Content - } else if option.OmitContent != nil && *option.OmitContent { - out.Content = HarContentPolicyOmit - } - return out -} - -type safeValue[T any] struct { - sync.Mutex - v T -} - -func (s *safeValue[T]) Set(v T) { - s.Lock() - defer s.Unlock() - s.v = v -} - -func (s *safeValue[T]) Get() T { - s.Lock() - defer s.Unlock() - return s.v -} diff --git a/vendor/github.com/playwright-community/playwright-go/input.go b/vendor/github.com/playwright-community/playwright-go/input.go deleted file mode 100644 index d6e4ba4..0000000 --- a/vendor/github.com/playwright-community/playwright-go/input.go +++ /dev/null @@ -1,117 +0,0 @@ -package playwright - -type mouseImpl struct { - channel *channel -} - -func newMouse(channel *channel) *mouseImpl { - return &mouseImpl{ - channel: channel, - } -} - -func (m *mouseImpl) Move(x float64, y float64, options ...MouseMoveOptions) error { - _, err := m.channel.Send("mouseMove", map[string]interface{}{ - "x": x, - "y": y, - }, options) - return err -} - -func (m *mouseImpl) Down(options ...MouseDownOptions) error { - _, err := m.channel.Send("mouseDown", options) - return err -} - -func (m *mouseImpl) Up(options ...MouseUpOptions) error { - _, err := m.channel.Send("mouseUp", options) - return err -} - -func (m *mouseImpl) Click(x, y float64, options ...MouseClickOptions) error { - _, err := m.channel.Send("mouseClick", map[string]interface{}{ - "x": x, - "y": y, - }, options) - return err -} - -func (m *mouseImpl) Dblclick(x, y float64, options ...MouseDblclickOptions) error { - var option MouseDblclickOptions - if len(options) == 1 { - option = options[0] - } - return m.Click(x, y, MouseClickOptions{ - ClickCount: Int(2), - Button: option.Button, - Delay: option.Delay, - }) -} - -func (m *mouseImpl) Wheel(deltaX, deltaY float64) error { - _, err := m.channel.Send("mouseWheel", map[string]interface{}{ - "deltaX": deltaX, - "deltaY": deltaY, - }) - return err -} - -type keyboardImpl struct { - channel *channel -} - -func newKeyboard(channel *channel) *keyboardImpl { - return &keyboardImpl{ - channel: channel, - } -} - -func (m *keyboardImpl) Down(key string) error { - _, err := m.channel.Send("keyboardDown", map[string]interface{}{ - "key": key, - }) - return err -} - -func (m *keyboardImpl) Up(key string) error { - _, err := m.channel.Send("keyboardUp", map[string]interface{}{ - "key": key, - }) - return err -} - -func (m *keyboardImpl) InsertText(text string) error { - _, err := m.channel.Send("keyboardInsertText", map[string]interface{}{ - "text": text, - }) - return err -} - -func (m *keyboardImpl) Type(text string, options ...KeyboardTypeOptions) error { - _, err := m.channel.Send("keyboardInsertText", map[string]interface{}{ - "text": text, - }, options) - return err -} - -func (m *keyboardImpl) Press(key string, options ...KeyboardPressOptions) error { - _, err := m.channel.Send("keyboardPress", map[string]interface{}{ - "key": key, - }, options) - return err -} - -type touchscreenImpl struct { - channel *channel -} - -func newTouchscreen(channel *channel) *touchscreenImpl { - return &touchscreenImpl{ - channel: channel, - } -} - -func (t *touchscreenImpl) Tap(x int, y int) error { - _, err := t.channel.Send("touchscreenTap", map[string]interface{}{"x": x, "y": y}) - return err -} diff --git a/vendor/github.com/playwright-community/playwright-go/input_files_helper.go b/vendor/github.com/playwright-community/playwright-go/input_files_helper.go deleted file mode 100644 index 3318cb5..0000000 --- a/vendor/github.com/playwright-community/playwright-go/input_files_helper.go +++ /dev/null @@ -1,202 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "errors" - "fmt" - "os" - "path/filepath" -) - -const fileSizeLimitInBytes = 50 * 1024 * 1024 - -var ErrInputFilesSizeExceeded = errors.New("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.") - -type inputFiles struct { - Selector *string `json:"selector,omitempty"` - Streams []*channel `json:"streams,omitempty"` // writableStream - LocalPaths []string `json:"localPaths,omitempty"` - Payloads []map[string]string `json:"payloads,omitempty"` - LocalDirectory *string `json:"localDirectory,omitempty"` - DirectoryStream *channel `json:"directoryStream,omitempty"` -} - -type fileItem struct { - LastModifiedMs *int64 `json:"lastModifiedMs,omitempty"` - Name string `json:"name"` -} - -// convertInputFiles converts files to proper format for Playwright -// -// - files should be one of: string, []string, InputFile, []InputFile, -// string: local file path -func convertInputFiles(files interface{}, context *browserContextImpl) (*inputFiles, error) { - var ( - converted = &inputFiles{} - paths []string - ) - switch items := files.(type) { - case InputFile: - if sizeOfInputFiles([]InputFile{items}) > fileSizeLimitInBytes { - return nil, ErrInputFilesSizeExceeded - } - converted.Payloads = normalizeFilePayloads([]InputFile{items}) - case []InputFile: - if sizeOfInputFiles(items) > fileSizeLimitInBytes { - return nil, ErrInputFilesSizeExceeded - } - converted.Payloads = normalizeFilePayloads(items) - case string: // local file path - paths = []string{items} - case []string: - paths = items - default: - return nil, errors.New("files should be one of: string, []string, InputFile, []InputFile") - } - - localPaths, localDir, err := resolvePathsAndDirectoryForInputFiles(paths) - if err != nil { - return nil, err - } - - if !context.connection.isRemote { - converted.LocalPaths = localPaths - converted.LocalDirectory = localDir - return converted, nil - } - - // remote - params := map[string]interface{}{ - "items": []fileItem{}, - } - allFiles := localPaths - if localDir != nil { - params["rootDirName"] = filepath.Base(*localDir) - allFiles, err = listFiles(*localDir) - if err != nil { - return nil, err - } - } - for _, file := range allFiles { - lastModifiedMs, err := getFileLastModifiedMs(file) - if err != nil { - return nil, fmt.Errorf("failed to get last modified time of %s: %w", file, err) - } - filename := filepath.Base(file) - if localDir != nil { - var err error - filename, err = filepath.Rel(*localDir, file) - if err != nil { - return nil, err - } - } - params["items"] = append(params["items"].([]fileItem), fileItem{ - LastModifiedMs: &lastModifiedMs, - Name: filename, - }) - } - - ret, err := context.connection.WrapAPICall(func() (interface{}, error) { - return context.channel.SendReturnAsDict("createTempFiles", params) - }, true) - if err != nil { - return nil, err - } - result := ret.(map[string]interface{}) - - streams := make([]*channel, 0) - items := result["writableStreams"].([]interface{}) - for i := 0; i < len(allFiles); i++ { - stream := fromChannel(items[i]).(*writableStream) - if err := stream.Copy(allFiles[i]); err != nil { - return nil, err - } - streams = append(streams, stream.channel) - } - - if result["rootDir"] != nil { - converted.DirectoryStream = result["rootDir"].(*channel) - } else { - converted.Streams = streams - } - - return converted, nil -} - -func getFileLastModifiedMs(path string) (int64, error) { - info, err := os.Stat(path) - if err != nil { - return 0, err - } - if info.IsDir() { - return 0, fmt.Errorf("%s is a directory", path) - } - return info.ModTime().UnixMilli(), nil -} - -func sizeOfInputFiles(files []InputFile) int { - size := 0 - for _, file := range files { - size += len(file.Buffer) - } - return size -} - -func normalizeFilePayloads(files []InputFile) []map[string]string { - out := make([]map[string]string, 0) - for _, file := range files { - out = append(out, map[string]string{ - "name": file.Name, - "mimeType": file.MimeType, - "buffer": base64.StdEncoding.EncodeToString(file.Buffer), - }) - } - return out -} - -func resolvePathsAndDirectoryForInputFiles(items []string) (localPaths []string, localDirectory *string, e error) { - for _, item := range items { - abspath, err := filepath.Abs(item) - if err != nil { - e = err - return - } - // if the path is a directory - if info, err := os.Stat(abspath); err == nil { - if info.IsDir() { - if localDirectory != nil { - e = errors.New("Multiple directories are not supported") - return - } - localDirectory = &abspath - } else { - if localPaths == nil { - localPaths = []string{abspath} - } else { - localPaths = append(localPaths, abspath) - } - } - } else { - e = err - return - } - } - if localPaths != nil && localDirectory != nil { - e = errors.New("File paths must be all files or a single directory") - } - return -} - -func listFiles(dir string) ([]string, error) { - var files []string - err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() { - files = append(files, path) - } - return nil - }) - return files, err -} diff --git a/vendor/github.com/playwright-community/playwright-go/internal/safe/map.go b/vendor/github.com/playwright-community/playwright-go/internal/safe/map.go deleted file mode 100644 index 93a8800..0000000 --- a/vendor/github.com/playwright-community/playwright-go/internal/safe/map.go +++ /dev/null @@ -1,90 +0,0 @@ -package safe - -import ( - "maps" - "sync" -) - -// SyncMap is a thread-safe map -type SyncMap[K comparable, V any] struct { - sync.RWMutex - m map[K]V -} - -// NewSyncMap creates a new thread-safe map -func NewSyncMap[K comparable, V any]() *SyncMap[K, V] { - return &SyncMap[K, V]{ - m: make(map[K]V), - } -} - -func (m *SyncMap[K, V]) Store(k K, v V) { - m.Lock() - defer m.Unlock() - m.m[k] = v -} - -func (m *SyncMap[K, V]) Load(k K) (v V, ok bool) { - m.RLock() - defer m.RUnlock() - v, ok = m.m[k] - return -} - -// LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. -func (m *SyncMap[K, V]) LoadOrStore(k K, v V) (actual V, loaded bool) { - m.Lock() - defer m.Unlock() - actual, loaded = m.m[k] - if loaded { - return - } - m.m[k] = v - return v, false -} - -// LoadAndDelete deletes the value for a key, and returns the previous value if any. -func (m *SyncMap[K, V]) LoadAndDelete(k K) (v V, loaded bool) { - m.Lock() - defer m.Unlock() - v, loaded = m.m[k] - if loaded { - delete(m.m, k) - } - return -} - -func (m *SyncMap[K, V]) Delete(k K) { - m.Lock() - defer m.Unlock() - delete(m.m, k) -} - -func (m *SyncMap[K, V]) Clear() { - m.Lock() - defer m.Unlock() - clear(m.m) -} - -func (m *SyncMap[K, V]) Len() int { - m.RLock() - defer m.RUnlock() - return len(m.m) -} - -func (m *SyncMap[K, V]) Clone() map[K]V { - m.RLock() - defer m.RUnlock() - return maps.Clone(m.m) -} - -func (m *SyncMap[K, V]) Range(f func(k K, v V) bool) { - m.RLock() - defer m.RUnlock() - - for k, v := range m.m { - if !f(k, v) { - break - } - } -} diff --git a/vendor/github.com/playwright-community/playwright-go/js_handle.go b/vendor/github.com/playwright-community/playwright-go/js_handle.go deleted file mode 100644 index 6aaa68d..0000000 --- a/vendor/github.com/playwright-community/playwright-go/js_handle.go +++ /dev/null @@ -1,421 +0,0 @@ -package playwright - -import ( - "bytes" - "encoding/base64" - "encoding/binary" - "errors" - "fmt" - "math" - "math/big" - "net/url" - "reflect" - "time" -) - -type jsHandleImpl struct { - channelOwner - preview string -} - -func (j *jsHandleImpl) Evaluate(expression string, options ...interface{}) (interface{}, error) { - var arg interface{} - if len(options) == 1 { - arg = options[0] - } - result, err := j.channel.Send("evaluateExpression", map[string]interface{}{ - "expression": expression, - "arg": serializeArgument(arg), - }) - if err != nil { - return nil, err - } - return parseResult(result), nil -} - -func (j *jsHandleImpl) EvaluateHandle(expression string, options ...interface{}) (JSHandle, error) { - var arg interface{} - if len(options) == 1 { - arg = options[0] - } - result, err := j.channel.Send("evaluateExpressionHandle", map[string]interface{}{ - "expression": expression, - "arg": serializeArgument(arg), - }) - if err != nil { - return nil, err - } - channelOwner := fromChannel(result) - if channelOwner == nil { - return nil, nil - } - return channelOwner.(*jsHandleImpl), nil -} - -func (j *jsHandleImpl) GetProperty(name string) (JSHandle, error) { - channel, err := j.channel.Send("getProperty", map[string]interface{}{ - "name": name, - }) - if err != nil { - return nil, err - } - return fromChannel(channel).(*jsHandleImpl), nil -} - -func (j *jsHandleImpl) GetProperties() (map[string]JSHandle, error) { - properties, err := j.channel.Send("getPropertyList") - if err != nil { - return nil, err - } - propertiesMap := make(map[string]JSHandle) - for _, property := range properties.([]interface{}) { - item := property.(map[string]interface{}) - propertiesMap[item["name"].(string)] = fromChannel(item["value"]).(*jsHandleImpl) - } - return propertiesMap, nil -} - -func (j *jsHandleImpl) AsElement() ElementHandle { - return nil -} - -func (j *jsHandleImpl) Dispose() error { - _, err := j.channel.Send("dispose") - if errors.Is(err, ErrTargetClosed) { - return nil - } - return err -} - -func (j *jsHandleImpl) String() string { - return j.preview -} - -func (j *jsHandleImpl) JSONValue() (interface{}, error) { - v, err := j.channel.Send("jsonValue") - if err != nil { - return nil, err - } - return parseResult(v), nil -} - -func parseValue(result interface{}, refs map[float64]interface{}) interface{} { - vMap, ok := result.(map[string]interface{}) - if !ok { - return result - } - if v, ok := vMap["n"]; ok { - if math.Ceil(v.(float64))-v.(float64) == 0 { - return int(v.(float64)) - } - return v.(float64) - } - - if v, ok := vMap["u"]; ok { - u, _ := url.Parse(v.(string)) - return u - } - - if v, ok := vMap["bi"]; ok { - n := new(big.Int) - n.SetString(v.(string), 0) - return n - } - - if v, ok := vMap["ref"]; ok { - if vV, ok := refs[v.(float64)]; ok { - return vV - } - return nil - } - - if v, ok := vMap["s"]; ok { - return v.(string) - } - if v, ok := vMap["b"]; ok { - return v.(bool) - } - if v, ok := vMap["v"]; ok { - if v == "undefined" || v == "null" { - return nil - } - if v == "NaN" { - return math.NaN() - } - if v == "Infinity" { - return math.Inf(1) - } - if v == "-Infinity" { - return math.Inf(-1) - } - if v == "-0" { - return math.Copysign(0, -1) - } - return v - } - if v, ok := vMap["d"]; ok { - t, _ := time.Parse(time.RFC3339Nano, v.(string)) - return t - } - if v, ok := vMap["a"]; ok { - aV := v.([]interface{}) - refs[vMap["id"].(float64)] = aV - for i := range aV { - aV[i] = parseValue(aV[i], refs) - } - return aV - } - if v, ok := vMap["o"]; ok { - aV := v.([]interface{}) - out := map[string]interface{}{} - refs[vMap["id"].(float64)] = out - for key := range aV { - entry := aV[key].(map[string]interface{}) - out[entry["k"].(string)] = parseValue(entry["v"], refs) - } - return out - } - - if v, ok := vMap["e"]; ok { - return parseError(Error{ - Name: v.(map[string]interface{})["n"].(string), - Message: v.(map[string]interface{})["m"].(string), - Stack: v.(map[string]interface{})["s"].(string), - }) - } - if v, ok := vMap["ta"]; ok { - b, b_ok := v.(map[string]interface{})["b"].(string) - k, k_ok := v.(map[string]interface{})["k"].(string) - if b_ok && k_ok { - decoded, err := base64.StdEncoding.DecodeString(b) - if err != nil { - panic(fmt.Errorf("Unexpected value: %v", vMap)) - } - r := bytes.NewReader(decoded) - switch k { - case "i8": - result := make([]int8, len(decoded)) - return mustReadArray(r, &result) - case "ui8", "ui8c": - result := make([]uint8, len(decoded)) - return mustReadArray(r, &result) - case "i16": - size := mustBeDivisible(len(decoded), 2) - result := make([]int16, size) - return mustReadArray(r, &result) - case "ui16": - size := mustBeDivisible(len(decoded), 2) - result := make([]uint16, size) - return mustReadArray(r, &result) - case "i32": - size := mustBeDivisible(len(decoded), 4) - result := make([]int32, size) - return mustReadArray(r, &result) - case "ui32": - size := mustBeDivisible(len(decoded), 4) - result := make([]uint32, size) - return mustReadArray(r, &result) - case "f32": - size := mustBeDivisible(len(decoded), 4) - result := make([]float32, size) - return mustReadArray(r, &result) - case "f64": - size := mustBeDivisible(len(decoded), 8) - result := make([]float64, size) - return mustReadArray(r, &result) - case "bi64": - size := mustBeDivisible(len(decoded), 8) - result := make([]int64, size) - return mustReadArray(r, &result) - case "bui64": - size := mustBeDivisible(len(decoded), 8) - result := make([]uint64, size) - return mustReadArray(r, &result) - default: - panic(fmt.Errorf("Unsupported array type: %s", k)) - } - } - } - panic(fmt.Errorf("Unexpected value: %v", vMap)) -} - -func serializeValue(value interface{}, handles *[]*channel, depth int) interface{} { - if handle, ok := value.(*elementHandleImpl); ok { - h := len(*handles) - *handles = append(*handles, handle.channel) - return map[string]interface{}{ - "h": h, - } - } - if handle, ok := value.(*jsHandleImpl); ok { - h := len(*handles) - *handles = append(*handles, handle.channel) - return map[string]interface{}{ - "h": h, - } - } - if u, ok := value.(*url.URL); ok { - return map[string]interface{}{ - "u": u.String(), - } - } - - if err, ok := value.(error); ok { - var e *Error - if errors.As(err, &e) { - return map[string]interface{}{ - "e": map[string]interface{}{ - "n": e.Name, - "m": e.Message, - "s": e.Stack, - }, - } - } - return map[string]interface{}{ - "e": map[string]interface{}{ - "n": "", - "m": err.Error(), - "s": "", - }, - } - } - - if depth > 100 { - panic(errors.New("Maximum argument depth exceeded")) - } - if value == nil { - return map[string]interface{}{ - "v": "undefined", - } - } - if n, ok := value.(*big.Int); ok { - return map[string]interface{}{ - "bi": n.String(), - } - } - - switch v := value.(type) { - case time.Time: - return map[string]interface{}{ - "d": v.Format(time.RFC3339Nano), - } - case int: - return map[string]interface{}{ - "n": v, - } - case string: - return map[string]interface{}{ - "s": v, - } - case bool: - return map[string]interface{}{ - "b": v, - } - } - - refV := reflect.ValueOf(value) - - switch refV.Kind() { - case reflect.Float32, reflect.Float64: - floatV := refV.Float() - if math.IsInf(floatV, 1) { - return map[string]interface{}{ - "v": "Infinity", - } - } - if math.IsInf(floatV, -1) { - return map[string]interface{}{ - "v": "-Infinity", - } - } - // https://github.com/golang/go/issues/2196 - if floatV == math.Copysign(0, -1) { - return map[string]interface{}{ - "v": "-0", - } - } - if math.IsNaN(floatV) { - return map[string]interface{}{ - "v": "NaN", - } - } - return map[string]interface{}{ - "n": floatV, - } - case reflect.Slice: - aV := make([]interface{}, refV.Len()) - for i := 0; i < refV.Len(); i++ { - aV[i] = serializeValue(refV.Index(i).Interface(), handles, depth+1) - } - return map[string]interface{}{ - "a": aV, - } - case reflect.Map: - out := []interface{}{} - vM := value.(map[string]interface{}) - for key := range vM { - v := serializeValue(vM[key], handles, depth+1) - // had key, so convert "undefined" to "null" - if reflect.DeepEqual(v, map[string]interface{}{ - "v": "undefined", - }) { - v = map[string]interface{}{ - "v": "null", - } - } - out = append(out, map[string]interface{}{ - "k": key, - "v": v, - }) - } - return map[string]interface{}{ - "o": out, - } - } - return map[string]interface{}{ - "v": "undefined", - } -} - -func parseResult(result interface{}) interface{} { - return parseValue(result, map[float64]interface{}{}) -} - -func serializeArgument(arg interface{}) interface{} { - handles := []*channel{} - value := serializeValue(arg, &handles, 0) - return map[string]interface{}{ - "value": value, - "handles": handles, - } -} - -func newJSHandle(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *jsHandleImpl { - bt := &jsHandleImpl{ - preview: initializer["preview"].(string), - } - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - bt.channel.On("previewUpdated", func(ev map[string]interface{}) { - bt.preview = ev["preview"].(string) - }) - return bt -} - -func mustBeDivisible(length int, wordSize int) int { - if length%wordSize != 0 { - panic(fmt.Errorf(`Decoded bytes length %d is not a multiple of word size %d`, length, wordSize)) - } - return length / wordSize -} - -func mustReadArray[T int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | float32 | float64](r *bytes.Reader, v *[]T) []float64 { - err := binary.Read(r, binary.LittleEndian, v) - if err != nil { - panic(err) - } - data := make([]float64, len(*v)) - for i, v := range *v { - data[i] = float64(v) - } - return data -} diff --git a/vendor/github.com/playwright-community/playwright-go/jsonPipe.go b/vendor/github.com/playwright-community/playwright-go/jsonPipe.go deleted file mode 100644 index e6c0e79..0000000 --- a/vendor/github.com/playwright-community/playwright-go/jsonPipe.go +++ /dev/null @@ -1,64 +0,0 @@ -package playwright - -import ( - "encoding/json" - "errors" - "fmt" -) - -type jsonPipe struct { - channelOwner - msgChan chan *message -} - -func (j *jsonPipe) Send(message map[string]interface{}) error { - _, err := j.channel.Send("send", map[string]interface{}{ - "message": message, - }) - return err -} - -func (j *jsonPipe) Close() error { - _, err := j.channel.Send("close") - return err -} - -func (j *jsonPipe) Poll() (*message, error) { - msg := <-j.msgChan - if msg == nil { - return nil, errors.New("jsonPipe closed") - } - return msg, nil -} - -func newJsonPipe(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *jsonPipe { - j := &jsonPipe{ - msgChan: make(chan *message, 2), - } - j.createChannelOwner(j, parent, objectType, guid, initializer) - j.channel.On("message", func(ev map[string]interface{}) { - var msg message - m, err := json.Marshal(ev["message"]) - if err == nil { - err = json.Unmarshal(m, &msg) - } - if err != nil { - msg = message{ - Error: &struct { - Error Error "json:\"error\"" - }{ - Error: Error{ - Name: "Error", - Message: fmt.Sprintf("jsonPipe: could not decode message: %s", err.Error()), - }, - }, - } - } - j.msgChan <- &msg - }) - j.channel.Once("closed", func() { - j.Emit("closed") - close(j.msgChan) - }) - return j -} diff --git a/vendor/github.com/playwright-community/playwright-go/local_utils.go b/vendor/github.com/playwright-community/playwright-go/local_utils.go deleted file mode 100644 index 395c09a..0000000 --- a/vendor/github.com/playwright-community/playwright-go/local_utils.go +++ /dev/null @@ -1,165 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "encoding/json" - "fmt" -) - -type localUtilsImpl struct { - channelOwner - Devices map[string]*DeviceDescriptor -} - -type ( - localUtilsZipOptions struct { - ZipFile string `json:"zipFile"` - Entries []interface{} `json:"entries"` - StacksId string `json:"stacksId"` - Mode string `json:"mode"` - IncludeSources bool `json:"includeSources"` - } - - harLookupOptions struct { - HarId string `json:"harId"` - URL string `json:"url"` - Method string `json:"method"` - Headers map[string]string `json:"headers"` - IsNavigationRequest bool `json:"isNavigationRequest"` - PostData interface{} `json:"postData,omitempty"` - } - - harLookupResult struct { - Action string `json:"action"` - Message *string `json:"message,omitempty"` - RedirectURL *string `json:"redirectUrl,omitempty"` - Status *int `json:"status,omitempty"` - Headers []map[string]string `json:"headers,omitempty"` - Body *string `json:"body,omitempty"` - } -) - -func (l *localUtilsImpl) Zip(options localUtilsZipOptions) (interface{}, error) { - return l.channel.Send("zip", options) -} - -func (l *localUtilsImpl) HarOpen(file string) (string, error) { - result, err := l.channel.SendReturnAsDict("harOpen", []map[string]interface{}{ - { - "file": file, - }, - }) - if err == nil { - if harId, ok := result["harId"]; ok { - return harId.(string), nil - } - if err, ok := result["error"]; ok { - return "", fmt.Errorf("%w:%v", ErrPlaywright, err) - } - } - return "", err -} - -func (l *localUtilsImpl) HarLookup(option harLookupOptions) (*harLookupResult, error) { - overrides := make(map[string]interface{}) - overrides["harId"] = option.HarId - overrides["url"] = option.URL - overrides["method"] = option.Method - if option.Headers != nil { - overrides["headers"] = serializeMapToNameAndValue(option.Headers) - } - overrides["isNavigationRequest"] = option.IsNavigationRequest - if option.PostData != nil { - switch v := option.PostData.(type) { - case string: - overrides["postData"] = base64.StdEncoding.EncodeToString([]byte(v)) - case []byte: - overrides["postData"] = base64.StdEncoding.EncodeToString(v) - } - } - ret, err := l.channel.SendReturnAsDict("harLookup", overrides) - if ret == nil { - return nil, err - } - var result harLookupResult - mJson, err := json.Marshal(ret) - if err != nil { - return nil, err - } - err = json.Unmarshal(mJson, &result) - if err != nil { - return nil, err - } - if result.Body != nil { - body, err := base64.StdEncoding.DecodeString(*result.Body) - if err != nil { - return nil, err - } - result.Body = String(string(body)) - } - return &result, err -} - -func (l *localUtilsImpl) HarClose(harId string) error { - _, err := l.channel.Send("harClose", []map[string]interface{}{ - { - "harId": harId, - }, - }) - return err -} - -func (l *localUtilsImpl) HarUnzip(zipFile, harFile string) error { - _, err := l.channel.Send("harUnzip", []map[string]interface{}{ - { - "zipFile": zipFile, - "harFile": harFile, - }, - }) - return err -} - -func (l *localUtilsImpl) TracingStarted(traceName string, tracesDir ...string) (string, error) { - overrides := make(map[string]interface{}) - overrides["traceName"] = traceName - if len(tracesDir) > 0 { - overrides["tracesDir"] = tracesDir[0] - } - stacksId, err := l.channel.Send("tracingStarted", overrides) - if stacksId == nil { - return "", err - } - return stacksId.(string), err -} - -func (l *localUtilsImpl) TraceDiscarded(stacksId string) error { - _, err := l.channel.Send("traceDiscarded", map[string]interface{}{ - "stacksId": stacksId, - }) - return err -} - -func (l *localUtilsImpl) AddStackToTracingNoReply(id uint32, stack []map[string]interface{}) { - l.channel.SendNoReply("addStackToTracingNoReply", map[string]interface{}{ - "callData": map[string]interface{}{ - "id": id, - "stack": stack, - }, - }) -} - -func newLocalUtils(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *localUtilsImpl { - l := &localUtilsImpl{ - Devices: make(map[string]*DeviceDescriptor), - } - l.createChannelOwner(l, parent, objectType, guid, initializer) - for _, dd := range initializer["deviceDescriptors"].([]interface{}) { - entry := dd.(map[string]interface{}) - l.Devices[entry["name"].(string)] = &DeviceDescriptor{ - Viewport: &Size{}, - } - remapMapToStruct(entry["descriptor"], l.Devices[entry["name"].(string)]) - } - l.markAsInternalType() - return l -} diff --git a/vendor/github.com/playwright-community/playwright-go/locator.go b/vendor/github.com/playwright-community/playwright-go/locator.go deleted file mode 100644 index e6a49b7..0000000 --- a/vendor/github.com/playwright-community/playwright-go/locator.go +++ /dev/null @@ -1,914 +0,0 @@ -package playwright - -import ( - "errors" - "fmt" - "strconv" -) - -var ( - testIdAttributeName = "data-testid" - ErrLocatorNotSameFrame = errors.New("inner 'has' or 'hasNot' locator must belong to the same frame") -) - -type locatorImpl struct { - frame *frameImpl - selector string - options *LocatorOptions - err error -} - -type LocatorOptions LocatorFilterOptions - -func newLocator(frame *frameImpl, selector string, options ...LocatorOptions) *locatorImpl { - option := &LocatorOptions{} - if len(options) == 1 { - option = &options[0] - } - locator := &locatorImpl{frame: frame, selector: selector, options: option, err: nil} - if option.HasText != nil { - selector += fmt.Sprintf(` >> internal:has-text=%s`, escapeForTextSelector(option.HasText, false)) - } - if option.HasNotText != nil { - selector += fmt.Sprintf(` >> internal:has-not-text=%s`, escapeForTextSelector(option.HasNotText, false)) - } - if option.Has != nil { - has := option.Has.(*locatorImpl) - if frame != has.frame { - 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 = errors.Join(locator.err, ErrLocatorNotSameFrame) - } else { - selector += fmt.Sprintf(` >> internal:has-not=%s`, escapeText(hasNot.selector)) - } - } - if option.Visible != nil { - selector += fmt.Sprintf(` >> visible=%s`, strconv.FormatBool(*option.Visible)) - } - - locator.selector = selector - - return locator -} - -func (l *locatorImpl) equals(locator Locator) bool { - return l.frame == locator.(*locatorImpl).frame && l.err == locator.(*locatorImpl).err && l.selector == locator.(*locatorImpl).selector -} - -func (l *locatorImpl) Err() error { - return l.err -} - -func (l *locatorImpl) All() ([]Locator, error) { - result := make([]Locator, 0) - count, err := l.Count() - if err != nil { - return nil, err - } - for i := 0; i < count; i++ { - result = append(result, l.Nth(i)) - } - return result, nil -} - -func (l *locatorImpl) AllInnerTexts() ([]string, error) { - if l.err != nil { - return nil, l.err - } - innerTexts, err := l.frame.EvalOnSelectorAll(l.selector, "ee => ee.map(e => e.innerText)") - if err != nil { - return nil, err - } - texts := innerTexts.([]interface{}) - result := make([]string, len(texts)) - for i := range texts { - result[i] = texts[i].(string) - } - return result, nil -} - -func (l *locatorImpl) AllTextContents() ([]string, error) { - if l.err != nil { - return nil, l.err - } - textContents, err := l.frame.EvalOnSelectorAll(l.selector, "ee => ee.map(e => e.textContent || '')") - if err != nil { - return nil, err - } - texts := textContents.([]interface{}) - result := make([]string, len(texts)) - for i := range texts { - result[i] = texts[i].(string) - } - return result, nil -} - -func (l *locatorImpl) And(locator Locator) Locator { - return newLocator(l.frame, l.selector+` >> internal:and=`+escapeText(locator.(*locatorImpl).selector)) -} - -func (l *locatorImpl) Or(locator Locator) Locator { - return newLocator(l.frame, l.selector+` >> internal:or=`+escapeText(locator.(*locatorImpl).selector)) -} - -func (l *locatorImpl) Blur(options ...LocatorBlurOptions) error { - if l.err != nil { - return l.err - } - params := map[string]interface{}{ - "selector": l.selector, - "strict": true, - } - if len(options) == 1 { - if options[0].Timeout != nil { - params["timeout"] = options[0].Timeout - } - } - _, err := l.frame.channel.Send("blur", params) - return err -} - -func (l *locatorImpl) AriaSnapshot(options ...LocatorAriaSnapshotOptions) (string, error) { - var option LocatorAriaSnapshotOptions - if len(options) == 1 { - option = options[0] - } - ret, err := l.frame.channel.Send("ariaSnapshot", option, - map[string]interface{}{"selector": l.selector}) - if err != nil { - return "", err - } - return ret.(string), nil -} - -func (l *locatorImpl) BoundingBox(options ...LocatorBoundingBoxOptions) (*Rect, error) { - if l.err != nil { - return nil, l.err - } - var option FrameWaitForSelectorOptions - if len(options) == 1 { - option.Timeout = options[0].Timeout - } - - result, err := l.withElement(func(handle ElementHandle) (interface{}, error) { - return handle.BoundingBox() - }, option) - if err != nil { - return nil, err - } - - return result.(*Rect), nil -} - -func (l *locatorImpl) Check(options ...LocatorCheckOptions) error { - if l.err != nil { - return l.err - } - opt := FrameCheckOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.Check(l.selector, opt) -} - -func (l *locatorImpl) Clear(options ...LocatorClearOptions) error { - if l.err != nil { - return l.err - } - if len(options) == 1 { - return l.Fill("", LocatorFillOptions{ - Force: options[0].Force, - Timeout: options[0].Timeout, - }) - } else { - return l.Fill("") - } -} - -func (l *locatorImpl) Click(options ...LocatorClickOptions) error { - if l.err != nil { - return l.err - } - opt := FrameClickOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.Click(l.selector, opt) -} - -func (l *locatorImpl) ContentFrame() FrameLocator { - return newFrameLocator(l.frame, l.selector) -} - -func (l *locatorImpl) Count() (int, error) { - if l.err != nil { - return 0, l.err - } - return l.frame.queryCount(l.selector) -} - -func (l *locatorImpl) Dblclick(options ...LocatorDblclickOptions) error { - if l.err != nil { - return l.err - } - opt := FrameDblclickOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.Dblclick(l.selector, opt) -} - -func (l *locatorImpl) DispatchEvent(typ string, eventInit interface{}, options ...LocatorDispatchEventOptions) error { - if l.err != nil { - return l.err - } - opt := FrameDispatchEventOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.DispatchEvent(l.selector, typ, eventInit, opt) -} - -func (l *locatorImpl) DragTo(target Locator, options ...LocatorDragToOptions) error { - if l.err != nil { - return l.err - } - opt := FrameDragAndDropOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.DragAndDrop(l.selector, target.(*locatorImpl).selector, opt) -} - -func (l *locatorImpl) ElementHandle(options ...LocatorElementHandleOptions) (ElementHandle, error) { - if l.err != nil { - return nil, l.err - } - option := FrameWaitForSelectorOptions{ - State: WaitForSelectorStateAttached, - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&option, options[0], false); err != nil { - return nil, err - } - } - return l.frame.WaitForSelector(l.selector, option) -} - -func (l *locatorImpl) ElementHandles() ([]ElementHandle, error) { - if l.err != nil { - return nil, l.err - } - return l.frame.QuerySelectorAll(l.selector) -} - -func (l *locatorImpl) Evaluate(expression string, arg interface{}, options ...LocatorEvaluateOptions) (interface{}, error) { - if l.err != nil { - return nil, l.err - } - var option FrameWaitForSelectorOptions - if len(options) == 1 { - option.Timeout = options[0].Timeout - } - - return l.withElement(func(handle ElementHandle) (interface{}, error) { - return handle.Evaluate(expression, arg) - }, option) -} - -func (l *locatorImpl) EvaluateAll(expression string, options ...interface{}) (interface{}, error) { - if l.err != nil { - return nil, l.err - } - return l.frame.EvalOnSelectorAll(l.selector, expression, options...) -} - -func (l *locatorImpl) EvaluateHandle(expression string, arg interface{}, options ...LocatorEvaluateHandleOptions) (JSHandle, error) { - if l.err != nil { - return nil, l.err - } - var option FrameWaitForSelectorOptions - if len(options) == 1 { - option.Timeout = options[0].Timeout - } - - h, err := l.withElement(func(handle ElementHandle) (interface{}, error) { - return handle.EvaluateHandle(expression, arg) - }, option) - if err != nil { - return nil, err - } - return h.(JSHandle), nil -} - -func (l *locatorImpl) Fill(value string, options ...LocatorFillOptions) error { - if l.err != nil { - return l.err - } - opt := FrameFillOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.Fill(l.selector, value, opt) -} - -func (l *locatorImpl) Filter(options ...LocatorFilterOptions) Locator { - if len(options) == 1 { - return newLocator(l.frame, l.selector, LocatorOptions(options[0])) - } - return newLocator(l.frame, l.selector) -} - -func (l *locatorImpl) First() Locator { - return newLocator(l.frame, l.selector+" >> nth=0") -} - -func (l *locatorImpl) Focus(options ...LocatorFocusOptions) error { - if l.err != nil { - return l.err - } - opt := FrameFocusOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.Focus(l.selector, opt) -} - -func (l *locatorImpl) FrameLocator(selector string) FrameLocator { - return newFrameLocator(l.frame, l.selector+" >> "+selector) -} - -func (l *locatorImpl) GetAttribute(name string, options ...LocatorGetAttributeOptions) (string, error) { - if l.err != nil { - return "", l.err - } - opt := FrameGetAttributeOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return "", err - } - } - return l.frame.GetAttribute(l.selector, name, opt) -} - -func (l *locatorImpl) GetByAltText(text interface{}, options ...LocatorGetByAltTextOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return l.Locator(getByAltTextSelector(text, exact)) -} - -func (l *locatorImpl) GetByLabel(text interface{}, options ...LocatorGetByLabelOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return l.Locator(getByLabelSelector(text, exact)) -} - -func (l *locatorImpl) GetByPlaceholder(text interface{}, options ...LocatorGetByPlaceholderOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return l.Locator(getByPlaceholderSelector(text, exact)) -} - -func (l *locatorImpl) GetByRole(role AriaRole, options ...LocatorGetByRoleOptions) Locator { - return l.Locator(getByRoleSelector(role, options...)) -} - -func (l *locatorImpl) GetByTestId(testId interface{}) Locator { - return l.Locator(getByTestIdSelector(getTestIdAttributeName(), testId)) -} - -func (l *locatorImpl) GetByText(text interface{}, options ...LocatorGetByTextOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return l.Locator(getByTextSelector(text, exact)) -} - -func (l *locatorImpl) GetByTitle(text interface{}, options ...LocatorGetByTitleOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return l.Locator(getByTitleSelector(text, exact)) -} - -func (l *locatorImpl) Highlight() error { - if l.err != nil { - return l.err - } - return l.frame.highlight(l.selector) -} - -func (l *locatorImpl) Hover(options ...LocatorHoverOptions) error { - if l.err != nil { - return l.err - } - opt := FrameHoverOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.Hover(l.selector, opt) -} - -func (l *locatorImpl) InnerHTML(options ...LocatorInnerHTMLOptions) (string, error) { - if l.err != nil { - return "", l.err - } - opt := FrameInnerHTMLOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return "", err - } - } - return l.frame.InnerHTML(l.selector, opt) -} - -func (l *locatorImpl) InnerText(options ...LocatorInnerTextOptions) (string, error) { - if l.err != nil { - return "", l.err - } - opt := FrameInnerTextOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return "", err - } - } - return l.frame.InnerText(l.selector, opt) -} - -func (l *locatorImpl) InputValue(options ...LocatorInputValueOptions) (string, error) { - if l.err != nil { - return "", l.err - } - opt := FrameInputValueOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return "", err - } - } - return l.frame.InputValue(l.selector, opt) -} - -func (l *locatorImpl) IsChecked(options ...LocatorIsCheckedOptions) (bool, error) { - if l.err != nil { - return false, l.err - } - opt := FrameIsCheckedOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return false, err - } - } - return l.frame.IsChecked(l.selector, opt) -} - -func (l *locatorImpl) IsDisabled(options ...LocatorIsDisabledOptions) (bool, error) { - if l.err != nil { - return false, l.err - } - opt := FrameIsDisabledOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return false, err - } - } - return l.frame.IsDisabled(l.selector, opt) -} - -func (l *locatorImpl) IsEditable(options ...LocatorIsEditableOptions) (bool, error) { - if l.err != nil { - return false, l.err - } - opt := FrameIsEditableOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return false, err - } - } - return l.frame.IsEditable(l.selector, opt) -} - -func (l *locatorImpl) IsEnabled(options ...LocatorIsEnabledOptions) (bool, error) { - if l.err != nil { - return false, l.err - } - opt := FrameIsEnabledOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return false, err - } - } - return l.frame.IsEnabled(l.selector, opt) -} - -func (l *locatorImpl) IsHidden(options ...LocatorIsHiddenOptions) (bool, error) { - if l.err != nil { - return false, l.err - } - opt := FrameIsHiddenOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return false, err - } - } - return l.frame.IsHidden(l.selector, opt) -} - -func (l *locatorImpl) IsVisible(options ...LocatorIsVisibleOptions) (bool, error) { - if l.err != nil { - return false, l.err - } - opt := FrameIsVisibleOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return false, err - } - } - return l.frame.IsVisible(l.selector, opt) -} - -func (l *locatorImpl) Last() Locator { - return newLocator(l.frame, l.selector+" >> nth=-1") -} - -func (l *locatorImpl) Locator(selectorOrLocator interface{}, options ...LocatorLocatorOptions) Locator { - var option LocatorOptions - if len(options) == 1 { - option = LocatorOptions{ - Has: options[0].Has, - HasNot: options[0].HasNot, - HasText: options[0].HasText, - HasNotText: options[0].HasNotText, - } - } - - selector, ok := selectorOrLocator.(string) - if ok { - return newLocator(l.frame, l.selector+" >> "+selector, option) - } - locator, ok := selectorOrLocator.(*locatorImpl) - if ok { - if l.frame != locator.frame { - l.err = errors.Join(l.err, ErrLocatorNotSameFrame) - return l - } - return newLocator(l.frame, - l.selector+" >> internal:chain="+escapeText(locator.selector), - option, - ) - } - l.err = errors.Join(l.err, fmt.Errorf("invalid locator parameter: %v", selectorOrLocator)) - return l -} - -func (l *locatorImpl) Nth(index int) Locator { - return newLocator(l.frame, l.selector+" >> nth="+strconv.Itoa(index)) -} - -func (l *locatorImpl) Page() (Page, error) { - if l.err != nil { - return nil, l.err - } - return l.frame.Page(), nil -} - -func (l *locatorImpl) Press(key string, options ...LocatorPressOptions) error { - if l.err != nil { - return l.err - } - opt := FramePressOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.Press(l.selector, key, opt) -} - -func (l *locatorImpl) PressSequentially(text string, options ...LocatorPressSequentiallyOptions) error { - if l.err != nil { - return l.err - } - var option LocatorTypeOptions - if len(options) == 1 { - option = LocatorTypeOptions(options[0]) - } - return l.Type(text, option) -} - -func (l *locatorImpl) Screenshot(options ...LocatorScreenshotOptions) ([]byte, error) { - if l.err != nil { - return nil, l.err - } - var option FrameWaitForSelectorOptions - if len(options) == 1 { - option.Timeout = options[0].Timeout - } - - result, err := l.withElement(func(handle ElementHandle) (interface{}, error) { - var screenshotOption ElementHandleScreenshotOptions - if len(options) == 1 { - screenshotOption = ElementHandleScreenshotOptions(options[0]) - } - return handle.Screenshot(screenshotOption) - }, option) - if err != nil { - return nil, err - } - - return result.([]byte), nil -} - -func (l *locatorImpl) ScrollIntoViewIfNeeded(options ...LocatorScrollIntoViewIfNeededOptions) error { - if l.err != nil { - return l.err - } - var option FrameWaitForSelectorOptions - if len(options) == 1 { - option.Timeout = options[0].Timeout - } - - _, err := l.withElement(func(handle ElementHandle) (interface{}, error) { - var opt ElementHandleScrollIntoViewIfNeededOptions - if len(options) == 1 { - opt.Timeout = options[0].Timeout - } - return nil, handle.ScrollIntoViewIfNeeded(opt) - }, option) - - return err -} - -func (l *locatorImpl) SelectOption(values SelectOptionValues, options ...LocatorSelectOptionOptions) ([]string, error) { - if l.err != nil { - return nil, l.err - } - opt := FrameSelectOptionOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return nil, err - } - } - return l.frame.SelectOption(l.selector, values, opt) -} - -func (l *locatorImpl) SelectText(options ...LocatorSelectTextOptions) error { - if l.err != nil { - return l.err - } - var option FrameWaitForSelectorOptions - if len(options) == 1 { - option.Timeout = options[0].Timeout - } - - _, err := l.withElement(func(handle ElementHandle) (interface{}, error) { - var opt ElementHandleSelectTextOptions - if len(options) == 1 { - opt = ElementHandleSelectTextOptions(options[0]) - } - return nil, handle.SelectText(opt) - }, option) - - return err -} - -func (l *locatorImpl) SetChecked(checked bool, options ...LocatorSetCheckedOptions) error { - if l.err != nil { - return l.err - } - opt := FrameSetCheckedOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.SetChecked(l.selector, checked, opt) -} - -func (l *locatorImpl) SetInputFiles(files interface{}, options ...LocatorSetInputFilesOptions) error { - if l.err != nil { - return l.err - } - opt := FrameSetInputFilesOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.SetInputFiles(l.selector, files, opt) -} - -func (l *locatorImpl) Tap(options ...LocatorTapOptions) error { - if l.err != nil { - return l.err - } - opt := FrameTapOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.Tap(l.selector, opt) -} - -func (l *locatorImpl) TextContent(options ...LocatorTextContentOptions) (string, error) { - if l.err != nil { - return "", l.err - } - opt := FrameTextContentOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return "", err - } - } - return l.frame.TextContent(l.selector, opt) -} - -func (l *locatorImpl) Type(text string, options ...LocatorTypeOptions) error { - if l.err != nil { - return l.err - } - opt := FrameTypeOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.Type(l.selector, text, opt) -} - -func (l *locatorImpl) Uncheck(options ...LocatorUncheckOptions) error { - if l.err != nil { - return l.err - } - opt := FrameUncheckOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - return l.frame.Uncheck(l.selector, opt) -} - -func (l *locatorImpl) WaitFor(options ...LocatorWaitForOptions) error { - if l.err != nil { - return l.err - } - opt := FrameWaitForSelectorOptions{ - Strict: Bool(true), - } - if len(options) == 1 { - if err := assignStructFields(&opt, options[0], false); err != nil { - return err - } - } - _, err := l.frame.WaitForSelector(l.selector, opt) - return err -} - -func (l *locatorImpl) withElement( - callback func(handle ElementHandle) (interface{}, error), - options ...FrameWaitForSelectorOptions, -) (interface{}, error) { - if l.err != nil { - return nil, l.err - } - handle, err := l.frame.WaitForSelector(l.selector, options...) - if err != nil { - return nil, err - } - - result, err := callback(handle) - if err != nil { - return nil, err - } - return result, nil -} - -func (l *locatorImpl) expect(expression string, options frameExpectOptions) (*frameExpectResult, error) { - if l.err != nil { - return nil, l.err - } - overrides := map[string]interface{}{ - "selector": l.selector, - "expression": expression, - } - if options.ExpectedValue != nil { - overrides["expectedValue"] = serializeArgument(options.ExpectedValue) - options.ExpectedValue = nil - } - result, err := l.frame.channel.SendReturnAsDict("expect", options, overrides) - if err != nil { - return nil, err - } - var ( - received interface{} - matches bool - log []string - ) - - if v, ok := result["received"]; ok { - received = parseResult(v) - } - if v, ok := result["matches"]; ok { - matches = v.(bool) - } - if v, ok := result["log"]; ok { - for _, l := range v.([]interface{}) { - log = append(log, l.(string)) - } - } - return &frameExpectResult{Received: received, Matches: matches, Log: log}, nil -} diff --git a/vendor/github.com/playwright-community/playwright-go/locator_assertions.go b/vendor/github.com/playwright-community/playwright-go/locator_assertions.go deleted file mode 100644 index e2ea2bb..0000000 --- a/vendor/github.com/playwright-community/playwright-go/locator_assertions.go +++ /dev/null @@ -1,568 +0,0 @@ -package playwright - -import ( - "fmt" - "regexp" -) - -type locatorAssertionsImpl struct { - assertionsBase -} - -func newLocatorAssertions(locator Locator, isNot bool, defaultTimeout *float64) *locatorAssertionsImpl { - return &locatorAssertionsImpl{ - assertionsBase: assertionsBase{ - actualLocator: locator, - isNot: isNot, - defaultTimeout: defaultTimeout, - }, - } -} - -func (la *locatorAssertionsImpl) ToBeAttached(options ...LocatorAssertionsToBeAttachedOptions) error { - expression := "to.be.attached" - var timeout *float64 - if len(options) == 1 { - if options[0].Attached != nil && !*options[0].Attached { - expression = "to.be.detached" - } - timeout = options[0].Timeout - } - return la.expect( - expression, - frameExpectOptions{Timeout: timeout}, - nil, - "Locator expected to be attached", - ) -} - -func (la *locatorAssertionsImpl) ToBeChecked(options ...LocatorAssertionsToBeCheckedOptions) error { - var timeout *float64 - - expectedValue := map[string]interface{}{} - expected := "checked" - - if len(options) == 1 { - if options[0].Indeterminate != nil { - expectedValue["indeterminate"] = *options[0].Indeterminate - if *options[0].Indeterminate { - expected = "indeterminate" - } - } else { - if options[0].Checked != nil { - expectedValue["checked"] = *options[0].Checked - if !*options[0].Checked { - expected = "unchecked" - } - } - } - timeout = options[0].Timeout - } - return la.expect( - "to.be.checked", - frameExpectOptions{ - ExpectedValue: expectedValue, - Timeout: timeout, - }, - nil, - fmt.Sprintf("Locator expected to be %s", expected), - ) -} - -func (la *locatorAssertionsImpl) ToBeDisabled(options ...LocatorAssertionsToBeDisabledOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - return la.expect( - "to.be.disabled", - frameExpectOptions{Timeout: timeout}, - nil, - "Locator expected to be disabled", - ) -} - -func (la *locatorAssertionsImpl) ToBeEditable(options ...LocatorAssertionsToBeEditableOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - return la.expect( - "to.be.editable", - frameExpectOptions{Timeout: timeout}, - nil, - "Locator expected to be editable", - ) -} - -func (la *locatorAssertionsImpl) ToBeEmpty(options ...LocatorAssertionsToBeEmptyOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - return la.expect( - "to.be.empty", - frameExpectOptions{Timeout: timeout}, - nil, - "Locator expected to be empty", - ) -} - -func (la *locatorAssertionsImpl) ToBeEnabled(options ...LocatorAssertionsToBeEnabledOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - return la.expect( - "to.be.enabled", - frameExpectOptions{Timeout: timeout}, - nil, - "Locator expected to be enabled", - ) -} - -func (la *locatorAssertionsImpl) ToBeFocused(options ...LocatorAssertionsToBeFocusedOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - return la.expect( - "to.be.focused", - frameExpectOptions{Timeout: timeout}, - nil, - "Locator expected to be focused", - ) -} - -func (la *locatorAssertionsImpl) ToBeHidden(options ...LocatorAssertionsToBeHiddenOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - return la.expect( - "to.be.hidden", - frameExpectOptions{Timeout: timeout}, - nil, - "Locator expected to be hidden", - ) -} - -func (la *locatorAssertionsImpl) ToBeInViewport(options ...LocatorAssertionsToBeInViewportOptions) error { - var ( - ratio *float64 - timeout *float64 - ) - if len(options) == 1 { - ratio = options[0].Ratio - timeout = options[0].Timeout - } - return la.expect( - "to.be.in.viewport", - frameExpectOptions{ - ExpectedNumber: ratio, - Timeout: timeout, - }, - nil, - "Locator expected to be in viewport", - ) -} - -func (la *locatorAssertionsImpl) ToBeVisible(options ...LocatorAssertionsToBeVisibleOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - return la.expect( - "to.be.visible", - frameExpectOptions{Timeout: timeout}, - nil, - "Locator expected to be visible", - ) -} - -func (la *locatorAssertionsImpl) ToContainClass(expected interface{}, options ...LocatorAssertionsToContainClassOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - switch expected.(type) { - case []string: - expectedText, err := toExpectedTextValues(convertToInterfaceList(expected), false, false, nil) - if err != nil { - return err - } - return la.expect( - "to.contain.class.array", - frameExpectOptions{ - ExpectedText: expectedText, - Timeout: timeout, - }, - expected, - "Locator expected to contain class", - ) - case string: - expectedText, err := toExpectedTextValues([]interface{}{expected}, false, false, nil) - if err != nil { - return err - } - return la.expect( - "to.contain.class", - frameExpectOptions{ - ExpectedText: expectedText, - Timeout: timeout, - }, - expected, - "Locator expected to contain class", - ) - default: - return fmt.Errorf("expected should be string or []string, but got %T", expected) - } -} - -func (la *locatorAssertionsImpl) ToContainText(expected interface{}, options ...LocatorAssertionsToContainTextOptions) error { - var ( - timeout *float64 - useInnerText *bool - ignoreCase *bool - ) - if len(options) == 1 { - timeout = options[0].Timeout - useInnerText = options[0].UseInnerText - ignoreCase = options[0].IgnoreCase - } - - switch expected.(type) { - case []string, []*regexp.Regexp: - expectedText, err := toExpectedTextValues(convertToInterfaceList(expected), true, true, ignoreCase) - if err != nil { - return err - } - return la.expect( - "to.contain.text.array", - frameExpectOptions{ - ExpectedText: expectedText, - UseInnerText: useInnerText, - Timeout: timeout, - }, - expected, - "Locator expected to contain text", - ) - default: - expectedText, err := toExpectedTextValues([]interface{}{expected}, true, true, ignoreCase) - if err != nil { - return err - } - return la.expect( - "to.have.text", - frameExpectOptions{ - ExpectedText: expectedText, - UseInnerText: useInnerText, - Timeout: timeout, - }, - expected, - "Locator expected to contain text", - ) - } -} - -func (la *locatorAssertionsImpl) ToHaveAccessibleDescription(description interface{}, options ...LocatorAssertionsToHaveAccessibleDescriptionOptions) error { - var timeout *float64 - var ignoreCase *bool - if len(options) == 1 { - timeout = options[0].Timeout - ignoreCase = options[0].IgnoreCase - } - expectedText, err := toExpectedTextValues([]interface{}{description}, false, false, ignoreCase) - if err != nil { - return err - } - return la.expect( - "to.have.accessible.description", - frameExpectOptions{ExpectedText: expectedText, Timeout: timeout}, - description, - "Locator expected to have AccessibleDescription", - ) -} - -func (la *locatorAssertionsImpl) ToHaveAccessibleErrorMessage(errorMessage interface{}, options ...LocatorAssertionsToHaveAccessibleErrorMessageOptions) error { - var timeout *float64 - var ignoreCase *bool - if len(options) == 1 { - timeout = options[0].Timeout - ignoreCase = options[0].IgnoreCase - } - expectedText, err := toExpectedTextValues([]interface{}{errorMessage}, false, false, ignoreCase) - if err != nil { - return err - } - return la.expect( - "to.have.accessible.error.message", - frameExpectOptions{ExpectedText: expectedText, Timeout: timeout}, - errorMessage, - "Locator expected to have AccessibleErrorMessage", - ) -} - -func (la *locatorAssertionsImpl) ToHaveAccessibleName(name interface{}, options ...LocatorAssertionsToHaveAccessibleNameOptions) error { - var timeout *float64 - var ignoreCase *bool - if len(options) == 1 { - timeout = options[0].Timeout - ignoreCase = options[0].IgnoreCase - } - expectedText, err := toExpectedTextValues([]interface{}{name}, false, false, ignoreCase) - if err != nil { - return err - } - return la.expect( - "to.have.accessible.name", - frameExpectOptions{ExpectedText: expectedText, Timeout: timeout}, - name, - "Locator expected to have AccessibleName", - ) -} - -func (la *locatorAssertionsImpl) ToHaveAttribute(name string, value interface{}, options ...LocatorAssertionsToHaveAttributeOptions) error { - var timeout *float64 - var ignoreCase *bool - if len(options) == 1 { - timeout = options[0].Timeout - ignoreCase = options[0].IgnoreCase - } - expectedText, err := toExpectedTextValues([]interface{}{value}, false, false, ignoreCase) - if err != nil { - return err - } - return la.expect( - "to.have.attribute.value", - frameExpectOptions{ - ExpressionArg: name, - ExpectedText: expectedText, - Timeout: timeout, - }, - value, - "Locator expected to have attribute", - ) -} - -func (la *locatorAssertionsImpl) ToHaveClass(expected interface{}, options ...LocatorAssertionsToHaveClassOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - switch expected.(type) { - case []string, []*regexp.Regexp: - expectedText, err := toExpectedTextValues(convertToInterfaceList(expected), false, false, nil) - if err != nil { - return err - } - return la.expect( - "to.have.class.array", - frameExpectOptions{ - ExpectedText: expectedText, - Timeout: timeout, - }, - expected, - "Locator expected to have class", - ) - default: - expectedText, err := toExpectedTextValues([]interface{}{expected}, false, false, nil) - if err != nil { - return err - } - return la.expect( - "to.have.class", - frameExpectOptions{ - ExpectedText: expectedText, - Timeout: timeout, - }, - expected, - "Locator expected to have class", - ) - } -} - -func (la *locatorAssertionsImpl) ToHaveCount(count int, options ...LocatorAssertionsToHaveCountOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - return la.expect( - "to.have.count", - frameExpectOptions{ExpectedNumber: Float(float64(count)), Timeout: timeout}, - count, - "Locator expected to have count", - ) -} - -func (la *locatorAssertionsImpl) ToHaveCSS(name string, value interface{}, options ...LocatorAssertionsToHaveCSSOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - expectedText, err := toExpectedTextValues([]interface{}{value}, false, false, nil) - if err != nil { - return err - } - return la.expect( - "to.have.css", - frameExpectOptions{ - ExpressionArg: name, - ExpectedText: expectedText, - Timeout: timeout, - }, - value, - "Locator expected to have CSS", - ) -} - -func (la *locatorAssertionsImpl) ToHaveId(id interface{}, options ...LocatorAssertionsToHaveIdOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - expectedText, err := toExpectedTextValues([]interface{}{id}, false, false, nil) - if err != nil { - return err - } - return la.expect( - "to.have.id", - frameExpectOptions{ExpectedText: expectedText, Timeout: timeout}, - id, - "Locator expected to have ID", - ) -} - -func (la *locatorAssertionsImpl) ToHaveJSProperty(name string, value interface{}, options ...LocatorAssertionsToHaveJSPropertyOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - return la.expect( - "to.have.property", - frameExpectOptions{ - ExpressionArg: name, - ExpectedValue: value, - Timeout: timeout, - }, - value, - "Locator expected to have JS Property", - ) -} - -func (la *locatorAssertionsImpl) ToHaveRole(role AriaRole, options ...LocatorAssertionsToHaveRoleOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - expectedText, err := toExpectedTextValues([]interface{}{string(role)}, false, false, nil) - if err != nil { - return err - } - return la.expect( - "to.have.role", - frameExpectOptions{ExpectedText: expectedText, Timeout: timeout}, - role, - "Locator expected to have Role", - ) -} - -func (la *locatorAssertionsImpl) ToHaveText(expected interface{}, options ...LocatorAssertionsToHaveTextOptions) error { - var ( - timeout *float64 - useInnerText *bool - ignoreCase *bool - ) - if len(options) == 1 { - timeout = options[0].Timeout - useInnerText = options[0].UseInnerText - ignoreCase = options[0].IgnoreCase - } - - switch expected.(type) { - case []string, []*regexp.Regexp: - expectedText, err := toExpectedTextValues(convertToInterfaceList(expected), false, true, ignoreCase) - if err != nil { - return err - } - return la.expect( - "to.have.text.array", - frameExpectOptions{ - ExpectedText: expectedText, - UseInnerText: useInnerText, - Timeout: timeout, - }, - expected, - "Locator expected to have text", - ) - default: - expectedText, err := toExpectedTextValues([]interface{}{expected}, false, true, ignoreCase) - if err != nil { - return err - } - return la.expect( - "to.have.text", - frameExpectOptions{ - ExpectedText: expectedText, - UseInnerText: useInnerText, - Timeout: timeout, - }, - expected, - "Locator expected to have text", - ) - } -} - -func (la *locatorAssertionsImpl) ToHaveValue(value interface{}, options ...LocatorAssertionsToHaveValueOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - expectedText, err := toExpectedTextValues([]interface{}{value}, false, false, nil) - if err != nil { - return err - } - return la.expect( - "to.have.value", - frameExpectOptions{ExpectedText: expectedText, Timeout: timeout}, - value, - "Locator expected to have Value", - ) -} - -func (la *locatorAssertionsImpl) ToHaveValues(values []interface{}, options ...LocatorAssertionsToHaveValuesOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - expectedText, err := toExpectedTextValues(values, false, false, nil) - if err != nil { - return err - } - return la.expect( - "to.have.values", - frameExpectOptions{ExpectedText: expectedText, Timeout: timeout}, - values, - "Locator expected to have Values", - ) -} - -func (la *locatorAssertionsImpl) ToMatchAriaSnapshot(expected string, options ...LocatorAssertionsToMatchAriaSnapshotOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - return la.expect( - "to.match.aria", - frameExpectOptions{ - ExpectedValue: expected, - Timeout: timeout, - }, - expected, - "Locator expected to match Aria snapshot", - ) -} - -func (la *locatorAssertionsImpl) Not() LocatorAssertions { - return newLocatorAssertions(la.actualLocator, true, la.defaultTimeout) -} diff --git a/vendor/github.com/playwright-community/playwright-go/locator_helpers.go b/vendor/github.com/playwright-community/playwright-go/locator_helpers.go deleted file mode 100644 index 2836fca..0000000 --- a/vendor/github.com/playwright-community/playwright-go/locator_helpers.go +++ /dev/null @@ -1,133 +0,0 @@ -package playwright - -import ( - "encoding/json" - "fmt" - "regexp" - "strings" -) - -func convertRegexp(reg *regexp.Regexp) (pattern, flags string) { - matches := regexp.MustCompile(`\(\?([imsU]+)\)(.+)`).FindStringSubmatch(reg.String()) - - if len(matches) == 3 { - pattern = matches[2] - flags = matches[1] - } else { - pattern = reg.String() - } - return -} - -func escapeForAttributeSelector(text interface{}, exact bool) string { - switch text := text.(type) { - case *regexp.Regexp: - return escapeRegexForSelector(text) - default: - suffix := "i" - if exact { - suffix = "s" - } - return fmt.Sprintf(`"%s"%s`, strings.Replace(strings.Replace(text.(string), `\`, `\\`, -1), `"`, `\"`, -1), suffix) - } -} - -func escapeForTextSelector(text interface{}, exact bool) string { - switch text := text.(type) { - case *regexp.Regexp: - return escapeRegexForSelector(text) - default: - if exact { - return fmt.Sprintf(`%ss`, escapeText(text.(string))) - } - return fmt.Sprintf(`%si`, escapeText(text.(string))) - } -} - -func escapeRegexForSelector(re *regexp.Regexp) string { - pattern, flag := convertRegexp(re) - return fmt.Sprintf(`/%s/%s`, strings.ReplaceAll(pattern, `>>`, `\>\>`), flag) -} - -func escapeText(s string) string { - builder := &strings.Builder{} - encoder := json.NewEncoder(builder) - encoder.SetEscapeHTML(false) - _ = encoder.Encode(s) - return strings.TrimSpace(builder.String()) -} - -func getByAltTextSelector(text interface{}, exact bool) string { - return getByAttributeTextSelector("alt", text, exact) -} - -func getByAttributeTextSelector(attrName string, text interface{}, exact bool) string { - return fmt.Sprintf(`internal:attr=[%s=%s]`, attrName, escapeForAttributeSelector(text, exact)) -} - -func getByLabelSelector(text interface{}, exact bool) string { - return fmt.Sprintf(`internal:label=%s`, escapeForTextSelector(text, exact)) -} - -func getByPlaceholderSelector(text interface{}, exact bool) string { - return getByAttributeTextSelector("placeholder", text, exact) -} - -func getByRoleSelector(role AriaRole, options ...LocatorGetByRoleOptions) string { - props := make(map[string]string) - if len(options) == 1 { - if options[0].Checked != nil { - props["checked"] = fmt.Sprintf("%t", *options[0].Checked) - } - if options[0].Disabled != nil { - props["disabled"] = fmt.Sprintf("%t", *options[0].Disabled) - } - if options[0].Selected != nil { - props["selected"] = fmt.Sprintf("%t", *options[0].Selected) - } - if options[0].Expanded != nil { - props["expanded"] = fmt.Sprintf("%t", *options[0].Expanded) - } - if options[0].IncludeHidden != nil { - props["include-hidden"] = fmt.Sprintf("%t", *options[0].IncludeHidden) - } - if options[0].Level != nil { - props["level"] = fmt.Sprintf("%d", *options[0].Level) - } - if options[0].Name != nil { - exact := false - if options[0].Exact != nil { - exact = *options[0].Exact - } - props["name"] = escapeForAttributeSelector(options[0].Name, exact) - } - if options[0].Pressed != nil { - props["pressed"] = fmt.Sprintf("%t", *options[0].Pressed) - } - } - propsStr := "" - for k, v := range props { - propsStr += "[" + k + "=" + v + "]" - } - return fmt.Sprintf("internal:role=%s%s", role, propsStr) -} - -func getByTextSelector(text interface{}, exact bool) string { - return fmt.Sprintf(`internal:text=%s`, escapeForTextSelector(text, exact)) -} - -func getByTestIdSelector(testIdAttributeName string, testId interface{}) string { - return fmt.Sprintf(`internal:testid=[%s=%s]`, testIdAttributeName, escapeForAttributeSelector(testId, true)) -} - -func getByTitleSelector(text interface{}, exact bool) string { - return getByAttributeTextSelector("title", text, exact) -} - -func getTestIdAttributeName() string { - return testIdAttributeName -} - -func setTestIdAttributeName(name string) { - testIdAttributeName = name -} diff --git a/vendor/github.com/playwright-community/playwright-go/network.go b/vendor/github.com/playwright-community/playwright-go/network.go deleted file mode 100644 index 6f76fa5..0000000 --- a/vendor/github.com/playwright-community/playwright-go/network.go +++ /dev/null @@ -1,62 +0,0 @@ -package playwright - -import ( - "strings" -) - -type rawHeaders struct { - headersArray []NameValue - headersMap map[string][]string -} - -func (r *rawHeaders) Get(name string) string { - values := r.GetAll(name) - if len(values) == 0 { - return "" - } - sep := ", " - if strings.ToLower(name) == "set-cookie" { - sep = "\n" - } - return strings.Join(values, sep) -} - -func (r *rawHeaders) GetAll(name string) []string { - name = strings.ToLower(name) - if _, ok := r.headersMap[name]; !ok { - return []string{} - } - return r.headersMap[name] -} - -func (r *rawHeaders) Headers() map[string]string { - out := make(map[string]string) - for key := range r.headersMap { - out[key] = r.Get(key) - } - return out -} - -func (r *rawHeaders) HeadersArray() []NameValue { - return r.headersArray -} - -func newRawHeaders(headers interface{}) *rawHeaders { - r := &rawHeaders{} - r.headersArray = make([]NameValue, 0) - r.headersMap = make(map[string][]string) - for _, header := range headers.([]interface{}) { - entry := header.(map[string]interface{}) - name := entry["name"].(string) - value := entry["value"].(string) - r.headersArray = append(r.headersArray, NameValue{ - Name: name, - Value: value, - }) - if _, ok := r.headersMap[strings.ToLower(name)]; !ok { - r.headersMap[strings.ToLower(name)] = make([]string, 0) - } - r.headersMap[strings.ToLower(name)] = append(r.headersMap[strings.ToLower(name)], value) - } - return r -} diff --git a/vendor/github.com/playwright-community/playwright-go/objectFactory.go b/vendor/github.com/playwright-community/playwright-go/objectFactory.go deleted file mode 100644 index 9474c54..0000000 --- a/vendor/github.com/playwright-community/playwright-go/objectFactory.go +++ /dev/null @@ -1,74 +0,0 @@ -package playwright - -func createObjectFactory(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) interface{} { - switch objectType { - case "Android": - return nil - case "AndroidSocket": - return nil - case "AndroidDevice": - return nil - case "APIRequestContext": - return newAPIRequestContext(parent, objectType, guid, initializer) - case "Artifact": - return newArtifact(parent, objectType, guid, initializer) - case "BindingCall": - return newBindingCall(parent, objectType, guid, initializer) - case "Browser": - return newBrowser(parent, objectType, guid, initializer) - case "BrowserType": - return newBrowserType(parent, objectType, guid, initializer) - case "BrowserContext": - return newBrowserContext(parent, objectType, guid, initializer) - case "CDPSession": - return newCDPSession(parent, objectType, guid, initializer) - case "Dialog": - return newDialog(parent, objectType, guid, initializer) - case "Electron": - return nil - case "ElectronApplication": - return nil - case "ElementHandle": - return newElementHandle(parent, objectType, guid, initializer) - case "Frame": - return newFrame(parent, objectType, guid, initializer) - case "JSHandle": - return newJSHandle(parent, objectType, guid, initializer) - case "JsonPipe": - return newJsonPipe(parent, objectType, guid, initializer) - case "LocalUtils": - localUtils := newLocalUtils(parent, objectType, guid, initializer) - if localUtils.connection.localUtils == nil { - localUtils.connection.localUtils = localUtils - } - return localUtils - case "Page": - return newPage(parent, objectType, guid, initializer) - case "Playwright": - return newPlaywright(parent, objectType, guid, initializer) - case "Request": - return newRequest(parent, objectType, guid, initializer) - case "Response": - return newResponse(parent, objectType, guid, initializer) - case "Route": - return newRoute(parent, objectType, guid, initializer) - case "Selectors": - return newSelectorsOwner(parent, objectType, guid, initializer) - case "SocksSupport": - return nil - case "Stream": - return newStream(parent, objectType, guid, initializer) - case "Tracing": - return newTracing(parent, objectType, guid, initializer) - case "WebSocket": - return newWebsocket(parent, objectType, guid, initializer) - case "WebSocketRoute": - return newWebSocketRoute(parent, objectType, guid, initializer) - case "Worker": - return newWorker(parent, objectType, guid, initializer) - case "WritableStream": - return newWritableStream(parent, objectType, guid, initializer) - default: - panic(objectType) - } -} diff --git a/vendor/github.com/playwright-community/playwright-go/page.go b/vendor/github.com/playwright-community/playwright-go/page.go deleted file mode 100644 index d4271a0..0000000 --- a/vendor/github.com/playwright-community/playwright-go/page.go +++ /dev/null @@ -1,1384 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "errors" - "fmt" - "os" - "slices" - "sync" - - "github.com/playwright-community/playwright-go/internal/safe" -) - -type pageImpl struct { - channelOwner - isClosed bool - closedOrCrashed chan error - video *videoImpl - mouse *mouseImpl - keyboard *keyboardImpl - touchscreen *touchscreenImpl - timeoutSettings *timeoutSettings - browserContext *browserContextImpl - frames []Frame - workers []Worker - mainFrame Frame - routes []*routeHandlerEntry - webSocketRoutes []*webSocketRouteHandler - viewportSize *Size - ownedContext BrowserContext - bindings *safe.SyncMap[string, BindingCallFunction] - closeReason *string - closeWasCalled bool - harRouters []*harRouter - locatorHandlers map[float64]*locatorHandlerEntry -} - -type locatorHandlerEntry struct { - locator *locatorImpl - handler func(Locator) - times *int -} - -func (p *pageImpl) AddLocatorHandler(locator Locator, handler func(Locator), options ...PageAddLocatorHandlerOptions) error { - if locator == nil || handler == nil { - return errors.New("locator or handler must not be nil") - } - if locator.Err() != nil { - return locator.Err() - } - - var option PageAddLocatorHandlerOptions - if len(options) == 1 { - option = options[0] - if option.Times != nil && *option.Times == 0 { - return nil - } - } - - loc := locator.(*locatorImpl) - if loc.frame != p.mainFrame { - return errors.New("locator must belong to the main frame of this page") - } - uid, err := p.channel.Send("registerLocatorHandler", map[string]any{ - "selector": loc.selector, - "noWaitAfter": option.NoWaitAfter, - }) - if err != nil { - return err - } - p.locatorHandlers[uid.(float64)] = &locatorHandlerEntry{locator: loc, handler: handler, times: option.Times} - return nil -} - -func (p *pageImpl) onLocatorHandlerTriggered(uid float64) { - var remove *bool - handler, ok := p.locatorHandlers[uid] - if !ok { - return - } - if handler.times != nil { - *handler.times-- - if *handler.times == 0 { - remove = Bool(true) - } - } - defer func() { - if remove != nil && *remove { - delete(p.locatorHandlers, uid) - } - _, _ = p.connection.WrapAPICall(func() (interface{}, error) { - _, err := p.channel.Send("resolveLocatorHandlerNoReply", map[string]any{ - "uid": uid, - "remove": remove, - }) - return nil, err - }, true) - }() - - handler.handler(handler.locator) -} - -func (p *pageImpl) RemoveLocatorHandler(locator Locator) error { - for uid := range p.locatorHandlers { - if p.locatorHandlers[uid].locator.equals(locator) { - delete(p.locatorHandlers, uid) - p.channel.SendNoReply("unregisterLocatorHandler", map[string]any{ - "uid": uid, - }) - return nil - } - } - return nil -} - -func (p *pageImpl) Context() BrowserContext { - return p.browserContext -} - -func (b *pageImpl) Clock() Clock { - return b.browserContext.clock -} - -func (p *pageImpl) Close(options ...PageCloseOptions) error { - if len(options) == 1 { - p.closeReason = options[0].Reason - } - p.closeWasCalled = true - _, err := p.channel.Send("close", options) - if err == nil && p.ownedContext != nil { - err = p.ownedContext.Close() - } - if errors.Is(err, ErrTargetClosed) || (len(options) == 1 && options[0].RunBeforeUnload != nil && *(options[0].RunBeforeUnload)) { - return nil - } - return err -} - -func (p *pageImpl) InnerText(selector string, options ...PageInnerTextOptions) (string, error) { - if len(options) == 1 { - return p.mainFrame.InnerText(selector, FrameInnerTextOptions(options[0])) - } - return p.mainFrame.InnerText(selector) -} - -func (p *pageImpl) InnerHTML(selector string, options ...PageInnerHTMLOptions) (string, error) { - if len(options) == 1 { - return p.mainFrame.InnerHTML(selector, FrameInnerHTMLOptions(options[0])) - } - return p.mainFrame.InnerHTML(selector) -} - -func (p *pageImpl) Opener() (Page, error) { - channel := p.initializer["opener"] - channelOwner := fromNullableChannel(channel) - if channelOwner == nil { - // not popup page or opener has been closed - return nil, nil - } - return channelOwner.(*pageImpl), nil -} - -func (p *pageImpl) MainFrame() Frame { - return p.mainFrame -} - -func (p *pageImpl) Frame(options ...PageFrameOptions) Frame { - option := PageFrameOptions{} - if len(options) == 1 { - option = options[0] - } - var matcher *urlMatcher - if option.URL != nil { - matcher = newURLMatcher(option.URL, p.browserContext.options.BaseURL) - } - - for _, f := range p.frames { - if option.Name != nil && f.Name() == *option.Name { - return f - } - - if option.URL != nil && matcher != nil && matcher.Matches(f.URL()) { - return f - } - } - - return nil -} - -func (p *pageImpl) Frames() []Frame { - return p.frames -} - -func (p *pageImpl) SetDefaultNavigationTimeout(timeout float64) { - p.timeoutSettings.SetDefaultNavigationTimeout(&timeout) - p.channel.SendNoReplyInternal("setDefaultNavigationTimeoutNoReply", map[string]interface{}{ - "timeout": timeout, - }) -} - -func (p *pageImpl) SetDefaultTimeout(timeout float64) { - p.timeoutSettings.SetDefaultTimeout(&timeout) - p.channel.SendNoReplyInternal("setDefaultTimeoutNoReply", map[string]interface{}{ - "timeout": timeout, - }) -} - -func (p *pageImpl) QuerySelector(selector string, options ...PageQuerySelectorOptions) (ElementHandle, error) { - if len(options) == 1 { - return p.mainFrame.QuerySelector(selector, FrameQuerySelectorOptions(options[0])) - } - return p.mainFrame.QuerySelector(selector) -} - -func (p *pageImpl) QuerySelectorAll(selector string) ([]ElementHandle, error) { - return p.mainFrame.QuerySelectorAll(selector) -} - -func (p *pageImpl) WaitForSelector(selector string, options ...PageWaitForSelectorOptions) (ElementHandle, error) { - if len(options) == 1 { - return p.mainFrame.WaitForSelector(selector, FrameWaitForSelectorOptions(options[0])) - } - return p.mainFrame.WaitForSelector(selector) -} - -func (p *pageImpl) DispatchEvent(selector string, typ string, eventInit interface{}, options ...PageDispatchEventOptions) error { - if len(options) == 1 { - return p.mainFrame.DispatchEvent(selector, typ, eventInit, FrameDispatchEventOptions(options[0])) - } - return p.mainFrame.DispatchEvent(selector, typ, eventInit) -} - -func (p *pageImpl) Evaluate(expression string, arg ...interface{}) (interface{}, error) { - return p.mainFrame.Evaluate(expression, arg...) -} - -func (p *pageImpl) EvaluateHandle(expression string, arg ...interface{}) (JSHandle, error) { - return p.mainFrame.EvaluateHandle(expression, arg...) -} - -func (p *pageImpl) EvalOnSelector(selector string, expression string, arg interface{}, options ...PageEvalOnSelectorOptions) (interface{}, error) { - if len(options) == 1 { - return p.mainFrame.EvalOnSelector(selector, expression, arg, FrameEvalOnSelectorOptions(options[0])) - } - return p.mainFrame.EvalOnSelector(selector, expression, arg) -} - -func (p *pageImpl) EvalOnSelectorAll(selector string, expression string, arg ...interface{}) (interface{}, error) { - return p.mainFrame.EvalOnSelectorAll(selector, expression, arg...) -} - -func (p *pageImpl) AddScriptTag(options PageAddScriptTagOptions) (ElementHandle, error) { - return p.mainFrame.AddScriptTag(FrameAddScriptTagOptions(options)) -} - -func (p *pageImpl) AddStyleTag(options PageAddStyleTagOptions) (ElementHandle, error) { - return p.mainFrame.AddStyleTag(FrameAddStyleTagOptions(options)) -} - -func (p *pageImpl) SetExtraHTTPHeaders(headers map[string]string) error { - _, err := p.channel.Send("setExtraHTTPHeaders", map[string]interface{}{ - "headers": serializeMapToNameAndValue(headers), - }) - return err -} - -func (p *pageImpl) URL() string { - return p.mainFrame.URL() -} - -func (p *pageImpl) Unroute(url interface{}, handlers ...routeHandler) error { - p.Lock() - defer p.Unlock() - - removed, remaining, err := unroute(p.routes, url, handlers...) - if err != nil { - return err - } - return p.unrouteInternal(removed, remaining, UnrouteBehaviorDefault) -} - -func (p *pageImpl) unrouteInternal(removed []*routeHandlerEntry, remaining []*routeHandlerEntry, behavior *UnrouteBehavior) error { - p.routes = remaining - err := p.updateInterceptionPatterns() - if err != nil { - return err - } - if behavior == nil || behavior == UnrouteBehaviorDefault { - return nil - } - wg := &sync.WaitGroup{} - for _, entry := range removed { - wg.Add(1) - go func(entry *routeHandlerEntry) { - defer wg.Done() - entry.Stop(string(*behavior)) - }(entry) - } - wg.Wait() - return nil -} - -func (p *pageImpl) disposeHarRouters() { - for _, router := range p.harRouters { - router.dispose() - } - p.harRouters = make([]*harRouter, 0) -} - -func (p *pageImpl) UnrouteAll(options ...PageUnrouteAllOptions) error { - var behavior *UnrouteBehavior - if len(options) == 1 { - behavior = options[0].Behavior - } - p.Lock() - defer p.Unlock() - defer p.disposeHarRouters() - return p.unrouteInternal(p.routes, []*routeHandlerEntry{}, behavior) -} - -func (p *pageImpl) Content() (string, error) { - return p.mainFrame.Content() -} - -func (p *pageImpl) SetContent(html string, options ...PageSetContentOptions) error { - if len(options) == 1 { - return p.mainFrame.SetContent(html, FrameSetContentOptions(options[0])) - } - return p.mainFrame.SetContent(html) -} - -func (p *pageImpl) Goto(url string, options ...PageGotoOptions) (Response, error) { - if len(options) == 1 { - return p.mainFrame.Goto(url, FrameGotoOptions(options[0])) - } - return p.mainFrame.Goto(url) -} - -func (p *pageImpl) Reload(options ...PageReloadOptions) (Response, error) { - channel, err := p.channel.Send("reload", options) - if err != nil { - return nil, err - } - channelOwner := fromNullableChannel(channel) - if channelOwner == nil { - return nil, nil - } - return channelOwner.(*responseImpl), nil -} - -func (p *pageImpl) WaitForLoadState(options ...PageWaitForLoadStateOptions) error { - if len(options) == 1 { - return p.mainFrame.WaitForLoadState(FrameWaitForLoadStateOptions(options[0])) - } - return p.mainFrame.WaitForLoadState() -} - -func (p *pageImpl) GoBack(options ...PageGoBackOptions) (Response, error) { - channel, err := p.channel.Send("goBack", options) - if err != nil { - return nil, err - } - channelOwner := fromNullableChannel(channel) - if channelOwner == nil { - // can not go back - return nil, nil - } - return channelOwner.(*responseImpl), nil -} - -func (p *pageImpl) GoForward(options ...PageGoForwardOptions) (Response, error) { - channel, err := p.channel.Send("goForward", options) - if err != nil { - return nil, err - } - channelOwner := fromNullableChannel(channel) - if channelOwner == nil { - // can not go forward - return nil, nil - } - return channelOwner.(*responseImpl), nil -} - -func (p *pageImpl) EmulateMedia(options ...PageEmulateMediaOptions) error { - _, err := p.channel.Send("emulateMedia", options) - if err != nil { - return err - } - return err -} - -func (p *pageImpl) SetViewportSize(width, height int) error { - _, err := p.channel.Send("setViewportSize", map[string]interface{}{ - "viewportSize": map[string]interface{}{ - "width": width, - "height": height, - }, - }) - if err != nil { - return err - } - p.viewportSize.Width = width - p.viewportSize.Height = height - return nil -} - -func (p *pageImpl) ViewportSize() *Size { - return p.viewportSize -} - -func (p *pageImpl) BringToFront() error { - _, err := p.channel.Send("bringToFront") - return err -} - -func (p *pageImpl) Type(selector, text string, options ...PageTypeOptions) error { - if len(options) == 1 { - return p.mainFrame.Type(selector, text, FrameTypeOptions(options[0])) - } - return p.mainFrame.Type(selector, text) -} - -func (p *pageImpl) Fill(selector, text string, options ...PageFillOptions) error { - if len(options) == 1 { - return p.mainFrame.Fill(selector, text, FrameFillOptions(options[0])) - } - return p.mainFrame.Fill(selector, text) -} - -func (p *pageImpl) Press(selector, key string, options ...PagePressOptions) error { - if len(options) == 1 { - return p.mainFrame.Press(selector, key, FramePressOptions(options[0])) - } - return p.mainFrame.Press(selector, key) -} - -func (p *pageImpl) Title() (string, error) { - return p.mainFrame.Title() -} - -func (p *pageImpl) Workers() []Worker { - return p.workers -} - -func (p *pageImpl) Request() APIRequestContext { - return p.Context().Request() -} - -func (p *pageImpl) Screenshot(options ...PageScreenshotOptions) ([]byte, error) { - var path *string - overrides := map[string]interface{}{} - if len(options) == 1 { - path = options[0].Path - options[0].Path = nil - if options[0].Mask != nil { - masks := make([]map[string]interface{}, 0) - for _, m := range options[0].Mask { - if m.Err() != nil { // ErrLocatorNotSameFrame - return nil, m.Err() - } - l, ok := m.(*locatorImpl) - if ok { - masks = append(masks, map[string]interface{}{ - "selector": l.selector, - "frame": l.frame.channel, - }) - } - } - overrides["mask"] = masks - } - } - data, err := p.channel.Send("screenshot", options, overrides) - if err != nil { - return nil, err - } - image, err := base64.StdEncoding.DecodeString(data.(string)) - if err != nil { - return nil, fmt.Errorf("could not decode base64 :%w", err) - } - if path != nil { - if err := os.WriteFile(*path, image, 0o644); err != nil { - return nil, err - } - } - return image, nil -} - -func (p *pageImpl) PDF(options ...PagePdfOptions) ([]byte, error) { - var path *string - if len(options) == 1 { - path = options[0].Path - } - data, err := p.channel.Send("pdf", options) - if err != nil { - return nil, err - } - pdf, err := base64.StdEncoding.DecodeString(data.(string)) - if err != nil { - return nil, fmt.Errorf("could not decode base64 :%w", err) - } - if path != nil { - if err := os.WriteFile(*path, pdf, 0o644); err != nil { - return nil, err - } - } - return pdf, nil -} - -func (p *pageImpl) Click(selector string, options ...PageClickOptions) error { - if len(options) == 1 { - return p.mainFrame.Click(selector, FrameClickOptions(options[0])) - } - return p.mainFrame.Click(selector) -} - -func (p *pageImpl) WaitForEvent(event string, options ...PageWaitForEventOptions) (interface{}, error) { - return p.waiterForEvent(event, options...).Wait() -} - -func (p *pageImpl) waiterForEvent(event string, options ...PageWaitForEventOptions) *waiter { - timeout := p.timeoutSettings.Timeout() - var predicate interface{} = nil - if len(options) == 1 { - if options[0].Timeout != nil { - timeout = *options[0].Timeout - } - predicate = options[0].Predicate - } - waiter := newWaiter().WithTimeout(timeout) - waiter.RejectOnEvent(p, "close", p.closeErrorWithReason()) - waiter.RejectOnEvent(p, "crash", errors.New("page crashed")) - return waiter.WaitForEvent(p, event, predicate) -} - -func (p *pageImpl) waiterForRequest(url interface{}, options ...PageExpectRequestOptions) *waiter { - option := PageExpectRequestOptions{} - if len(options) == 1 { - option = options[0] - } - if option.Timeout == nil { - option.Timeout = Float(p.timeoutSettings.Timeout()) - } - var matcher *urlMatcher - if url != nil { - matcher = newURLMatcher(url, p.browserContext.options.BaseURL) - } - predicate := func(req *requestImpl) bool { - if matcher != nil { - return matcher.Matches(req.URL()) - } - return true - } - - waiter := newWaiter().WithTimeout(*option.Timeout) - return waiter.WaitForEvent(p, "request", predicate) -} - -func (p *pageImpl) waiterForResponse(url interface{}, options ...PageExpectResponseOptions) *waiter { - option := PageExpectResponseOptions{} - if len(options) == 1 { - option = options[0] - } - if option.Timeout == nil { - option.Timeout = Float(p.timeoutSettings.Timeout()) - } - var matcher *urlMatcher - if url != nil { - matcher = newURLMatcher(url, p.browserContext.options.BaseURL) - } - predicate := func(req *responseImpl) bool { - if matcher != nil { - return matcher.Matches(req.URL()) - } - return true - } - - waiter := newWaiter().WithTimeout(*option.Timeout) - return waiter.WaitForEvent(p, "response", predicate) -} - -func (p *pageImpl) ExpectEvent(event string, cb func() error, options ...PageExpectEventOptions) (interface{}, error) { - if len(options) == 1 { - return p.waiterForEvent(event, PageWaitForEventOptions(options[0])).RunAndWait(cb) - } - return p.waiterForEvent(event).RunAndWait(cb) -} - -func (p *pageImpl) ExpectNavigation(cb func() error, options ...PageExpectNavigationOptions) (Response, error) { - if len(options) == 1 { - return p.mainFrame.ExpectNavigation(cb, FrameExpectNavigationOptions(options[0])) - } - return p.mainFrame.ExpectNavigation(cb) -} - -func (p *pageImpl) ExpectConsoleMessage(cb func() error, options ...PageExpectConsoleMessageOptions) (ConsoleMessage, error) { - option := PageWaitForEventOptions{} - if len(options) == 1 { - option.Timeout = options[0].Timeout - option.Predicate = options[0].Predicate - } - ret, err := p.waiterForEvent("console", option).RunAndWait(cb) - if ret == nil { - return nil, err - } - return ret.(*consoleMessageImpl), err -} - -func (p *pageImpl) ExpectDownload(cb func() error, options ...PageExpectDownloadOptions) (Download, error) { - option := PageWaitForEventOptions{} - if len(options) == 1 { - option.Timeout = options[0].Timeout - option.Predicate = options[0].Predicate - } - ret, err := p.waiterForEvent("download", option).RunAndWait(cb) - if ret == nil { - return nil, err - } - return ret.(*downloadImpl), err -} - -func (p *pageImpl) ExpectFileChooser(cb func() error, options ...PageExpectFileChooserOptions) (FileChooser, error) { - option := PageWaitForEventOptions{} - if len(options) == 1 { - option.Timeout = options[0].Timeout - option.Predicate = options[0].Predicate - } - ret, err := p.waiterForEvent("filechooser", option).RunAndWait(cb) - if ret == nil { - return nil, err - } - return ret.(*fileChooserImpl), err -} - -func (p *pageImpl) ExpectPopup(cb func() error, options ...PageExpectPopupOptions) (Page, error) { - option := PageWaitForEventOptions{} - if len(options) == 1 { - option.Timeout = options[0].Timeout - option.Predicate = options[0].Predicate - } - ret, err := p.waiterForEvent("popup", option).RunAndWait(cb) - if ret == nil { - return nil, err - } - return ret.(*pageImpl), err -} - -func (p *pageImpl) ExpectResponse(url interface{}, cb func() error, options ...PageExpectResponseOptions) (Response, error) { - ret, err := p.waiterForResponse(url, options...).RunAndWait(cb) - if ret == nil { - return nil, err - } - return ret.(*responseImpl), err -} - -func (p *pageImpl) ExpectRequest(url interface{}, cb func() error, options ...PageExpectRequestOptions) (Request, error) { - ret, err := p.waiterForRequest(url, options...).RunAndWait(cb) - if ret == nil { - return nil, err - } - return ret.(*requestImpl), err -} - -func (p *pageImpl) ExpectRequestFinished(cb func() error, options ...PageExpectRequestFinishedOptions) (Request, error) { - option := PageWaitForEventOptions{} - if len(options) == 1 { - option.Timeout = options[0].Timeout - option.Predicate = options[0].Predicate - } - ret, err := p.waiterForEvent("requestfinished", option).RunAndWait(cb) - if ret == nil { - return nil, err - } - return ret.(*requestImpl), err -} - -func (p *pageImpl) ExpectWebSocket(cb func() error, options ...PageExpectWebSocketOptions) (WebSocket, error) { - option := PageWaitForEventOptions{} - if len(options) == 1 { - option.Timeout = options[0].Timeout - option.Predicate = options[0].Predicate - } - ret, err := p.waiterForEvent("websocket", option).RunAndWait(cb) - if ret == nil { - return nil, err - } - return ret.(*webSocketImpl), err -} - -func (p *pageImpl) ExpectWorker(cb func() error, options ...PageExpectWorkerOptions) (Worker, error) { - option := PageWaitForEventOptions{} - if len(options) == 1 { - option.Timeout = options[0].Timeout - option.Predicate = options[0].Predicate - } - ret, err := p.waiterForEvent("worker", option).RunAndWait(cb) - if ret == nil { - return nil, err - } - return ret.(*workerImpl), err -} - -func (p *pageImpl) Route(url interface{}, handler routeHandler, times ...int) error { - p.Lock() - defer p.Unlock() - p.routes = slices.Insert(p.routes, 0, newRouteHandlerEntry(newURLMatcher(url, p.browserContext.options.BaseURL), handler, times...)) - return p.updateInterceptionPatterns() -} - -func (p *pageImpl) GetAttribute(selector string, name string, options ...PageGetAttributeOptions) (string, error) { - if len(options) == 1 { - return p.mainFrame.GetAttribute(selector, name, FrameGetAttributeOptions(options[0])) - } - return p.mainFrame.GetAttribute(selector, name) -} - -func (p *pageImpl) Hover(selector string, options ...PageHoverOptions) error { - if len(options) == 1 { - return p.mainFrame.Hover(selector, FrameHoverOptions(options[0])) - } - return p.mainFrame.Hover(selector) -} - -func (p *pageImpl) IsClosed() bool { - return p.isClosed -} - -func (p *pageImpl) AddInitScript(script Script) error { - var source string - if script.Content != nil { - source = *script.Content - } - if script.Path != nil { - content, err := os.ReadFile(*script.Path) - if err != nil { - return err - } - source = string(content) - } - _, err := p.channel.Send("addInitScript", map[string]interface{}{ - "source": source, - }) - return err -} - -func (p *pageImpl) Keyboard() Keyboard { - return p.keyboard -} - -func (p *pageImpl) Mouse() Mouse { - return p.mouse -} - -func (p *pageImpl) RouteFromHAR(har string, options ...PageRouteFromHAROptions) error { - opt := PageRouteFromHAROptions{} - if len(options) == 1 { - opt = options[0] - } - if opt.Update != nil && *opt.Update { - return p.browserContext.recordIntoHar(har, browserContextRecordIntoHarOptions{ - Page: p, - URL: opt.URL, - }) - } - notFound := opt.NotFound - if notFound == nil { - notFound = HarNotFoundAbort - } - router := newHarRouter(p.connection.localUtils, har, *notFound, opt.URL) - p.harRouters = append(p.harRouters, router) - return router.addPageRoute(p) -} - -func (p *pageImpl) Touchscreen() Touchscreen { - return p.touchscreen -} - -func newPage(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *pageImpl { - viewportSize := &Size{} - if _, ok := initializer["viewportSize"].(map[string]interface{}); ok { - viewportSize.Height = int(initializer["viewportSize"].(map[string]interface{})["height"].(float64)) - viewportSize.Width = int(initializer["viewportSize"].(map[string]interface{})["width"].(float64)) - } - bt := &pageImpl{ - workers: make([]Worker, 0), - routes: make([]*routeHandlerEntry, 0), - bindings: safe.NewSyncMap[string, BindingCallFunction](), - viewportSize: viewportSize, - harRouters: make([]*harRouter, 0), - locatorHandlers: make(map[float64]*locatorHandlerEntry, 0), - } - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - bt.browserContext = fromChannel(parent.channel).(*browserContextImpl) - bt.timeoutSettings = newTimeoutSettings(bt.browserContext.timeoutSettings) - mainframe := fromChannel(initializer["mainFrame"]).(*frameImpl) - mainframe.page = bt - bt.mainFrame = mainframe - bt.frames = []Frame{mainframe} - bt.mouse = newMouse(bt.channel) - bt.keyboard = newKeyboard(bt.channel) - bt.touchscreen = newTouchscreen(bt.channel) - bt.channel.On("bindingCall", func(params map[string]interface{}) { - bt.onBinding(fromChannel(params["binding"]).(*bindingCallImpl)) - }) - bt.channel.On("close", bt.onClose) - bt.channel.On("crash", func() { - bt.Emit("crash", bt) - }) - bt.channel.On("domcontentloaded", func() { - bt.Emit("domcontentloaded", bt) - }) - bt.channel.On("fileChooser", func(ev map[string]interface{}) { - bt.Emit("filechooser", newFileChooser(bt, fromChannel(ev["element"]).(*elementHandleImpl), ev["isMultiple"].(bool))) - }) - bt.channel.On("frameAttached", func(ev map[string]interface{}) { - bt.onFrameAttached(fromChannel(ev["frame"]).(*frameImpl)) - }) - bt.channel.On("frameDetached", func(ev map[string]interface{}) { - bt.onFrameDetached(fromChannel(ev["frame"]).(*frameImpl)) - }) - bt.channel.On("locatorHandlerTriggered", func(ev map[string]interface{}) { - bt.channel.CreateTask(func() { - bt.onLocatorHandlerTriggered(ev["uid"].(float64)) - }) - }) - bt.channel.On( - "load", func(ev map[string]interface{}) { - bt.Emit("load", bt) - }, - ) - bt.channel.On("popup", func(ev map[string]interface{}) { - bt.Emit("popup", fromChannel(ev["page"]).(*pageImpl)) - }) - bt.channel.On("route", func(ev map[string]interface{}) { - bt.channel.CreateTask(func() { - bt.onRoute(fromChannel(ev["route"]).(*routeImpl)) - }) - }) - bt.channel.On("download", func(ev map[string]interface{}) { - url := ev["url"].(string) - suggestedFilename := ev["suggestedFilename"].(string) - artifact := fromChannel(ev["artifact"]).(*artifactImpl) - bt.Emit("download", newDownload(bt, url, suggestedFilename, artifact)) - }) - bt.channel.On("video", func(params map[string]interface{}) { - artifact := fromChannel(params["artifact"]).(*artifactImpl) - bt.Video().(*videoImpl).artifactReady(artifact) - }) - bt.channel.On("webSocket", func(ev map[string]interface{}) { - bt.Emit("websocket", fromChannel(ev["webSocket"]).(*webSocketImpl)) - }) - bt.channel.On("webSocketRoute", func(ev map[string]interface{}) { - bt.channel.CreateTask(func() { - bt.onWebSocketRoute(fromChannel(ev["webSocketRoute"]).(*webSocketRouteImpl)) - }) - }) - - bt.channel.On("worker", func(ev map[string]interface{}) { - bt.onWorker(fromChannel(ev["worker"]).(*workerImpl)) - }) - bt.closedOrCrashed = make(chan error, 1) - bt.OnClose(func(Page) { - select { - case bt.closedOrCrashed <- bt.closeErrorWithReason(): - default: - } - }) - bt.OnCrash(func(Page) { - select { - case bt.closedOrCrashed <- ErrTargetClosed: - default: - } - }) - bt.setEventSubscriptionMapping(map[string]string{ - "console": "console", - "dialog": "dialog", - "request": "request", - "response": "response", - "requestfinished": "requestFinished", - "responsefailed": "responseFailed", - "filechooser": "fileChooser", - }) - - return bt -} - -func (p *pageImpl) closeErrorWithReason() error { - if p.closeReason != nil { - return targetClosedError(p.closeReason) - } - return targetClosedError(p.browserContext.effectiveCloseReason()) -} - -func (p *pageImpl) onBinding(binding *bindingCallImpl) { - function, ok := p.bindings.Load(binding.initializer["name"].(string)) - if !ok || function == nil { - return - } - go binding.Call(function) -} - -func (p *pageImpl) onFrameAttached(frame *frameImpl) { - frame.page = p - p.frames = append(p.frames, frame) - p.Emit("frameattached", frame) -} - -func (p *pageImpl) onFrameDetached(frame *frameImpl) { - frame.detached = true - frames := make([]Frame, 0) - for i := 0; i < len(p.frames); i++ { - if p.frames[i] != frame { - frames = append(frames, frame) - } - } - if len(frames) != len(p.frames) { - p.frames = frames - } - p.Emit("framedetached", frame) -} - -func (p *pageImpl) onRoute(route *routeImpl) { - p.Lock() - route.context = p.browserContext - routes := make([]*routeHandlerEntry, len(p.routes)) - copy(routes, p.routes) - p.Unlock() - - checkInterceptionIfNeeded := func() { - p.Lock() - defer p.Unlock() - if len(p.routes) == 0 { - _, err := p.connection.WrapAPICall(func() (interface{}, error) { - err := p.updateInterceptionPatterns() - return nil, err - }, true) - if err != nil { - logger.Error("could not update interception patterns", "error", err) - } - } - } - - url := route.Request().URL() - for _, handlerEntry := range routes { - // If the page was closed we stall all requests right away. - if p.closeWasCalled || p.browserContext.closeWasCalled { - return - } - if !handlerEntry.Matches(url) { - continue - } - if !slices.ContainsFunc(p.routes, func(entry *routeHandlerEntry) bool { - return entry == handlerEntry - }) { - continue - } - if handlerEntry.WillExceed() { - p.routes = slices.DeleteFunc(p.routes, func(rhe *routeHandlerEntry) bool { - return rhe == handlerEntry - }) - } - handled := handlerEntry.Handle(route) - checkInterceptionIfNeeded() - - if <-handled { - return - } - } - p.browserContext.onRoute(route) -} - -func (p *pageImpl) updateInterceptionPatterns() error { - patterns := prepareInterceptionPatterns(p.routes) - _, err := p.channel.Send("setNetworkInterceptionPatterns", map[string]interface{}{ - "patterns": patterns, - }) - return err -} - -func (p *pageImpl) onWorker(worker *workerImpl) { - p.workers = append(p.workers, worker) - worker.page = p - p.Emit("worker", worker) -} - -func (p *pageImpl) onClose() { - p.isClosed = true - newPages := []Page{} - newBackgoundPages := []Page{} - if p.browserContext != nil { - p.browserContext.Lock() - for _, page := range p.browserContext.pages { - if page != p { - newPages = append(newPages, page) - } - } - for _, page := range p.browserContext.backgroundPages { - if page != p { - newBackgoundPages = append(newBackgoundPages, page) - } - } - p.browserContext.pages = newPages - p.browserContext.backgroundPages = newBackgoundPages - p.browserContext.Unlock() - } - p.disposeHarRouters() - p.Emit("close", p) -} - -func (p *pageImpl) SetInputFiles(selector string, files interface{}, options ...PageSetInputFilesOptions) error { - if len(options) == 1 { - return p.mainFrame.SetInputFiles(selector, files, FrameSetInputFilesOptions(options[0])) - } - return p.mainFrame.SetInputFiles(selector, files) -} - -func (p *pageImpl) Check(selector string, options ...PageCheckOptions) error { - if len(options) == 1 { - return p.mainFrame.Check(selector, FrameCheckOptions(options[0])) - } - return p.mainFrame.Check(selector) -} - -func (p *pageImpl) Uncheck(selector string, options ...PageUncheckOptions) error { - if len(options) == 1 { - return p.mainFrame.Uncheck(selector, FrameUncheckOptions(options[0])) - } - return p.mainFrame.Uncheck(selector) -} - -func (p *pageImpl) WaitForTimeout(timeout float64) { - p.mainFrame.WaitForTimeout(timeout) -} - -func (p *pageImpl) WaitForFunction(expression string, arg interface{}, options ...PageWaitForFunctionOptions) (JSHandle, error) { - if len(options) == 1 { - return p.mainFrame.WaitForFunction(expression, arg, FrameWaitForFunctionOptions(options[0])) - } - return p.mainFrame.WaitForFunction(expression, arg) -} - -func (p *pageImpl) Dblclick(expression string, options ...PageDblclickOptions) error { - if len(options) == 1 { - return p.mainFrame.Dblclick(expression, FrameDblclickOptions(options[0])) - } - return p.mainFrame.Dblclick(expression) -} - -func (p *pageImpl) Focus(expression string, options ...PageFocusOptions) error { - if len(options) == 1 { - return p.mainFrame.Focus(expression, FrameFocusOptions(options[0])) - } - return p.mainFrame.Focus(expression) -} - -func (p *pageImpl) TextContent(selector string, options ...PageTextContentOptions) (string, error) { - if len(options) == 1 { - return p.mainFrame.TextContent(selector, FrameTextContentOptions(options[0])) - } - return p.mainFrame.TextContent(selector) -} - -func (p *pageImpl) Video() Video { - p.Lock() - defer p.Unlock() - - if p.video == nil { - p.video = newVideo(p) - } - return p.video -} - -func (p *pageImpl) Tap(selector string, options ...PageTapOptions) error { - if len(options) == 1 { - return p.mainFrame.Tap(selector, FrameTapOptions(options[0])) - } - return p.mainFrame.Tap(selector) -} - -func (p *pageImpl) ExposeFunction(name string, binding ExposedFunction) error { - return p.ExposeBinding(name, func(source *BindingSource, args ...interface{}) interface{} { - return binding(args...) - }) -} - -func (p *pageImpl) ExposeBinding(name string, binding BindingCallFunction, handle ...bool) error { - needsHandle := false - if len(handle) == 1 { - needsHandle = handle[0] - } - if _, ok := p.bindings.Load(name); ok { - return fmt.Errorf("Function '%s' has been already registered", name) - } - if _, ok := p.browserContext.bindings.Load(name); ok { - return fmt.Errorf("Function '%s' has been already registered in the browser context", name) - } - _, err := p.channel.Send("exposeBinding", map[string]interface{}{ - "name": name, - "needsHandle": needsHandle, - }) - if err != nil { - return err - } - p.bindings.Store(name, binding) - return nil -} - -func (p *pageImpl) SelectOption(selector string, values SelectOptionValues, options ...PageSelectOptionOptions) ([]string, error) { - if len(options) == 1 { - return p.mainFrame.SelectOption(selector, values, FrameSelectOptionOptions(options[0])) - } - return p.mainFrame.SelectOption(selector, values) -} - -func (p *pageImpl) IsChecked(selector string, options ...PageIsCheckedOptions) (bool, error) { - if len(options) == 1 { - return p.mainFrame.IsChecked(selector, FrameIsCheckedOptions(options[0])) - } - return p.mainFrame.IsChecked(selector) -} - -func (p *pageImpl) IsDisabled(selector string, options ...PageIsDisabledOptions) (bool, error) { - if len(options) == 1 { - return p.mainFrame.IsDisabled(selector, FrameIsDisabledOptions(options[0])) - } - return p.mainFrame.IsDisabled(selector) -} - -func (p *pageImpl) IsEditable(selector string, options ...PageIsEditableOptions) (bool, error) { - if len(options) == 1 { - return p.mainFrame.IsEditable(selector, FrameIsEditableOptions(options[0])) - } - return p.mainFrame.IsEditable(selector) -} - -func (p *pageImpl) IsEnabled(selector string, options ...PageIsEnabledOptions) (bool, error) { - if len(options) == 1 { - return p.mainFrame.IsEnabled(selector, FrameIsEnabledOptions(options[0])) - } - return p.mainFrame.IsEnabled(selector) -} - -func (p *pageImpl) IsHidden(selector string, options ...PageIsHiddenOptions) (bool, error) { - if len(options) == 1 { - return p.mainFrame.IsHidden(selector, FrameIsHiddenOptions(options[0])) - } - return p.mainFrame.IsHidden(selector) -} - -func (p *pageImpl) IsVisible(selector string, options ...PageIsVisibleOptions) (bool, error) { - if len(options) == 1 { - return p.mainFrame.IsVisible(selector, FrameIsVisibleOptions(options[0])) - } - return p.mainFrame.IsVisible(selector) -} - -func (p *pageImpl) DragAndDrop(source, target string, options ...PageDragAndDropOptions) error { - if len(options) == 1 { - return p.mainFrame.DragAndDrop(source, target, FrameDragAndDropOptions(options[0])) - } - return p.mainFrame.DragAndDrop(source, target) -} - -func (p *pageImpl) Pause() (err error) { - defaultNavigationTimout := p.browserContext.timeoutSettings.DefaultNavigationTimeout() - defaultTimeout := p.browserContext.timeoutSettings.DefaultTimeout() - p.browserContext.SetDefaultNavigationTimeout(0) - p.browserContext.SetDefaultTimeout(0) - select { - case err = <-p.closedOrCrashed: - case err = <-p.browserContext.pause(): - } - if err != nil { - return err - } - p.browserContext.setDefaultNavigationTimeoutImpl(defaultNavigationTimout) - p.browserContext.setDefaultTimeoutImpl(defaultTimeout) - return -} - -func (p *pageImpl) InputValue(selector string, options ...PageInputValueOptions) (string, error) { - if len(options) == 1 { - return p.mainFrame.InputValue(selector, FrameInputValueOptions(options[0])) - } - return p.mainFrame.InputValue(selector) -} - -func (p *pageImpl) WaitForURL(url interface{}, options ...PageWaitForURLOptions) error { - if len(options) == 1 { - return p.mainFrame.WaitForURL(url, FrameWaitForURLOptions(options[0])) - } - return p.mainFrame.WaitForURL(url) -} - -func (p *pageImpl) SetChecked(selector string, checked bool, options ...PageSetCheckedOptions) error { - if len(options) == 1 { - return p.mainFrame.SetChecked(selector, checked, FrameSetCheckedOptions(options[0])) - } - return p.mainFrame.SetChecked(selector, checked) -} - -func (p *pageImpl) Locator(selector string, options ...PageLocatorOptions) Locator { - var option FrameLocatorOptions - if len(options) == 1 { - option = FrameLocatorOptions(options[0]) - } - return p.mainFrame.Locator(selector, option) -} - -func (p *pageImpl) GetByAltText(text interface{}, options ...PageGetByAltTextOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return p.Locator(getByAltTextSelector(text, exact)) -} - -func (p *pageImpl) GetByLabel(text interface{}, options ...PageGetByLabelOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return p.Locator(getByLabelSelector(text, exact)) -} - -func (p *pageImpl) GetByPlaceholder(text interface{}, options ...PageGetByPlaceholderOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return p.Locator(getByPlaceholderSelector(text, exact)) -} - -func (p *pageImpl) GetByRole(role AriaRole, options ...PageGetByRoleOptions) Locator { - if len(options) == 1 { - return p.Locator(getByRoleSelector(role, LocatorGetByRoleOptions(options[0]))) - } - return p.Locator(getByRoleSelector(role)) -} - -func (p *pageImpl) GetByTestId(testId interface{}) Locator { - return p.Locator(getByTestIdSelector(getTestIdAttributeName(), testId)) -} - -func (p *pageImpl) GetByText(text interface{}, options ...PageGetByTextOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return p.Locator(getByTextSelector(text, exact)) -} - -func (p *pageImpl) GetByTitle(text interface{}, options ...PageGetByTitleOptions) Locator { - exact := false - if len(options) == 1 { - if *options[0].Exact { - exact = true - } - } - return p.Locator(getByTitleSelector(text, exact)) -} - -func (p *pageImpl) FrameLocator(selector string) FrameLocator { - return p.mainFrame.FrameLocator(selector) -} - -func (p *pageImpl) OnClose(fn func(Page)) { - p.On("close", fn) -} - -func (p *pageImpl) OnConsole(fn func(ConsoleMessage)) { - p.On("console", fn) -} - -func (p *pageImpl) OnCrash(fn func(Page)) { - p.On("crash", fn) -} - -func (p *pageImpl) OnDialog(fn func(Dialog)) { - p.On("dialog", fn) -} - -func (p *pageImpl) OnDOMContentLoaded(fn func(Page)) { - p.On("domcontentloaded", fn) -} - -func (p *pageImpl) OnDownload(fn func(Download)) { - p.On("download", fn) -} - -func (p *pageImpl) OnFileChooser(fn func(FileChooser)) { - p.On("filechooser", fn) -} - -func (p *pageImpl) OnFrameAttached(fn func(Frame)) { - p.On("frameattached", fn) -} - -func (p *pageImpl) OnFrameDetached(fn func(Frame)) { - p.On("framedetached", fn) -} - -func (p *pageImpl) OnFrameNavigated(fn func(Frame)) { - p.On("framenavigated", fn) -} - -func (p *pageImpl) OnLoad(fn func(Page)) { - p.On("load", fn) -} - -func (p *pageImpl) OnPageError(fn func(error)) { - p.On("pageerror", fn) -} - -func (p *pageImpl) OnPopup(fn func(Page)) { - p.On("popup", fn) -} - -func (p *pageImpl) OnRequest(fn func(Request)) { - p.On("request", fn) -} - -func (p *pageImpl) OnRequestFailed(fn func(Request)) { - p.On("requestfailed", fn) -} - -func (p *pageImpl) OnRequestFinished(fn func(Request)) { - p.On("requestfinished", fn) -} - -func (p *pageImpl) OnResponse(fn func(Response)) { - p.On("response", fn) -} - -func (p *pageImpl) OnWebSocket(fn func(WebSocket)) { - p.On("websocket", fn) -} - -func (p *pageImpl) OnWorker(fn func(Worker)) { - p.On("worker", fn) -} - -func (p *pageImpl) RequestGC() error { - _, err := p.channel.Send("requestGC") - return err -} - -func (p *pageImpl) RouteWebSocket(url interface{}, handler func(WebSocketRoute)) error { - p.Lock() - defer p.Unlock() - p.webSocketRoutes = slices.Insert(p.webSocketRoutes, 0, newWebSocketRouteHandler(newURLMatcher(url, p.browserContext.options.BaseURL, true), handler)) - - return p.updateWebSocketInterceptionPatterns() -} - -func (p *pageImpl) onWebSocketRoute(wr WebSocketRoute) { - p.Lock() - index := slices.IndexFunc(p.webSocketRoutes, func(r *webSocketRouteHandler) bool { - return r.Matches(wr.URL()) - }) - if index == -1 { - p.Unlock() - p.browserContext.onWebSocketRoute(wr) - return - } - handler := p.webSocketRoutes[index] - p.Unlock() - handler.Handle(wr) -} - -func (p *pageImpl) updateWebSocketInterceptionPatterns() error { - patterns := prepareWebSocketRouteHandlerInterceptionPatterns(p.webSocketRoutes) - _, err := p.channel.Send("setWebSocketInterceptionPatterns", map[string]interface{}{ - "patterns": patterns, - }) - return err -} diff --git a/vendor/github.com/playwright-community/playwright-go/page_assertions.go b/vendor/github.com/playwright-community/playwright-go/page_assertions.go deleted file mode 100644 index 43bd0dc..0000000 --- a/vendor/github.com/playwright-community/playwright-go/page_assertions.go +++ /dev/null @@ -1,70 +0,0 @@ -package playwright - -import ( - "net/url" - "path" -) - -type pageAssertionsImpl struct { - assertionsBase - actualPage Page -} - -func newPageAssertions(page Page, isNot bool, defaultTimeout *float64) *pageAssertionsImpl { - return &pageAssertionsImpl{ - assertionsBase: assertionsBase{ - actualLocator: page.Locator(":root"), - isNot: isNot, - defaultTimeout: defaultTimeout, - }, - actualPage: page, - } -} - -func (pa *pageAssertionsImpl) ToHaveTitle(titleOrRegExp interface{}, options ...PageAssertionsToHaveTitleOptions) error { - var timeout *float64 - if len(options) == 1 { - timeout = options[0].Timeout - } - expectedValues, err := toExpectedTextValues([]interface{}{titleOrRegExp}, false, true, nil) - if err != nil { - return err - } - return pa.expect( - "to.have.title", - frameExpectOptions{ExpectedText: expectedValues, Timeout: timeout}, - titleOrRegExp, - "Page title expected to be", - ) -} - -func (pa *pageAssertionsImpl) ToHaveURL(urlOrRegExp interface{}, options ...PageAssertionsToHaveURLOptions) error { - var timeout *float64 - var ignoreCase *bool - if len(options) == 1 { - timeout = options[0].Timeout - ignoreCase = options[0].IgnoreCase - } - - baseURL := pa.actualPage.Context().(*browserContextImpl).options.BaseURL - if urlPath, ok := urlOrRegExp.(string); ok && baseURL != nil { - u, _ := url.Parse(*baseURL) - u.Path = path.Join(u.Path, urlPath) - urlOrRegExp = u.String() - } - - expectedValues, err := toExpectedTextValues([]interface{}{urlOrRegExp}, false, false, ignoreCase) - if err != nil { - return err - } - return pa.expect( - "to.have.url", - frameExpectOptions{ExpectedText: expectedValues, Timeout: timeout}, - urlOrRegExp, - "Page URL expected to be", - ) -} - -func (pa *pageAssertionsImpl) Not() PageAssertions { - return newPageAssertions(pa.actualPage, true, pa.defaultTimeout) -} diff --git a/vendor/github.com/playwright-community/playwright-go/playwright.go b/vendor/github.com/playwright-community/playwright-go/playwright.go deleted file mode 100644 index 805ac14..0000000 --- a/vendor/github.com/playwright-community/playwright-go/playwright.go +++ /dev/null @@ -1,64 +0,0 @@ -// Package playwright is a library to automate Chromium, Firefox and WebKit with -// a single API. Playwright is built to enable cross-browser web automation that -// is ever-green, capable, reliable and fast. -package playwright - -// DeviceDescriptor represents a single device -type DeviceDescriptor struct { - UserAgent string `json:"userAgent"` - Viewport *Size `json:"viewport"` - Screen *Size `json:"screen"` - DeviceScaleFactor float64 `json:"deviceScaleFactor"` - IsMobile bool `json:"isMobile"` - HasTouch bool `json:"hasTouch"` - DefaultBrowserType string `json:"defaultBrowserType"` -} - -// Playwright represents a Playwright instance -type Playwright struct { - channelOwner - Selectors Selectors - Chromium BrowserType - Firefox BrowserType - WebKit BrowserType - Request APIRequest - Devices map[string]*DeviceDescriptor -} - -// Stop stops the Playwright instance -func (p *Playwright) Stop() error { - return p.connection.Stop() -} - -func (p *Playwright) setSelectors(selectors Selectors) { - selectorsOwner := fromChannel(p.initializer["selectors"]).(*selectorsOwnerImpl) - p.Selectors.(*selectorsImpl).removeChannel(selectorsOwner) - p.Selectors = selectors - p.Selectors.(*selectorsImpl).addChannel(selectorsOwner) -} - -func newPlaywright(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *Playwright { - pw := &Playwright{ - Selectors: newSelectorsImpl(), - Chromium: fromChannel(initializer["chromium"]).(*browserTypeImpl), - Firefox: fromChannel(initializer["firefox"]).(*browserTypeImpl), - WebKit: fromChannel(initializer["webkit"]).(*browserTypeImpl), - Devices: make(map[string]*DeviceDescriptor), - } - pw.createChannelOwner(pw, parent, objectType, guid, initializer) - pw.Request = newApiRequestImpl(pw) - pw.Chromium.(*browserTypeImpl).playwright = pw - pw.Firefox.(*browserTypeImpl).playwright = pw - pw.WebKit.(*browserTypeImpl).playwright = pw - selectorsOwner := fromChannel(initializer["selectors"]).(*selectorsOwnerImpl) - pw.Selectors.(*selectorsImpl).addChannel(selectorsOwner) - pw.connection.afterClose = func() { - pw.Selectors.(*selectorsImpl).removeChannel(selectorsOwner) - } - if pw.connection.localUtils != nil { - pw.Devices = pw.connection.localUtils.Devices - } - return pw -} - -//go:generate bash scripts/generate-api.sh diff --git a/vendor/github.com/playwright-community/playwright-go/request.go b/vendor/github.com/playwright-community/playwright-go/request.go deleted file mode 100644 index 43a3161..0000000 --- a/vendor/github.com/playwright-community/playwright-go/request.go +++ /dev/null @@ -1,274 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "encoding/json" - "fmt" -) - -type serializedFallbackOverrides struct { - URL *string - Method *string - Headers map[string]string - PostDataBuffer []byte -} - -type requestImpl struct { - channelOwner - timing *RequestTiming - provisionalHeaders *rawHeaders - allHeaders *rawHeaders - redirectedFrom Request - redirectedTo Request - failureText string - fallbackOverrides *serializedFallbackOverrides -} - -func (r *requestImpl) URL() string { - if r.fallbackOverrides.URL != nil { - return *r.fallbackOverrides.URL - } - return r.initializer["url"].(string) -} - -func (r *requestImpl) ResourceType() string { - return r.initializer["resourceType"].(string) -} - -func (r *requestImpl) Method() string { - if r.fallbackOverrides.Method != nil { - return *r.fallbackOverrides.Method - } - return r.initializer["method"].(string) -} - -func (r *requestImpl) PostData() (string, error) { - body, err := r.PostDataBuffer() - if err != nil { - return "", err - } - return string(body), err -} - -func (r *requestImpl) PostDataJSON(v interface{}) error { - body, err := r.PostDataBuffer() - if err != nil { - return err - } - return json.Unmarshal(body, v) -} - -func (r *requestImpl) PostDataBuffer() ([]byte, error) { - if r.fallbackOverrides.PostDataBuffer != nil { - return r.fallbackOverrides.PostDataBuffer, nil - } - if _, ok := r.initializer["postData"]; !ok { - return nil, nil - } - return base64.StdEncoding.DecodeString(r.initializer["postData"].(string)) -} - -func (r *requestImpl) Headers() map[string]string { - if r.fallbackOverrides.Headers != nil { - return newRawHeaders(serializeMapToNameAndValue(r.fallbackOverrides.Headers)).Headers() - } - return r.provisionalHeaders.Headers() -} - -func (r *requestImpl) Response() (Response, error) { - channel, err := r.channel.Send("response") - if err != nil { - return nil, err - } - channelOwner := fromNullableChannel(channel) - if channelOwner == nil { - // no response - return nil, nil - } - return channelOwner.(*responseImpl), nil -} - -func (r *requestImpl) Frame() Frame { - channel, ok := r.initializer["frame"] - if !ok { - // Service Worker requests do not have an associated frame. - return nil - } - frame := fromChannel(channel).(*frameImpl) - if frame.page == nil { - // Frame for this navigation request is not available, because the request - // was issued before the frame is created. You can check whether the request - // is a navigation request by calling IsNavigationRequest() method. - return nil - } - return frame -} - -func (r *requestImpl) IsNavigationRequest() bool { - return r.initializer["isNavigationRequest"].(bool) -} - -func (r *requestImpl) RedirectedFrom() Request { - return r.redirectedFrom -} - -func (r *requestImpl) RedirectedTo() Request { - return r.redirectedTo -} - -func (r *requestImpl) Failure() error { - if r.failureText == "" { - return nil - } - return fmt.Errorf("%v", r.failureText) -} - -func (r *requestImpl) Timing() *RequestTiming { - return r.timing -} - -func (r *requestImpl) AllHeaders() (map[string]string, error) { - headers, err := r.ActualHeaders() - if err != nil { - return nil, err - } - return headers.Headers(), nil -} - -func (r *requestImpl) HeadersArray() ([]NameValue, error) { - headers, err := r.ActualHeaders() - if err != nil { - return nil, err - } - return headers.HeadersArray(), nil -} - -func (r *requestImpl) HeaderValue(name string) (string, error) { - headers, err := r.ActualHeaders() - if err != nil { - return "", err - } - return headers.Get(name), err -} - -func (r *requestImpl) HeaderValues(name string) ([]string, error) { - headers, err := r.ActualHeaders() - if err != nil { - return []string{}, err - } - return headers.GetAll(name), err -} - -func (r *requestImpl) ActualHeaders() (*rawHeaders, error) { - if r.fallbackOverrides.Headers != nil { - return newRawHeaders(serializeMapToNameAndValue(r.fallbackOverrides.Headers)), nil - } - if r.allHeaders == nil { - response, err := r.Response() - if err != nil { - return nil, err - } - if response == nil { - return r.provisionalHeaders, nil - } - headers, err := r.channel.Send("rawRequestHeaders") - if err != nil { - return nil, err - } - r.allHeaders = newRawHeaders(headers) - } - return r.allHeaders, nil -} - -func (r *requestImpl) ServiceWorker() Worker { - channel, ok := r.initializer["serviceWorker"] - if !ok { - return nil - } - return fromChannel(channel).(*workerImpl) -} - -func (r *requestImpl) Sizes() (*RequestSizesResult, error) { - response, err := r.Response() - if err != nil { - return nil, err - } - sizes, err := response.(*responseImpl).channel.Send("sizes") - if err != nil { - return nil, err - } - result := &RequestSizesResult{} - remapMapToStruct(sizes, result) - return result, nil -} - -func (r *requestImpl) applyFallbackOverrides(options RouteFallbackOptions) { - if options.URL != nil { - r.fallbackOverrides.URL = options.URL - } - if options.Method != nil { - r.fallbackOverrides.Method = options.Method - } - r.fallbackOverrides.Headers = options.Headers - if options.PostData != nil { - switch v := options.PostData.(type) { - case string: - r.fallbackOverrides.PostDataBuffer = []byte(v) - case []byte: - r.fallbackOverrides.PostDataBuffer = v - } - } -} - -func (r *requestImpl) targetClosed() <-chan error { - page := r.safePage() - if page == nil { - return make(<-chan error, 1) - } - return page.closedOrCrashed -} - -func (r *requestImpl) setResponseEndTiming(t float64) { - r.timing.ResponseEnd = t - if r.timing.ResponseStart == -1 { - r.timing.ResponseStart = t - } -} - -func (r *requestImpl) safePage() *pageImpl { - channel := fromNullableChannel(r.initializer["frame"]) - if channel == nil { - return nil - } - frame, ok := channel.(*frameImpl) - if !ok { - return nil - } - return frame.page -} - -func newRequest(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *requestImpl { - req := &requestImpl{} - req.createChannelOwner(req, parent, objectType, guid, initializer) - redirectedFrom := fromNullableChannel(initializer["redirectedFrom"]) - if redirectedFrom != nil { - req.redirectedFrom = redirectedFrom.(*requestImpl) - } - if req.redirectedFrom != nil { - req.redirectedFrom.(*requestImpl).redirectedTo = req - } - req.timing = &RequestTiming{ - StartTime: 0, - DomainLookupStart: -1, - DomainLookupEnd: -1, - ConnectStart: -1, - SecureConnectionStart: -1, - ConnectEnd: -1, - RequestStart: -1, - ResponseStart: -1, - ResponseEnd: -1, - } - req.provisionalHeaders = newRawHeaders(req.initializer["headers"]) - req.fallbackOverrides = &serializedFallbackOverrides{} - return req -} diff --git a/vendor/github.com/playwright-community/playwright-go/response.go b/vendor/github.com/playwright-community/playwright-go/response.go deleted file mode 100644 index 8f26d6d..0000000 --- a/vendor/github.com/playwright-community/playwright-go/response.go +++ /dev/null @@ -1,162 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "encoding/json" -) - -type responseImpl struct { - channelOwner - request *requestImpl - provisionalHeaders *rawHeaders - rawHeaders *rawHeaders - finished chan error -} - -func (r *responseImpl) FromServiceWorker() bool { - return r.initializer["fromServiceWorker"].(bool) -} - -func (r *responseImpl) URL() string { - return r.initializer["url"].(string) -} - -func (r *responseImpl) Ok() bool { - return r.Status() == 0 || (r.Status() >= 200 && r.Status() <= 299) -} - -func (r *responseImpl) Status() int { - return int(r.initializer["status"].(float64)) -} - -func (r *responseImpl) StatusText() string { - return r.initializer["statusText"].(string) -} - -func (r *responseImpl) Headers() map[string]string { - return r.provisionalHeaders.Headers() -} - -func (r *responseImpl) Finished() error { - select { - case err := <-r.request.targetClosed(): - return err - case err := <-r.finished: - return err - } -} - -func (r *responseImpl) Body() ([]byte, error) { - b64Body, err := r.channel.Send("body") - if err != nil { - return nil, err - } - return base64.StdEncoding.DecodeString(b64Body.(string)) -} - -func (r *responseImpl) Text() (string, error) { - body, err := r.Body() - if err != nil { - return "", err - } - return string(body), nil -} - -func (r *responseImpl) JSON(v interface{}) error { - body, err := r.Body() - if err != nil { - return err - } - return json.Unmarshal(body, v) -} - -func (r *responseImpl) Request() Request { - return r.request -} - -func (r *responseImpl) Frame() Frame { - return r.request.Frame() -} - -func (r *responseImpl) AllHeaders() (map[string]string, error) { - headers, err := r.ActualHeaders() - if err != nil { - return nil, err - } - return headers.Headers(), nil -} - -func (r *responseImpl) HeadersArray() ([]NameValue, error) { - headers, err := r.ActualHeaders() - if err != nil { - return nil, err - } - return headers.HeadersArray(), nil -} - -func (r *responseImpl) HeaderValue(name string) (string, error) { - headers, err := r.ActualHeaders() - if err != nil { - return "", err - } - return headers.Get(name), err -} - -func (r *responseImpl) HeaderValues(name string) ([]string, error) { - headers, err := r.ActualHeaders() - if err != nil { - return []string{}, err - } - return headers.GetAll(name), err -} - -func (r *responseImpl) ActualHeaders() (*rawHeaders, error) { - if r.rawHeaders == nil { - headers, err := r.channel.Send("rawResponseHeaders") - if err != nil { - return nil, err - } - r.rawHeaders = newRawHeaders(headers) - } - return r.rawHeaders, nil -} - -func (r *responseImpl) SecurityDetails() (*ResponseSecurityDetailsResult, error) { - details, err := r.channel.Send("securityDetails") - if err != nil { - return nil, err - } - result := &ResponseSecurityDetailsResult{} - remapMapToStruct(details.(map[string]interface{}), result) - return result, nil -} - -func (r *responseImpl) ServerAddr() (*ResponseServerAddrResult, error) { - addr, err := r.channel.Send("serverAddr") - if err != nil { - return nil, err - } - result := &ResponseServerAddrResult{} - remapMapToStruct(addr, result) - return result, nil -} - -func newResponse(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *responseImpl { - resp := &responseImpl{} - resp.createChannelOwner(resp, parent, objectType, guid, initializer) - timing := resp.initializer["timing"].(map[string]interface{}) - resp.request = fromChannel(resp.initializer["request"]).(*requestImpl) - resp.request.timing = &RequestTiming{ - StartTime: timing["startTime"].(float64), - DomainLookupStart: timing["domainLookupStart"].(float64), - DomainLookupEnd: timing["domainLookupEnd"].(float64), - ConnectStart: timing["connectStart"].(float64), - SecureConnectionStart: timing["secureConnectionStart"].(float64), - ConnectEnd: timing["connectEnd"].(float64), - RequestStart: timing["requestStart"].(float64), - ResponseStart: timing["responseStart"].(float64), - } - resp.provisionalHeaders = newRawHeaders(resp.initializer["headers"]) - resp.finished = make(chan error, 1) - return resp -} diff --git a/vendor/github.com/playwright-community/playwright-go/route.go b/vendor/github.com/playwright-community/playwright-go/route.go deleted file mode 100644 index c9e6ee9..0000000 --- a/vendor/github.com/playwright-community/playwright-go/route.go +++ /dev/null @@ -1,270 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "errors" - "net/http" - "os" - "reflect" - "strconv" - "strings" -) - -type routeImpl struct { - channelOwner - handling *chan bool - context *browserContextImpl - didThrow bool -} - -func (r *routeImpl) startHandling() chan bool { - r.Lock() - defer r.Unlock() - handling := make(chan bool, 1) - r.handling = &handling - return handling -} - -func (r *routeImpl) reportHandled(done bool) { - r.Lock() - defer r.Unlock() - if r.handling != nil { - handling := *r.handling - r.handling = nil - handling <- done - } -} - -func (r *routeImpl) checkNotHandled() error { - r.RLock() - defer r.RUnlock() - if r.handling == nil { - return errors.New("Route is already handled!") - } - return nil -} - -func (r *routeImpl) Request() Request { - return fromChannel(r.initializer["request"]).(*requestImpl) -} - -func unpackOptionalArgument(input interface{}) interface{} { - inputValue := reflect.ValueOf(input) - if inputValue.Kind() != reflect.Slice { - panic("Needs to be a slice") - } - if inputValue.Len() == 0 { - return nil - } - return inputValue.Index(0).Interface() -} - -func (r *routeImpl) Abort(errorCode ...string) error { - return r.handleRoute(func() error { - return r.raceWithPageClose(func() error { - _, err := r.channel.Send("abort", map[string]interface{}{ - "errorCode": unpackOptionalArgument(errorCode), - }) - return err - }) - }) -} - -func (r *routeImpl) raceWithPageClose(f func() error) error { - errChan := make(chan error, 1) - go func() { - errChan <- f() - }() - - select { - case <-r.Request().(*requestImpl).targetClosed(): - // upstream does not throw the err - return nil - case err := <-errChan: - return err - } -} - -func (r *routeImpl) Fulfill(options ...RouteFulfillOptions) error { - return r.handleRoute(func() error { - return r.innerFulfill(options...) - }) -} - -func (r *routeImpl) handleRoute(cb func() error) error { - err := r.checkNotHandled() - if err != nil { - return err - } - if err := cb(); err != nil { - r.didThrow = true - return err - } - r.reportHandled(true) - return nil -} - -func (r *routeImpl) innerFulfill(options ...RouteFulfillOptions) error { - err := r.checkNotHandled() - if err != nil { - return err - } - option := RouteFulfillOptions{} - if len(options) == 1 { - option = options[0] - } - overrides := map[string]interface{}{ - "status": 200, - } - headers := make(map[string]string) - - if option.Response != nil { - overrides["status"] = option.Response.Status() - headers = option.Response.Headers() - response, ok := option.Response.(*apiResponseImpl) - if option.Body == nil && option.Path == nil && ok && response.request.connection == r.connection { - overrides["fetchResponseUid"] = response.fetchUid() - } else { - option.Body, _ = option.Response.Body() - } - option.Response = nil - } - if option.Status != nil { - overrides["status"] = *option.Status - option.Status = nil - } - - length := 0 - isBase64 := false - var fileContentType string - if _, ok := option.Body.(string); ok { - isBase64 = false - } else if body, ok := option.Body.([]byte); ok { - option.Body = base64.StdEncoding.EncodeToString(body) - length = len(body) - isBase64 = true - } else if option.Path != nil { - content, err := os.ReadFile(*option.Path) - if err != nil { - return err - } - fileContentType = http.DetectContentType(content) - option.Body = base64.StdEncoding.EncodeToString(content) - isBase64 = true - length = len(content) - } - - if option.Headers != nil { - headers = make(map[string]string) - for key, val := range option.Headers { - headers[strings.ToLower(key)] = val - } - option.Headers = nil - } - if option.ContentType != nil { - headers["content-type"] = *option.ContentType - option.ContentType = nil - } else if option.Path != nil { - headers["content-type"] = fileContentType - } - if _, ok := headers["content-length"]; !ok && length > 0 { - headers["content-length"] = strconv.Itoa(length) - } - overrides["headers"] = serializeMapToNameAndValue(headers) - overrides["isBase64"] = isBase64 - - option.Path = nil - err = r.raceWithPageClose(func() error { - _, err := r.channel.Send("fulfill", option, overrides) - return err - }) - return err -} - -func (r *routeImpl) Fallback(options ...RouteFallbackOptions) error { - err := r.checkNotHandled() - if err != nil { - return err - } - opt := RouteFallbackOptions{} - if len(options) == 1 { - opt = options[0] - } - r.Request().(*requestImpl).applyFallbackOverrides(opt) - r.reportHandled(false) - return nil -} - -func (r *routeImpl) Fetch(options ...RouteFetchOptions) (APIResponse, error) { - opt := &APIRequestContextFetchOptions{} - url := "" - if len(options) == 1 { - err := assignStructFields(opt, options[0], true) - if err != nil { - return nil, err - } - opt.Data = options[0].PostData - if options[0].URL != nil { - url = *options[0].URL - } - } - ret, err := r.connection.WrapAPICall(func() (interface{}, error) { - return r.context.request.innerFetch(url, r.Request(), *opt) - }, false) - if ret == nil { - return nil, err - } - return ret.(APIResponse), err -} - -func (r *routeImpl) Continue(options ...RouteContinueOptions) error { - option := &RouteFallbackOptions{} - if len(options) == 1 { - err := assignStructFields(option, options[0], true) - if err != nil { - return err - } - } - - return r.handleRoute(func() error { - r.Request().(*requestImpl).applyFallbackOverrides(*option) - return r.internalContinue(false) - }) -} - -func (r *routeImpl) internalContinue(isFallback bool) error { - overrides := make(map[string]interface{}) - overrides["url"] = r.Request().(*requestImpl).fallbackOverrides.URL - overrides["method"] = r.Request().(*requestImpl).fallbackOverrides.Method - headers := r.Request().(*requestImpl).fallbackOverrides.Headers - if headers != nil { - overrides["headers"] = serializeMapToNameAndValue(headers) - } - postDataBuf := r.Request().(*requestImpl).fallbackOverrides.PostDataBuffer - if postDataBuf != nil { - overrides["postData"] = base64.StdEncoding.EncodeToString(postDataBuf) - } - overrides["isFallback"] = isFallback - return r.raceWithPageClose(func() error { - _, err := r.channel.Send("continue", overrides) - return err - }) -} - -func (r *routeImpl) redirectedNavigationRequest(url string) error { - return r.handleRoute(func() error { - return r.raceWithPageClose(func() error { - _, err := r.channel.Send("redirectNavigationRequest", map[string]interface{}{ - "url": url, - }) - return err - }) - }) -} - -func newRoute(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *routeImpl { - bt := &routeImpl{} - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - bt.markAsInternalType() - return bt -} diff --git a/vendor/github.com/playwright-community/playwright-go/run.go b/vendor/github.com/playwright-community/playwright-go/run.go deleted file mode 100644 index 79ad11e..0000000 --- a/vendor/github.com/playwright-community/playwright-go/run.go +++ /dev/null @@ -1,409 +0,0 @@ -package playwright - -import ( - "archive/zip" - "bytes" - "errors" - "fmt" - "io" - "log" - "log/slog" - "net/http" - "os" - "os/exec" - "path/filepath" - "runtime" - "strings" -) - -const playwrightCliVersion = "1.52.0" - -var ( - logger = slog.Default() - playwrightCDNMirrors = []string{ - "https://playwright.azureedge.net", - "https://playwright-akamai.azureedge.net", - "https://playwright-verizon.azureedge.net", - } -) - -// PlaywrightDriver wraps the Playwright CLI of upstream Playwright. -// -// It's required for playwright-go to work. -type PlaywrightDriver struct { - Version string - options *RunOptions -} - -func NewDriver(options ...*RunOptions) (*PlaywrightDriver, error) { - transformed, err := transformRunOptions(options...) // get default values - if err != nil { - return nil, err - } - return &PlaywrightDriver{ - options: transformed, - Version: playwrightCliVersion, - }, nil -} - -func getDefaultCacheDirectory() (string, error) { - userHomeDir, err := os.UserHomeDir() - if err != nil { - return "", fmt.Errorf("could not get user home directory: %w", err) - } - switch runtime.GOOS { - case "windows": - return filepath.Join(userHomeDir, "AppData", "Local"), nil - case "darwin": - return filepath.Join(userHomeDir, "Library", "Caches"), nil - case "linux": - return filepath.Join(userHomeDir, ".cache"), nil - } - return "", errors.New("could not determine cache directory") -} - -func (d *PlaywrightDriver) isUpToDateDriver() (bool, error) { - if _, err := os.Stat(d.options.DriverDirectory); os.IsNotExist(err) { - if err := os.MkdirAll(d.options.DriverDirectory, 0o777); err != nil { - return false, fmt.Errorf("could not create driver directory: %w", err) - } - } - if _, err := os.Stat(getDriverCliJs(d.options.DriverDirectory)); os.IsNotExist(err) { - return false, nil - } else if err != nil { - return false, fmt.Errorf("could not check if driver is up2date: %w", err) - } - cmd := d.Command("--version") - output, err := cmd.Output() - if err != nil { - return false, fmt.Errorf("could not run driver: %w", err) - } - if bytes.Contains(output, []byte(d.Version)) { - return true, nil - } - // avoid triggering downloads and accidentally overwriting files - return false, fmt.Errorf("driver exists but version not %s in : %s", d.Version, d.options.DriverDirectory) -} - -// Command returns an exec.Cmd for the driver. -func (d *PlaywrightDriver) Command(arg ...string) *exec.Cmd { - cmd := exec.Command(getNodeExecutable(d.options.DriverDirectory), append([]string{getDriverCliJs(d.options.DriverDirectory)}, arg...)...) - cmd.SysProcAttr = defaultSysProcAttr - return cmd -} - -// Install downloads the driver and the browsers depending on [RunOptions]. -func (d *PlaywrightDriver) Install() error { - if err := d.DownloadDriver(); err != nil { - return fmt.Errorf("could not install driver: %w", err) - } - if d.options.SkipInstallBrowsers { - return nil - } - - d.log("Downloading browsers...") - if err := d.installBrowsers(); err != nil { - return fmt.Errorf("could not install browsers: %w", err) - } - d.log("Downloaded browsers successfully") - - return nil -} - -// Uninstall removes the driver and the browsers. -func (d *PlaywrightDriver) Uninstall() error { - d.log("Removing browsers...") - if err := d.uninstallBrowsers(); err != nil { - return fmt.Errorf("could not uninstall browsers: %w", err) - } - - d.log("Removing driver...") - if err := os.RemoveAll(d.options.DriverDirectory); err != nil { - return fmt.Errorf("could not remove driver directory: %w", err) - } - - d.log("Uninstall driver successfully") - return nil -} - -// DownloadDriver downloads the driver only -func (d *PlaywrightDriver) DownloadDriver() error { - up2Date, err := d.isUpToDateDriver() - if err != nil { - return err - } - if up2Date { - return nil - } - - d.log("Downloading driver", "path", d.options.DriverDirectory) - - body, err := downloadDriver(d.getDriverURLs()) - if err != nil { - return err - } - zipReader, err := zip.NewReader(bytes.NewReader(body), int64(len(body))) - if err != nil { - return fmt.Errorf("could not read zip content: %w", err) - } - - for _, zipFile := range zipReader.File { - zipFileDiskPath := filepath.Join(d.options.DriverDirectory, zipFile.Name) - if zipFile.FileInfo().IsDir() { - if err := os.MkdirAll(zipFileDiskPath, os.ModePerm); err != nil { - return fmt.Errorf("could not create directory: %w", err) - } - continue - } - - outFile, err := os.Create(zipFileDiskPath) - if err != nil { - return fmt.Errorf("could not create driver: %w", err) - } - file, err := zipFile.Open() - if err != nil { - return fmt.Errorf("could not open zip file: %w", err) - } - if _, err = io.Copy(outFile, file); err != nil { - return fmt.Errorf("could not copy response body to file: %w", err) - } - if err := outFile.Close(); err != nil { - return fmt.Errorf("could not close file (driver): %w", err) - } - if err := file.Close(); err != nil { - return fmt.Errorf("could not close file (zip file): %w", err) - } - if zipFile.Mode().Perm()&0o100 != 0 && runtime.GOOS != "windows" { - if err := makeFileExecutable(zipFileDiskPath); err != nil { - return fmt.Errorf("could not make executable: %w", err) - } - } - } - - d.log("Downloaded driver successfully") - - return nil -} - -func (d *PlaywrightDriver) log(msg string, args ...any) { - if d.options.Verbose { - logger.Info(msg, args...) - } -} - -func (d *PlaywrightDriver) run() (*connection, error) { - transport, err := newPipeTransport(d, d.options.Stderr) - if err != nil { - return nil, err - } - connection := newConnection(transport) - return connection, nil -} - -func (d *PlaywrightDriver) installBrowsers() error { - additionalArgs := []string{"install"} - if d.options.Browsers != nil { - additionalArgs = append(additionalArgs, d.options.Browsers...) - } - - if d.options.OnlyInstallShell { - additionalArgs = append(additionalArgs, "--only-shell") - } - - if d.options.DryRun { - additionalArgs = append(additionalArgs, "--dry-run") - } - - cmd := d.Command(additionalArgs...) - cmd.Stdout = d.options.Stdout - cmd.Stderr = d.options.Stderr - return cmd.Run() -} - -func (d *PlaywrightDriver) uninstallBrowsers() error { - cmd := d.Command("uninstall") - cmd.Stdout = d.options.Stdout - cmd.Stderr = d.options.Stderr - return cmd.Run() -} - -// RunOptions are custom options to run the driver -type RunOptions struct { - // DriverDirectory points to the playwright driver directory. - // It should have two subdirectories: node and package. - // You can also specify it using the environment variable PLAYWRIGHT_DRIVER_PATH. - // - // Default is user cache directory + "/ms-playwright-go/x.xx.xx": - // - Windows: %USERPROFILE%\AppData\Local - // - macOS: ~/Library/Caches - // - Linux: ~/.cache - DriverDirectory string - // OnlyInstallShell only downloads the headless shell. (For chromium browsers only) - OnlyInstallShell bool - SkipInstallBrowsers bool - // if not set and SkipInstallBrowsers is false, will download all browsers (chromium, firefox, webkit) - Browsers []string - Verbose bool // default true - Stdout io.Writer - Stderr io.Writer - Logger *slog.Logger - // DryRun does not install browser/dependencies. It will only print information. - DryRun bool -} - -// Install does download the driver and the browsers. -// -// Use this before playwright.Run() or use playwright cli to install the driver and browsers -func Install(options ...*RunOptions) error { - driver, err := NewDriver(options...) - if err != nil { - return fmt.Errorf("could not get driver instance: %w", err) - } - if err := driver.Install(); err != nil { - return fmt.Errorf("could not install driver: %w", err) - } - return nil -} - -// Run starts a Playwright instance. -// -// Requires the driver and the browsers to be installed before. -// Either use Install() or use playwright cli. -func Run(options ...*RunOptions) (*Playwright, error) { - driver, err := NewDriver(options...) - if err != nil { - return nil, fmt.Errorf("could not get driver instance: %w", err) - } - up2date, err := driver.isUpToDateDriver() - if err != nil || !up2date { - return nil, fmt.Errorf("please install the driver (v%s) first: %w", playwrightCliVersion, err) - } - connection, err := driver.run() - if err != nil { - return nil, err - } - playwright, err := connection.Start() - return playwright, err -} - -func transformRunOptions(options ...*RunOptions) (*RunOptions, error) { - option := &RunOptions{ - Verbose: true, - } - if len(options) == 1 { - option = options[0] - } - if option.DriverDirectory == "" { // if user did not set it, try to get it from env - option.DriverDirectory = os.Getenv("PLAYWRIGHT_DRIVER_PATH") - } - if option.DriverDirectory == "" { - cacheDirectory, err := getDefaultCacheDirectory() - if err != nil { - return nil, fmt.Errorf("could not get default cache directory: %w", err) - } - option.DriverDirectory = filepath.Join(cacheDirectory, "ms-playwright-go", playwrightCliVersion) - } - if option.Stdout == nil { - option.Stdout = os.Stdout - } - if option.Stderr == nil { - option.Stderr = os.Stderr - } else if option.Logger == nil { - log.SetOutput(option.Stderr) - } - if option.Logger != nil { - logger = option.Logger - } - return option, nil -} - -func getNodeExecutable(driverDirectory string) string { - envPath := os.Getenv("PLAYWRIGHT_NODEJS_PATH") - if envPath != "" { - return envPath - } - - node := "node" - if runtime.GOOS == "windows" { - node = "node.exe" - } - return filepath.Join(driverDirectory, node) -} - -func getDriverCliJs(driverDirectory string) string { - return filepath.Join(driverDirectory, "package", "cli.js") -} - -func (d *PlaywrightDriver) getDriverURLs() []string { - platform := "" - switch runtime.GOOS { - case "windows": - platform = "win32_x64" - case "darwin": - if runtime.GOARCH == "arm64" { - platform = "mac-arm64" - } else { - platform = "mac" - } - case "linux": - if runtime.GOARCH == "arm64" { - platform = "linux-arm64" - } else { - platform = "linux" - } - } - - baseURLs := []string{} - pattern := "%s/builds/driver/playwright-%s-%s.zip" - if !d.isReleaseVersion() { - pattern = "%s/builds/driver/next/playwright-%s-%s.zip" - } - - if hostEnv := os.Getenv("PLAYWRIGHT_DOWNLOAD_HOST"); hostEnv != "" { - baseURLs = append(baseURLs, fmt.Sprintf(pattern, hostEnv, d.Version, platform)) - } else { - for _, mirror := range playwrightCDNMirrors { - baseURLs = append(baseURLs, fmt.Sprintf(pattern, mirror, d.Version, platform)) - } - } - return baseURLs -} - -// isReleaseVersion checks if the version is not a beta or alpha release -// this helps to determine the url from where to download the driver -func (d *PlaywrightDriver) isReleaseVersion() bool { - return !strings.Contains(d.Version, "beta") && !strings.Contains(d.Version, "alpha") && !strings.Contains(d.Version, "next") -} - -func makeFileExecutable(path string) error { - stats, err := os.Stat(path) - if err != nil { - return fmt.Errorf("could not stat driver: %w", err) - } - if err := os.Chmod(path, stats.Mode()|0x40); err != nil { - return fmt.Errorf("could not set permissions: %w", err) - } - return nil -} - -func downloadDriver(driverURLs []string) (body []byte, e error) { - for _, driverURL := range driverURLs { - resp, err := http.Get(driverURL) - if err != nil { - 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 = 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 = errors.Join(e, fmt.Errorf("could not read response body: %w", err)) - continue - } - return body, nil - } - return nil, e -} diff --git a/vendor/github.com/playwright-community/playwright-go/run_unix.go b/vendor/github.com/playwright-community/playwright-go/run_unix.go deleted file mode 100644 index 8ff102b..0000000 --- a/vendor/github.com/playwright-community/playwright-go/run_unix.go +++ /dev/null @@ -1,10 +0,0 @@ -//go:build !windows - -package playwright - -import "syscall" - -var defaultSysProcAttr = &syscall.SysProcAttr{} - -// for WritableStream.Copy -const defaultCopyBufSize = 1024 * 1024 diff --git a/vendor/github.com/playwright-community/playwright-go/run_win.go b/vendor/github.com/playwright-community/playwright-go/run_win.go deleted file mode 100644 index fe7b50d..0000000 --- a/vendor/github.com/playwright-community/playwright-go/run_win.go +++ /dev/null @@ -1,10 +0,0 @@ -//go:build windows - -package playwright - -import "syscall" - -var defaultSysProcAttr = &syscall.SysProcAttr{HideWindow: true} - -// for WritableStream.Copy -const defaultCopyBufSize = 64 * 1024 diff --git a/vendor/github.com/playwright-community/playwright-go/selectors.go b/vendor/github.com/playwright-community/playwright-go/selectors.go deleted file mode 100644 index 1151647..0000000 --- a/vendor/github.com/playwright-community/playwright-go/selectors.go +++ /dev/null @@ -1,88 +0,0 @@ -package playwright - -import ( - "errors" - "os" - "sync" -) - -type selectorsOwnerImpl struct { - channelOwner -} - -func (s *selectorsOwnerImpl) setTestIdAttributeName(name string) { - s.channel.SendNoReply("setTestIdAttributeName", map[string]interface{}{ - "testIdAttributeName": name, - }) -} - -func newSelectorsOwner(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *selectorsOwnerImpl { - obj := &selectorsOwnerImpl{} - obj.createChannelOwner(obj, parent, objectType, guid, initializer) - return obj -} - -type selectorsImpl struct { - channels sync.Map - registrations []map[string]interface{} -} - -func (s *selectorsImpl) Register(name string, script Script, options ...SelectorsRegisterOptions) error { - if script.Path == nil && script.Content == nil { - return errors.New("Either source or path should be specified") - } - source := "" - if script.Path != nil { - content, err := os.ReadFile(*script.Path) - if err != nil { - return err - } - source = string(content) - } else { - source = *script.Content - } - params := map[string]interface{}{ - "name": name, - "source": source, - } - if len(options) == 1 && options[0].ContentScript != nil { - params["contentScript"] = *options[0].ContentScript - } - var err error - s.channels.Range(func(key, value any) bool { - _, err = value.(*selectorsOwnerImpl).channel.Send("register", params) - return err == nil - }) - if err != nil { - return err - } - s.registrations = append(s.registrations, params) - return nil -} - -func (s *selectorsImpl) SetTestIdAttribute(name string) { - setTestIdAttributeName(name) - s.channels.Range(func(key, value any) bool { - value.(*selectorsOwnerImpl).setTestIdAttributeName(name) - return true - }) -} - -func (s *selectorsImpl) addChannel(channel *selectorsOwnerImpl) { - s.channels.Store(channel.guid, channel) - for _, params := range s.registrations { - channel.channel.SendNoReply("register", params) - channel.setTestIdAttributeName(getTestIdAttributeName()) - } -} - -func (s *selectorsImpl) removeChannel(channel *selectorsOwnerImpl) { - s.channels.Delete(channel.guid) -} - -func newSelectorsImpl() *selectorsImpl { - return &selectorsImpl{ - channels: sync.Map{}, - registrations: make([]map[string]interface{}, 0), - } -} diff --git a/vendor/github.com/playwright-community/playwright-go/stream.go b/vendor/github.com/playwright-community/playwright-go/stream.go deleted file mode 100644 index e23942f..0000000 --- a/vendor/github.com/playwright-community/playwright-go/stream.go +++ /dev/null @@ -1,68 +0,0 @@ -package playwright - -import ( - "bufio" - "encoding/base64" - "os" - "path/filepath" -) - -type streamImpl struct { - channelOwner -} - -func (s *streamImpl) SaveAs(path string) error { - err := os.MkdirAll(filepath.Dir(path), 0o777) - if err != nil { - return err - } - file, err := os.Create(path) - if err != nil { - return err - } - defer file.Close() - writer := bufio.NewWriter(file) - for { - binary, err := s.channel.Send("read", map[string]interface{}{"size": 1024 * 1024}) - if err != nil { - return err - } - bytes, err := base64.StdEncoding.DecodeString(binary.(string)) - if err != nil { - return err - } - if len(bytes) == 0 { - break - } - _, err = writer.Write(bytes) - if err != nil { - return err - } - } - return writer.Flush() -} - -func (s *streamImpl) ReadAll() ([]byte, error) { - var data []byte - for { - binary, err := s.channel.Send("read", map[string]interface{}{"size": 1024 * 1024}) - if err != nil { - return nil, err - } - bytes, err := base64.StdEncoding.DecodeString(binary.(string)) - if err != nil { - return nil, err - } - if len(bytes) == 0 { - break - } - data = append(data, bytes...) - } - return data, nil -} - -func newStream(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *streamImpl { - stream := &streamImpl{} - stream.createChannelOwner(stream, parent, objectType, guid, initializer) - return stream -} diff --git a/vendor/github.com/playwright-community/playwright-go/tracing.go b/vendor/github.com/playwright-community/playwright-go/tracing.go deleted file mode 100644 index decd872..0000000 --- a/vendor/github.com/playwright-community/playwright-go/tracing.go +++ /dev/null @@ -1,164 +0,0 @@ -package playwright - -import "fmt" - -type tracingImpl struct { - channelOwner - includeSources bool - isTracing bool - stacksId string - tracesDir string -} - -func (t *tracingImpl) Start(options ...TracingStartOptions) error { - chunkOption := TracingStartChunkOptions{} - if len(options) == 1 { - if options[0].Sources != nil { - t.includeSources = *options[0].Sources - } - chunkOption.Name = options[0].Name - chunkOption.Title = options[0].Title - } - innerStart := func() (interface{}, error) { - if _, err := t.channel.Send("tracingStart", options); err != nil { - return "", err - } - return t.channel.Send("tracingStartChunk", chunkOption) - } - name, err := innerStart() - if err != nil { - return err - } - return t.startCollectingStacks(name.(string)) -} - -func (t *tracingImpl) StartChunk(options ...TracingStartChunkOptions) error { - name, err := t.channel.Send("tracingStartChunk", options) - if err != nil { - return err - } - return t.startCollectingStacks(name.(string)) -} - -func (t *tracingImpl) StopChunk(path ...string) error { - filePath := "" - if len(path) == 1 { - filePath = path[0] - } - return t.doStopChunk(filePath) -} - -func (t *tracingImpl) Stop(path ...string) error { - filePath := "" - if len(path) == 1 { - filePath = path[0] - } - if err := t.doStopChunk(filePath); err != nil { - return err - } - _, err := t.channel.Send("tracingStop") - return err -} - -func (t *tracingImpl) doStopChunk(filePath string) (err error) { - if t.isTracing { - t.isTracing = false - t.connection.setInTracing(false) - } - if filePath == "" { - // Not interested in artifacts. - _, err = t.channel.Send("tracingStopChunk", map[string]interface{}{ - "mode": "discard", - }) - if t.stacksId != "" { - return t.connection.LocalUtils().TraceDiscarded(t.stacksId) - } - return err - } - - isLocal := !t.connection.isRemote - if isLocal { - result, err := t.channel.SendReturnAsDict("tracingStopChunk", map[string]interface{}{ - "mode": "entries", - }) - if err != nil { - return err - } - entries, ok := result["entries"] - if !ok { - return fmt.Errorf("could not convert result to map: %v", result) - } - _, err = t.connection.LocalUtils().Zip(localUtilsZipOptions{ - ZipFile: filePath, - Entries: entries.([]interface{}), - StacksId: t.stacksId, - Mode: "write", - IncludeSources: t.includeSources, - }) - return err - } - - result, err := t.channel.SendReturnAsDict("tracingStopChunk", map[string]interface{}{ - "mode": "archive", - }) - if err != nil { - return err - } - artifactChannel, ok := result["artifact"] - if !ok { - return fmt.Errorf("could not convert result to map: %v", result) - } - // Save trace to the final local file. - artifact := fromNullableChannel(artifactChannel).(*artifactImpl) - // The artifact may be missing if the browser closed while stopping tracing. - if artifact == nil { - if t.stacksId != "" { - return t.connection.LocalUtils().TraceDiscarded(t.stacksId) - } - return - } - if err := artifact.SaveAs(filePath); err != nil { - return err - } - if err := artifact.Delete(); err != nil { - return err - } - _, err = t.connection.LocalUtils().Zip(localUtilsZipOptions{ - ZipFile: filePath, - Entries: []interface{}{}, - StacksId: t.stacksId, - Mode: "append", - IncludeSources: t.includeSources, - }) - return err -} - -func (t *tracingImpl) startCollectingStacks(name string) (err error) { - if !t.isTracing { - t.isTracing = true - t.connection.setInTracing(true) - } - t.stacksId, err = t.connection.LocalUtils().TracingStarted(name, t.tracesDir) - return -} - -func (t *tracingImpl) Group(name string, options ...TracingGroupOptions) error { - var option TracingGroupOptions - if len(options) == 1 { - option = options[0] - } - _, err := t.channel.Send("tracingGroup", option, map[string]interface{}{"name": name}) - return err -} - -func (t *tracingImpl) GroupEnd() error { - _, err := t.channel.Send("tracingGroupEnd") - return err -} - -func newTracing(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *tracingImpl { - bt := &tracingImpl{} - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - bt.markAsInternalType() - return bt -} diff --git a/vendor/github.com/playwright-community/playwright-go/transport.go b/vendor/github.com/playwright-community/playwright-go/transport.go deleted file mode 100644 index 1be3988..0000000 --- a/vendor/github.com/playwright-community/playwright-go/transport.go +++ /dev/null @@ -1,141 +0,0 @@ -package playwright - -import ( - "bufio" - "encoding/binary" - "fmt" - "io" - "os" - - "github.com/go-jose/go-jose/v3/json" -) - -type transport interface { - Send(msg map[string]interface{}) error - Poll() (*message, error) - Close() error -} - -type pipeTransport struct { - writer io.WriteCloser - bufReader *bufio.Reader - closed chan struct{} - onClose func() error -} - -func (t *pipeTransport) Poll() (*message, error) { - if t.isClosed() { - return nil, fmt.Errorf("transport closed") - } - - var length uint32 - err := binary.Read(t.bufReader, binary.LittleEndian, &length) - if err != nil { - return nil, fmt.Errorf("could not read protocol padding: %w", err) - } - - data := make([]byte, length) - _, err = io.ReadFull(t.bufReader, data) - if err != nil { - return nil, fmt.Errorf("could not read protocol data: %w", err) - } - - msg := &message{} - if err := json.Unmarshal(data, &msg); err != nil { - return nil, fmt.Errorf("could not decode json: %w", err) - } - if os.Getenv("DEBUGP") != "" { - fmt.Fprintf(os.Stdout, "\x1b[33mRECV>\x1b[0m\n%s\n", data) - } - return msg, nil -} - -type message struct { - ID int `json:"id"` - GUID string `json:"guid"` - Method string `json:"method,omitempty"` - Params map[string]interface{} `json:"params,omitempty"` - Result map[string]interface{} `json:"result,omitempty"` - Error *struct { - Error Error `json:"error"` - } `json:"error,omitempty"` -} - -func (t *pipeTransport) Send(msg map[string]interface{}) error { - if t.isClosed() { - return fmt.Errorf("transport closed") - } - msgBytes, err := json.Marshal(msg) - if err != nil { - return fmt.Errorf("pipeTransport: could not marshal json: %w", err) - } - if os.Getenv("DEBUGP") != "" { - fmt.Fprintf(os.Stdout, "\x1b[32mSEND>\x1b[0m\n%s\n", msgBytes) - } - - lengthPadding := make([]byte, 4) - binary.LittleEndian.PutUint32(lengthPadding, uint32(len(msgBytes))) - if _, err = t.writer.Write(append(lengthPadding, msgBytes...)); err != nil { - return err - } - return nil -} - -func (t *pipeTransport) Close() error { - select { - case <-t.closed: - return nil - default: - return t.onClose() - } -} - -func (t *pipeTransport) isClosed() bool { - select { - case <-t.closed: - return true - default: - return false - } -} - -func newPipeTransport(driver *PlaywrightDriver, stderr io.Writer) (transport, error) { - t := &pipeTransport{ - closed: make(chan struct{}, 1), - } - - cmd := driver.Command("run-driver") - cmd.Stderr = stderr - stdin, err := cmd.StdinPipe() - if err != nil { - return nil, fmt.Errorf("could not create stdin pipe: %w", err) - } - stdout, err := cmd.StdoutPipe() - if err != nil { - return nil, fmt.Errorf("could not create stdout pipe: %w", err) - } - t.writer = stdin - t.bufReader = bufio.NewReader(stdout) - - t.onClose = func() error { - select { - case <-t.closed: - default: - close(t.closed) - } - if err := t.writer.Close(); err != nil { - return err - } - // playwright-cli will exit when its stdin is closed - if err := cmd.Wait(); err != nil { - return err - } - return nil - } - - if err := cmd.Start(); err != nil { - return nil, fmt.Errorf("could not start driver: %w", err) - } - - return t, nil -} diff --git a/vendor/github.com/playwright-community/playwright-go/type_helpers.go b/vendor/github.com/playwright-community/playwright-go/type_helpers.go deleted file mode 100644 index d821e7c..0000000 --- a/vendor/github.com/playwright-community/playwright-go/type_helpers.go +++ /dev/null @@ -1,72 +0,0 @@ -package playwright - -// String is a helper routine that allocates a new string value -// to store v and returns a pointer to it. -func String(v string) *string { - return &v -} - -// Bool is a helper routine that allocates a new bool value -// to store v and returns a pointer to it. -func Bool(v bool) *bool { - return &v -} - -// Int is a helper routine that allocates a new int32 value -// to store v and returns a pointer to it. -func Int(v int) *int { - return &v -} - -// Float is a helper routine that allocates a new float64 value -// to store v and returns a pointer to it. -func Float(v float64) *float64 { - return &v -} - -// Null will be used in certain scenarios where a strict nil pointer -// check is not possible -func Null() interface{} { - return "PW_NULL" -} - -// StringSlice is a helper routine that allocates a new StringSlice value -// to store v and returns a pointer to it. -func StringSlice(v ...string) *[]string { - var o []string - o = append(o, v...) - return &o -} - -// IntSlice is a helper routine that allocates a new IntSlice value -// to store v and returns a pointer to it. -func IntSlice(v ...int) *[]int { - var o []int - o = append(o, v...) - return &o -} - -// ToOptionalStorageState converts StorageState to OptionalStorageState for use directly in [Browser.NewContext] -func (s StorageState) ToOptionalStorageState() *OptionalStorageState { - cookies := make([]OptionalCookie, len(s.Cookies)) - for i, c := range s.Cookies { - cookies[i] = c.ToOptionalCookie() - } - return &OptionalStorageState{ - Origins: s.Origins, - Cookies: cookies, - } -} - -func (c Cookie) ToOptionalCookie() OptionalCookie { - return OptionalCookie{ - Name: c.Name, - Value: c.Value, - Domain: String(c.Domain), - Path: String(c.Path), - Expires: Float(c.Expires), - HttpOnly: Bool(c.HttpOnly), - Secure: Bool(c.Secure), - SameSite: c.SameSite, - } -} diff --git a/vendor/github.com/playwright-community/playwright-go/video.go b/vendor/github.com/playwright-community/playwright-go/video.go deleted file mode 100644 index a57b61a..0000000 --- a/vendor/github.com/playwright-community/playwright-go/video.go +++ /dev/null @@ -1,97 +0,0 @@ -package playwright - -import ( - "errors" - "sync" -) - -type videoImpl struct { - page *pageImpl - artifact *artifactImpl - artifactChan chan *artifactImpl - done chan struct{} - closeOnce sync.Once - isRemote bool -} - -func (v *videoImpl) Path() (string, error) { - if v.isRemote { - return "", errors.New("Path is not available when connecting remotely. Use SaveAs() to save a local copy.") - } - v.getArtifact() - if v.artifact == nil { - return "", errors.New("Page did not produce any video frames") - } - return v.artifact.AbsolutePath(), nil -} - -func (v *videoImpl) Delete() error { - v.getArtifact() - if v.artifact == nil { - return nil - } - return v.artifact.Delete() -} - -func (v *videoImpl) SaveAs(path string) error { - if !v.page.IsClosed() { - return errors.New("Page is not yet closed. Close the page prior to calling SaveAs") - } - v.getArtifact() - if v.artifact == nil { - return errors.New("Page did not produce any video frames") - } - return v.artifact.SaveAs(path) -} - -func (v *videoImpl) artifactReady(artifact *artifactImpl) { - v.artifactChan <- artifact -} - -func (v *videoImpl) pageClosed(p Page) { - v.closeOnce.Do(func() { - close(v.done) - }) -} - -func (v *videoImpl) getArtifact() { - // prevent channel block if no video will be produced - if v.page.browserContext.options == nil { - v.pageClosed(v.page) - } else { - option := v.page.browserContext.options - if option == nil || option.RecordVideo == nil { // no recordVideo option - v.pageClosed(v.page) - } - } - select { - case artifact := <-v.artifactChan: - if artifact != nil { - v.artifact = artifact - } - case <-v.done: // page closed - select { // make sure get artifact if it's ready before page closed - case artifact := <-v.artifactChan: - if artifact != nil { - v.artifact = artifact - } - default: - } - } -} - -func newVideo(page *pageImpl) *videoImpl { - video := &videoImpl{ - page: page, - artifactChan: make(chan *artifactImpl, 1), - done: make(chan struct{}, 1), - isRemote: page.connection.isRemote, - } - - if page.isClosed { - video.pageClosed(page) - } else { - page.OnClose(video.pageClosed) - } - return video -} diff --git a/vendor/github.com/playwright-community/playwright-go/waiter.go b/vendor/github.com/playwright-community/playwright-go/waiter.go deleted file mode 100644 index fbcb39f..0000000 --- a/vendor/github.com/playwright-community/playwright-go/waiter.go +++ /dev/null @@ -1,181 +0,0 @@ -package playwright - -import ( - "context" - "fmt" - "reflect" - "sync" - "sync/atomic" - "time" -) - -type ( - waiter struct { - mu sync.Mutex - timeout float64 - fulfilled atomic.Bool - listeners []eventListener - errChan chan error - waitFunc func() (interface{}, error) - } - eventListener struct { - emitter EventEmitter - event string - handler interface{} - } -) - -// RejectOnEvent sets the Waiter to return an error when an event occurs (and the predicate returns true) -func (w *waiter) RejectOnEvent(emitter EventEmitter, event string, err error, predicates ...interface{}) *waiter { - w.mu.Lock() - defer w.mu.Unlock() - if w.waitFunc != nil { - w.reject(fmt.Errorf("waiter: call RejectOnEvent before WaitForEvent")) - return w - } - handler := func(ev ...interface{}) { - if w.fulfilled.Load() { - return - } - if len(predicates) == 0 { - w.reject(err) - } else { - result := reflect.ValueOf(predicates[0]).Call([]reflect.Value{reflect.ValueOf(ev[0])}) - if result[0].Bool() { - w.reject(err) - } - } - } - emitter.On(event, handler) - w.listeners = append(w.listeners, eventListener{ - emitter: emitter, - event: event, - handler: handler, - }) - return w -} - -// WithTimeout sets timeout, in milliseconds, for the waiter. 0 means no timeout. -func (w *waiter) WithTimeout(timeout float64) *waiter { - w.mu.Lock() - defer w.mu.Unlock() - if w.waitFunc != nil { - w.reject(fmt.Errorf("waiter: please set timeout before WaitForEvent")) - return w - } - w.timeout = timeout - return w -} - -// WaitForEvent sets the Waiter to return when an event occurs (and the predicate returns true) -func (w *waiter) WaitForEvent(emitter EventEmitter, event string, predicate interface{}) *waiter { - w.mu.Lock() - defer w.mu.Unlock() - if w.waitFunc != nil { - w.reject(fmt.Errorf("waiter: WaitForEvent can only be called once")) - return w - } - evChan := make(chan interface{}, 1) - handler := w.createHandler(evChan, predicate) - ctx, cancel := context.WithCancel(context.Background()) - if w.timeout != 0 { - timeout := w.timeout - go func() { - select { - case <-time.After(time.Duration(timeout) * time.Millisecond): - err := fmt.Errorf("%w:Timeout %.2fms exceeded.", ErrTimeout, timeout) - w.reject(err) - return - case <-ctx.Done(): - return - } - }() - } - - emitter.On(event, handler) - w.listeners = append(w.listeners, eventListener{ - emitter: emitter, - event: event, - handler: handler, - }) - - w.waitFunc = func() (interface{}, error) { - var ( - err error - val interface{} - ) - select { - case err = <-w.errChan: - break - case val = <-evChan: - break - } - cancel() - w.mu.Lock() - defer w.mu.Unlock() - for _, l := range w.listeners { - l.emitter.RemoveListener(l.event, l.handler) - } - close(evChan) - if err != nil { - return nil, err - } - return val, nil - } - return w -} - -// Wait waits for the waiter to return. It needs to call WaitForEvent once first. -func (w *waiter) Wait() (interface{}, error) { - if w.waitFunc == nil { - return nil, fmt.Errorf("waiter: call WaitForEvent first") - } - return w.waitFunc() -} - -// RunAndWait waits for the waiter to return after calls func. -func (w *waiter) RunAndWait(cb func() error) (interface{}, error) { - if w.waitFunc == nil { - return nil, fmt.Errorf("waiter: call WaitForEvent first") - } - if cb != nil { - if err := cb(); err != nil { - w.errChan <- err - } - } - return w.waitFunc() -} - -func (w *waiter) createHandler(evChan chan<- interface{}, predicate interface{}) func(...interface{}) { - return func(ev ...interface{}) { - if w.fulfilled.Load() { - return - } - if predicate == nil || reflect.ValueOf(predicate).IsNil() { - w.fulfilled.Store(true) - if len(ev) == 1 { - evChan <- ev[0] - } else { - evChan <- nil - } - } else { - result := reflect.ValueOf(predicate).Call([]reflect.Value{reflect.ValueOf(ev[0])}) - if result[0].Bool() { - w.fulfilled.Store(true) - evChan <- ev[0] - } - } - } -} - -func (w *waiter) reject(err error) { - w.fulfilled.Store(true) - w.errChan <- err -} - -func newWaiter() *waiter { - w := &waiter{ - errChan: make(chan error, 1), - } - return w -} diff --git a/vendor/github.com/playwright-community/playwright-go/web_error.go b/vendor/github.com/playwright-community/playwright-go/web_error.go deleted file mode 100644 index b8dab79..0000000 --- a/vendor/github.com/playwright-community/playwright-go/web_error.go +++ /dev/null @@ -1,21 +0,0 @@ -package playwright - -type webErrorImpl struct { - err error - page Page -} - -func (e *webErrorImpl) Page() Page { - return e.page -} - -func (e *webErrorImpl) Error() error { - return e.err -} - -func newWebError(page Page, err error) WebError { - return &webErrorImpl{ - err: err, - page: page, - } -} diff --git a/vendor/github.com/playwright-community/playwright-go/websocket.go b/vendor/github.com/playwright-community/playwright-go/websocket.go deleted file mode 100644 index 4d63ec3..0000000 --- a/vendor/github.com/playwright-community/playwright-go/websocket.go +++ /dev/null @@ -1,134 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "errors" -) - -type webSocketImpl struct { - channelOwner - isClosed bool - page *pageImpl -} - -func (ws *webSocketImpl) URL() string { - return ws.initializer["url"].(string) -} - -func newWebsocket(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *webSocketImpl { - ws := &webSocketImpl{} - ws.createChannelOwner(ws, parent, objectType, guid, initializer) - ws.page = fromChannel(parent.channel).(*pageImpl) - ws.channel.On("close", func() { - ws.Lock() - ws.isClosed = true - ws.Unlock() - ws.Emit("close", ws) - }) - ws.channel.On( - "frameSent", - func(params map[string]interface{}) { - ws.onFrameSent(params["opcode"].(float64), params["data"].(string)) - }, - ) - ws.channel.On( - "frameReceived", - func(params map[string]interface{}) { - ws.onFrameReceived(params["opcode"].(float64), params["data"].(string)) - }, - ) - ws.channel.On( - "socketError", - func(params map[string]interface{}) { - ws.Emit("socketerror", params["error"]) - }, - ) - return ws -} - -func (ws *webSocketImpl) onFrameSent(opcode float64, data string) { - if opcode == 2 { - payload, err := base64.StdEncoding.DecodeString(data) - if err != nil { - logger.Error("could not decode WebSocket.onFrameSent payload", "error", err) - return - } - ws.Emit("framesent", payload) - } else { - ws.Emit("framesent", []byte(data)) - } -} - -func (ws *webSocketImpl) onFrameReceived(opcode float64, data string) { - if opcode == 2 { - payload, err := base64.StdEncoding.DecodeString(data) - if err != nil { - logger.Error("could not decode WebSocket.onFrameReceived payload", "error", err) - return - } - ws.Emit("framereceived", payload) - } else { - ws.Emit("framereceived", []byte(data)) - } -} - -func (ws *webSocketImpl) ExpectEvent(event string, cb func() error, options ...WebSocketExpectEventOptions) (interface{}, error) { - return ws.expectEvent(event, cb, options...) -} - -func (ws *webSocketImpl) WaitForEvent(event string, options ...WebSocketWaitForEventOptions) (interface{}, error) { - if len(options) == 1 { - option := WebSocketExpectEventOptions(options[0]) - return ws.expectEvent(event, nil, option) - } else { - return ws.expectEvent(event, nil) - } -} - -func (ws *webSocketImpl) expectEvent(event string, cb func() error, options ...WebSocketExpectEventOptions) (interface{}, error) { - var predicate interface{} = nil - timeout := ws.page.timeoutSettings.Timeout() - if len(options) == 1 { - if options[0].Timeout != nil { - timeout = *options[0].Timeout - } - if options[0].Predicate != nil { - predicate = options[0].Predicate - } - } - waiter := newWaiter().WithTimeout(timeout) - if event != "close" { - waiter.RejectOnEvent(ws, "close", errors.New("websocket closed")) - } - if event != "socketerror" { - waiter.RejectOnEvent(ws, "socketerror", errors.New("websocket error")) - } - waiter.RejectOnEvent(ws.page, "close", errors.New("page closed")) - if cb == nil { - return waiter.WaitForEvent(ws, event, predicate).Wait() - } else { - return waiter.WaitForEvent(ws, event, predicate).RunAndWait(cb) - } -} - -func (ws *webSocketImpl) IsClosed() bool { - ws.RLock() - defer ws.RUnlock() - return ws.isClosed -} - -func (ws *webSocketImpl) OnClose(fn func(WebSocket)) { - ws.On("close", fn) -} - -func (ws *webSocketImpl) OnFrameReceived(fn func(payload []byte)) { - ws.On("framereceived", fn) -} - -func (ws *webSocketImpl) OnFrameSent(fn func(payload []byte)) { - ws.On("framesent", fn) -} - -func (ws *webSocketImpl) OnSocketError(fn func(string)) { - ws.On("socketerror", fn) -} diff --git a/vendor/github.com/playwright-community/playwright-go/websocket_route.go b/vendor/github.com/playwright-community/playwright-go/websocket_route.go deleted file mode 100644 index bb74ab9..0000000 --- a/vendor/github.com/playwright-community/playwright-go/websocket_route.go +++ /dev/null @@ -1,220 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "fmt" - "regexp" - "sync/atomic" -) - -type webSocketRouteImpl struct { - channelOwner - connected *atomic.Bool - server WebSocketRoute - onPageMessage func(interface{}) - onPageClose func(code *int, reason *string) - onServerMessage func(interface{}) - onServerClose func(code *int, reason *string) -} - -func newWebSocketRoute(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *webSocketRouteImpl { - route := &webSocketRouteImpl{ - connected: &atomic.Bool{}, - } - route.createChannelOwner(route, parent, objectType, guid, initializer) - route.markAsInternalType() - - route.server = newServerWebSocketRoute(route) - - route.channel.On("messageFromPage", func(event map[string]interface{}) { - msg, err := untransformWebSocketMessage(event) - if err != nil { - panic(fmt.Errorf("Could not decode WebSocket message: %w", err)) - } - if route.onPageMessage != nil { - route.onPageMessage(msg) - } else if route.connected.Load() { - go route.channel.SendNoReply("sendToServer", event) - } - }) - - route.channel.On("messageFromServer", func(event map[string]interface{}) { - msg, err := untransformWebSocketMessage(event) - if err != nil { - panic(fmt.Errorf("Could not decode WebSocket message: %w", err)) - } - if route.onServerMessage != nil { - route.onServerMessage(msg) - } else { - go route.channel.SendNoReply("sendToPage", event) - } - }) - - route.channel.On("closePage", func(event map[string]interface{}) { - if route.onPageClose != nil { - route.onPageClose(event["code"].(*int), event["reason"].(*string)) - } else { - go route.channel.SendNoReply("closeServer", event) - } - }) - - route.channel.On("closeServer", func(event map[string]interface{}) { - if route.onServerClose != nil { - route.onServerClose(event["code"].(*int), event["reason"].(*string)) - } else { - go route.channel.SendNoReply("closePage", event) - } - }) - - return route -} - -func (r *webSocketRouteImpl) Close(options ...WebSocketRouteCloseOptions) { - r.channel.SendNoReply("closePage", options, map[string]interface{}{"wasClean": true}) -} - -func (r *webSocketRouteImpl) ConnectToServer() (WebSocketRoute, error) { - if r.connected.Load() { - return nil, fmt.Errorf("Already connected to the server") - } - r.channel.SendNoReply("connect") - r.connected.Store(true) - return r.server, nil -} - -func (r *webSocketRouteImpl) OnClose(handler func(code *int, reason *string)) { - r.onPageClose = handler -} - -func (r *webSocketRouteImpl) OnMessage(handler func(interface{})) { - r.onPageMessage = handler -} - -func (r *webSocketRouteImpl) Send(message interface{}) { - data, err := transformWebSocketMessage(message) - if err != nil { - panic(fmt.Errorf("Could not encode WebSocket message: %w", err)) - } - go r.channel.SendNoReply("sendToPage", data) -} - -func (r *webSocketRouteImpl) URL() string { - return r.initializer["url"].(string) -} - -func (r *webSocketRouteImpl) afterHandle() error { - if r.connected.Load() { - return nil - } - // Ensure that websocket is "open" and can send messages without an actual server connection. - _, err := r.channel.Send("ensureOpened") - return err -} - -type serverWebSocketRouteImpl struct { - webSocketRoute *webSocketRouteImpl -} - -func newServerWebSocketRoute(route *webSocketRouteImpl) *serverWebSocketRouteImpl { - return &serverWebSocketRouteImpl{webSocketRoute: route} -} - -func (s *serverWebSocketRouteImpl) OnMessage(handler func(interface{})) { - s.webSocketRoute.onServerMessage = handler -} - -func (s *serverWebSocketRouteImpl) OnClose(handler func(code *int, reason *string)) { - s.webSocketRoute.onServerClose = handler -} - -func (s *serverWebSocketRouteImpl) ConnectToServer() (WebSocketRoute, error) { - return nil, fmt.Errorf("ConnectToServer must be called on the page-side WebSocketRoute") -} - -func (s *serverWebSocketRouteImpl) URL() string { - return s.webSocketRoute.URL() -} - -func (s *serverWebSocketRouteImpl) Close(options ...WebSocketRouteCloseOptions) { - go s.webSocketRoute.channel.SendNoReply("close", options, map[string]interface{}{"wasClean": true}) -} - -func (s *serverWebSocketRouteImpl) Send(message interface{}) { - data, err := transformWebSocketMessage(message) - if err != nil { - panic(fmt.Errorf("Could not encode WebSocket message: %w", err)) - } - go s.webSocketRoute.channel.SendNoReply("sendToServer", data) -} - -func transformWebSocketMessage(message interface{}) (map[string]interface{}, error) { - data := map[string]interface{}{} - switch v := message.(type) { - case []byte: - data["isBase64"] = true - data["message"] = base64.StdEncoding.EncodeToString(v) - case string: - data["isBase64"] = false - data["message"] = v - default: - return nil, fmt.Errorf("Unsupported message type: %T", v) - } - return data, nil -} - -func untransformWebSocketMessage(data map[string]interface{}) (interface{}, error) { - if data["isBase64"].(bool) { - return base64.StdEncoding.DecodeString(data["message"].(string)) - } - return data["message"], nil -} - -type webSocketRouteHandler struct { - matcher *urlMatcher - handler func(WebSocketRoute) -} - -func newWebSocketRouteHandler(matcher *urlMatcher, handler func(WebSocketRoute)) *webSocketRouteHandler { - return &webSocketRouteHandler{matcher: matcher, handler: handler} -} - -func (h *webSocketRouteHandler) Handle(route WebSocketRoute) { - h.handler(route) - err := route.(*webSocketRouteImpl).afterHandle() - if err != nil { - panic(fmt.Errorf("Could not handle WebSocketRoute: %w", err)) - } -} - -func (h *webSocketRouteHandler) Matches(wsURL string) bool { - return h.matcher.Matches(wsURL) -} - -func prepareWebSocketRouteHandlerInterceptionPatterns(handlers []*webSocketRouteHandler) []map[string]interface{} { - patterns := []map[string]interface{}{} - all := false - for _, handler := range handlers { - switch handler.matcher.raw.(type) { - case *regexp.Regexp: - pattern, flags := convertRegexp(handler.matcher.raw.(*regexp.Regexp)) - patterns = append(patterns, map[string]interface{}{ - "regexSource": pattern, - "regexFlags": flags, - }) - case string: - patterns = append(patterns, map[string]interface{}{ - "glob": handler.matcher.raw.(string), - }) - default: - all = true - } - } - if all { - return []map[string]interface{}{ - { - "glob": "**/*", - }, - } - } - return patterns -} diff --git a/vendor/github.com/playwright-community/playwright-go/worker.go b/vendor/github.com/playwright-community/playwright-go/worker.go deleted file mode 100644 index 6504385..0000000 --- a/vendor/github.com/playwright-community/playwright-go/worker.go +++ /dev/null @@ -1,78 +0,0 @@ -package playwright - -type workerImpl struct { - channelOwner - page *pageImpl - context *browserContextImpl -} - -func (w *workerImpl) URL() string { - return w.initializer["url"].(string) -} - -func (w *workerImpl) Evaluate(expression string, options ...interface{}) (interface{}, error) { - var arg interface{} - if len(options) == 1 { - arg = options[0] - } - result, err := w.channel.Send("evaluateExpression", map[string]interface{}{ - "expression": expression, - "arg": serializeArgument(arg), - }) - if err != nil { - return nil, err - } - return parseResult(result), nil -} - -func (w *workerImpl) EvaluateHandle(expression string, options ...interface{}) (JSHandle, error) { - var arg interface{} - if len(options) == 1 { - arg = options[0] - } - result, err := w.channel.Send("evaluateExpressionHandle", map[string]interface{}{ - "expression": expression, - "arg": serializeArgument(arg), - }) - if err != nil { - return nil, err - } - return fromChannel(result).(*jsHandleImpl), nil -} - -func (w *workerImpl) onClose() { - if w.page != nil { - w.page.Lock() - workers := make([]Worker, 0) - for i := 0; i < len(w.page.workers); i++ { - if w.page.workers[i] != w { - workers = append(workers, w.page.workers[i]) - } - } - w.page.workers = workers - w.page.Unlock() - } - if w.context != nil { - w.context.Lock() - workers := make([]Worker, 0) - for i := 0; i < len(w.context.serviceWorkers); i++ { - if w.context.serviceWorkers[i] != w { - workers = append(workers, w.context.serviceWorkers[i]) - } - } - w.context.serviceWorkers = workers - w.context.Unlock() - } - w.Emit("close", w) -} - -func (w *workerImpl) OnClose(fn func(Worker)) { - w.On("close", fn) -} - -func newWorker(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *workerImpl { - bt := &workerImpl{} - bt.createChannelOwner(bt, parent, objectType, guid, initializer) - bt.channel.On("close", bt.onClose) - return bt -} diff --git a/vendor/github.com/playwright-community/playwright-go/writable_stream.go b/vendor/github.com/playwright-community/playwright-go/writable_stream.go deleted file mode 100644 index 7f144b4..0000000 --- a/vendor/github.com/playwright-community/playwright-go/writable_stream.go +++ /dev/null @@ -1,44 +0,0 @@ -package playwright - -import ( - "encoding/base64" - "io" - "os" -) - -type writableStream struct { - channelOwner -} - -func (s *writableStream) Copy(file string) error { - f, err := os.OpenFile(file, os.O_RDONLY, 0) - if err != nil { - return err - } - defer f.Close() - - for { - buf := make([]byte, defaultCopyBufSize) - n, err := f.Read(buf) - if err != nil && err != io.EOF { - return err - } - if n == 0 { - break - } - _, err = s.channel.Send("write", map[string]interface{}{ - "binary": base64.StdEncoding.EncodeToString(buf[:n]), - }) - if err != nil { - return err - } - } - _, err = s.channel.Send("close") - return err -} - -func newWritableStream(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *writableStream { - stream := &writableStream{} - stream.createChannelOwner(stream, parent, objectType, guid, initializer) - return stream -} diff --git a/vendor/github.com/xlgmokha/minit/.gitignore b/vendor/github.com/xlgmokha/minit/.gitignore new file mode 100644 index 0000000..5e56e04 --- /dev/null +++ b/vendor/github.com/xlgmokha/minit/.gitignore @@ -0,0 +1 @@ +/bin diff --git a/vendor/github.com/xlgmokha/minit/Makefile b/vendor/github.com/xlgmokha/minit/Makefile new file mode 100644 index 0000000..8979cb4 --- /dev/null +++ b/vendor/github.com/xlgmokha/minit/Makefile @@ -0,0 +1,16 @@ +SHELL = /bin/sh + +clean: + @rm -f ./bin/minit + +build: + @go build -o ./bin/minit main.go + +test-unit: + @go test ./... + +test-integration: build + @./bin/minit -h + +test: test-unit test-integration + diff --git a/vendor/github.com/xlgmokha/minit/main.go b/vendor/github.com/xlgmokha/minit/main.go index 8fcf0e0..1e94c00 100644 --- a/vendor/github.com/xlgmokha/minit/main.go +++ b/vendor/github.com/xlgmokha/minit/main.go @@ -1,79 +1,103 @@ package main import ( - "bufio" + "flag" + "log" "os" - "os/exec" "os/signal" "strings" "sync" "sync/atomic" "syscall" "time" + + "github.com/xlgmokha/minit/pkg/procfile" ) -func main() { - file, _ := os.Open("Procfile") - defer file.Close() +var ( + pidMutex sync.Mutex + pids []int + procfilePath *string +) + +func init() { + procfilePath = flag.String("f", "Procfile", "path to Procfile") + flag.Parse() + log.SetFlags(0) +} + +func addPid(pid int) { + pidMutex.Lock() + defer pidMutex.Unlock() + pids = append(pids, pid) +} + +func removePid(pid int) { + pidMutex.Lock() + defer pidMutex.Unlock() + + for i, p := range pids { + if p == pid { + pids = append(pids[:i], pids[i+1:]...) + break + } + } +} - var cmds []*exec.Cmd +func forwardSignalToAll(sig os.Signal) { + pidMutex.Lock() + defer pidMutex.Unlock() + + signal := sig.(syscall.Signal) + for _, pid := range pids { + syscall.Kill(-pid, signal) + } +} + +func main() { var wg sync.WaitGroup var shutdown int32 - scanner := bufio.NewScanner(file) - for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - if line == "" || strings.HasPrefix(line, "#") { - continue + for _, path := range strings.Split(*procfilePath, ",") { + procs, err := procfile.ParseFile(path) + if err != nil { + log.Fatalln(err) } - parts := strings.SplitN(line, ":", 2) - if len(parts) != 2 { - continue - } + for _, proc := range procs { + wg.Add(1) + go func(proc *procfile.Proc) { + defer wg.Done() - args := strings.Fields(os.ExpandEnv(strings.TrimSpace(parts[1]))) - if len(args) == 0 { - continue - } + for atomic.LoadInt32(&shutdown) == 0 { + cmd := proc.NewCommand() + + if cmd.Start() != nil { + time.Sleep(2 * time.Second) + continue + } - cmd := exec.Command(args[0], args[1:]...) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} - - cmds = append(cmds, cmd) - - wg.Add(1) - go func(args []string) { - defer wg.Done() - for atomic.LoadInt32(&shutdown) == 0 { - cmd := exec.Command(args[0], args[1:]...) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} - - if cmd.Start() != nil { - time.Sleep(2 * time.Second) - continue + addPid(cmd.Process.Pid) + cmd.Wait() + removePid(cmd.Process.Pid) + time.Sleep(time.Second) } - cmd.Wait() - time.Sleep(time.Second) - } - }(args) + }(proc) + } } sigChan := make(chan os.Signal, 1) - signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(sigChan) go func() { - <-sigChan - atomic.StoreInt32(&shutdown, 1) - - for _, cmd := range cmds { - if cmd.Process != nil { - syscall.Kill(-cmd.Process.Pid, syscall.SIGTERM) + for sig := range sigChan { + if sig == syscall.SIGINT || sig == syscall.SIGTERM { + atomic.StoreInt32(&shutdown, 1) + forwardSignalToAll(sig) + return } + + forwardSignalToAll(sig) } }() diff --git a/vendor/github.com/xlgmokha/minit/pkg/procfile/parse.go b/vendor/github.com/xlgmokha/minit/pkg/procfile/parse.go new file mode 100644 index 0000000..8d3284b --- /dev/null +++ b/vendor/github.com/xlgmokha/minit/pkg/procfile/parse.go @@ -0,0 +1,44 @@ +package procfile + +import ( + "bufio" + "io" + "os" + "strings" +) + +func ParseFile(path string) ([]*Proc, error) { + file, err := os.Open(path) + if err != nil { + return nil, err + } + defer file.Close() + + return Parse(file), nil +} + +func Parse(file io.Reader) []*Proc { + var processes []*Proc + scanner := bufio.NewScanner(file) + + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if line == "" || strings.HasPrefix(line, "#") { + continue + } + + parts := strings.SplitN(line, ":", 2) + if len(parts) != 2 { + continue + } + + args := strings.Fields(os.ExpandEnv(strings.TrimSpace(parts[1]))) + if len(args) == 0 { + continue + } + + processes = append(processes, New(parts[0], args)) + } + + return processes +} diff --git a/vendor/github.com/xlgmokha/minit/pkg/procfile/proc.go b/vendor/github.com/xlgmokha/minit/pkg/procfile/proc.go new file mode 100644 index 0000000..59b1936 --- /dev/null +++ b/vendor/github.com/xlgmokha/minit/pkg/procfile/proc.go @@ -0,0 +1,27 @@ +package procfile + +import ( + "os" + "os/exec" + "syscall" +) + +type Proc struct { + name string + args []string +} + +func New(name string, args []string) *Proc { + return &Proc{ + name: name, + args: args, + } +} + +func (p *Proc) NewCommand() *exec.Cmd { + cmd := exec.Command(p.args[0], p.args[1:]...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} + return cmd +} diff --git a/vendor/modules.txt b/vendor/modules.txt index e5a79bc..3952ccc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -361,9 +361,6 @@ github.com/danieljoos/wincred # github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc ## explicit github.com/davecgh/go-spew/spew -# github.com/deckarep/golang-set/v2 v2.8.0 -## explicit; go 1.18 -github.com/deckarep/golang-set/v2 # github.com/distribution/reference v0.6.0 ## explicit; go 1.20 github.com/distribution/reference @@ -515,9 +512,6 @@ github.com/go-logr/zerologr ## explicit; go 1.12 github.com/go-ole/go-ole github.com/go-ole/go-ole/oleutil -# github.com/go-stack/stack v1.8.1 -## explicit; go 1.17 -github.com/go-stack/stack # github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 ## explicit; go 1.12 github.com/godbus/dbus @@ -672,6 +666,11 @@ github.com/lann/builder # github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 ## explicit github.com/lann/ps +# github.com/lib/pq v1.10.9 +## explicit; go 1.13 +github.com/lib/pq +github.com/lib/pq/oid +github.com/lib/pq/scram # github.com/lithammer/fuzzysearch v1.1.8 ## explicit; go 1.15 github.com/lithammer/fuzzysearch/fuzzy @@ -780,11 +779,6 @@ github.com/planetscale/vtprotobuf/types/known/emptypb github.com/planetscale/vtprotobuf/types/known/structpb github.com/planetscale/vtprotobuf/types/known/timestamppb github.com/planetscale/vtprotobuf/types/known/wrapperspb -# github.com/playwright-community/playwright-go v0.5200.0 -## explicit; go 1.22 -github.com/playwright-community/playwright-go -github.com/playwright-community/playwright-go/cmd/playwright -github.com/playwright-community/playwright-go/internal/safe # github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 ## explicit github.com/pmezard/go-difflib/difflib @@ -929,9 +923,10 @@ github.com/tklauser/numcpus # github.com/xlab/treeprint v1.2.0 ## explicit; go 1.13 github.com/xlab/treeprint -# github.com/xlgmokha/minit v0.0.0-20250725204255-8e0834741617 +# github.com/xlgmokha/minit v0.0.0-20250731211218-d06d0bc4c199 ## explicit; go 1.24 github.com/xlgmokha/minit +github.com/xlgmokha/minit/pkg/procfile # github.com/xlgmokha/x v0.0.0-20250730165105-1a2af5f242cf ## explicit; go 1.24 github.com/xlgmokha/x/pkg/context |
