mirror of
https://github.com/MontFerret/ferret.git
synced 2025-04-19 12:12:16 +02:00
44 lines
707 B
Go
44 lines
707 B
Go
package browser
|
|
|
|
import (
|
|
"context"
|
|
"github.com/mafredri/cdp"
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
func pointerInt(input int) *int {
|
|
return &input
|
|
}
|
|
|
|
type batchFunc = func() error
|
|
|
|
func runBatch(funcs ...batchFunc) error {
|
|
eg := errgroup.Group{}
|
|
|
|
for _, f := range funcs {
|
|
eg.Go(f)
|
|
}
|
|
|
|
return eg.Wait()
|
|
}
|
|
|
|
func contextWithTimeout() (context.Context, context.CancelFunc) {
|
|
return context.WithTimeout(context.Background(), DefaultTimeout)
|
|
}
|
|
|
|
func waitForLoadEvent(ctx context.Context, client *cdp.Client) error {
|
|
loadEventFired, err := client.Page.LoadEventFired(ctx)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = loadEventFired.Recv()
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return loadEventFired.Close()
|
|
}
|