mirror of
https://github.com/MontFerret/ferret.git
synced 2025-08-13 19:52:52 +02:00
Added delay randomization for inputs (#283)
* Added delay randomization for inputs * Fixed formatting
This commit is contained in:
6
Makefile
6
Makefile
@@ -1,6 +1,7 @@
|
|||||||
.PHONY: build compile test e2e doc fmt lint vet release
|
.PHONY: build install compile test e2e doc fmt lint vet release
|
||||||
|
|
||||||
export GOPATH
|
export GOPATH
|
||||||
|
export GO111MODULE=on
|
||||||
|
|
||||||
VERSION ?= $(shell git describe --tags --always --dirty)
|
VERSION ?= $(shell git describe --tags --always --dirty)
|
||||||
RELEASE_VERSION ?= $(version)
|
RELEASE_VERSION ?= $(version)
|
||||||
@@ -13,6 +14,9 @@ default: build
|
|||||||
|
|
||||||
build: vet generate test compile
|
build: vet generate test compile
|
||||||
|
|
||||||
|
install:
|
||||||
|
go get
|
||||||
|
|
||||||
compile:
|
compile:
|
||||||
go build -v -o ${DIR_BIN}/ferret \
|
go build -v -o ${DIR_BIN}/ferret \
|
||||||
-ldflags "-X main.version=${VERSION}" \
|
-ldflags "-X main.version=${VERSION}" \
|
||||||
|
@@ -529,9 +529,8 @@ func (doc *HTMLDocument) InputBySelector(ctx context.Context, selector values.St
|
|||||||
return values.False, nil
|
return values.False, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
delayMs := time.Duration(delay)
|
// Initial delay after focusing but before typing
|
||||||
|
time.Sleep(time.Duration(delay) * time.Millisecond)
|
||||||
time.Sleep(delayMs * time.Millisecond)
|
|
||||||
|
|
||||||
for _, ch := range valStr {
|
for _, ch := range valStr {
|
||||||
for _, ev := range []string{"keyDown", "keyUp"} {
|
for _, ev := range []string{"keyDown", "keyUp"} {
|
||||||
@@ -540,9 +539,9 @@ func (doc *HTMLDocument) InputBySelector(ctx context.Context, selector values.St
|
|||||||
if err := doc.client.Input.DispatchKeyEvent(ctx, ke); err != nil {
|
if err := doc.client.Input.DispatchKeyEvent(ctx, ke); err != nil {
|
||||||
return values.False, err
|
return values.False, err
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(delayMs * time.Millisecond)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(randomDuration(delay) * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
return values.True, nil
|
return values.True, nil
|
||||||
|
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/MontFerret/ferret/pkg/drivers/cdp/eval"
|
"github.com/MontFerret/ferret/pkg/drivers/cdp/eval"
|
||||||
"github.com/MontFerret/ferret/pkg/drivers/cdp/events"
|
"github.com/MontFerret/ferret/pkg/drivers/cdp/events"
|
||||||
"github.com/MontFerret/ferret/pkg/drivers/common"
|
"github.com/MontFerret/ferret/pkg/drivers/common"
|
||||||
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
||||||
"github.com/MontFerret/ferret/pkg/runtime/values"
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
"github.com/mafredri/cdp"
|
"github.com/mafredri/cdp"
|
||||||
@@ -483,3 +484,10 @@ func normalizeCookieURL(url string) string {
|
|||||||
|
|
||||||
return httpPrefix + url
|
return httpPrefix + url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func randomDuration(delay values.Int) time.Duration {
|
||||||
|
max, min := core.NumberBoundaries(float64(int64(delay)))
|
||||||
|
value := core.Random(max, min)
|
||||||
|
|
||||||
|
return time.Duration(int64(value))
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user