GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Ecwid/control: Framework to driving chrome browser

BranchesTags
Open more actions menu

Latest commit

 

History

194 Commits
194 Commits

Folders and files

NameName
Last commit message
Last commit date
cdp
cdp
 
 
chrome
chrome
 
 
example
example
 
 
key
key
 
 
protocol
protocol
 
 
retry
retry
 
 
README.md
README.md
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
input.go
input.go
 
 
main.go
main.go
 
 
node.go
node.go
 
 
optional.go
optional.go
 
 
page.go
page.go
 
 
runtime.go
runtime.go
 
 
session.go
session.go
 
 

Repository files navigation

ecwid-control

control is a automation tool written from scratch using golang on top of Chrome DevTools

Warning This is an experimental project, backward compatibility is not guaranteed!

Installation

go get -u github.com/ecwid/control

How to use

Here is an example of using:

func main() {
	session, cancel, err := control.Take("--no-startup-window")
	if err != nil {
		panic(err)
	}
	defer cancel()

	retrier := retry.Static{
		Timeout: 10 * time.Second,
		Delay:   500 * time.Millisecond, // delay between attempts
	}

	session.Frame.MustNavigate("https://zoid.ecwid.com")

	var products []string
	err = retry.Func(retrier, func() error {
		products = []string{}
		return session.Frame.QueryAll(".grid-product__title-inner").Then(func(nl control.NodeList) error {
			return nl.Foreach(func(n *control.Node) error {
				return n.GetText().Then(func(s string) error {
					products = append(products, s)
					return nil
				})
			})
		})
	})
	if err != nil {
		panic(err)
	}

    // "must way" throws panic on an error

	for _, node := range session.Frame.MustQueryAll(".grid-product__title-inner") {
		log.Println(node.MustGetText())
	}
}

You can call any CDP method implemented in protocol package using a session

err = security.SetIgnoreCertificateErrors(session, security.SetIgnoreCertificateErrorsArgs{
    Ignore: true,
})

or call a custom unimplemented method

err = session.Call("Security.setIgnoreCertificateErrors", sendStruct, receiveStruct)

Subscribe on the domain event

future := control.Subscribe(session, "Target.targetCreated", func(t target.TargetCreated) bool {
    return t.TargetInfo.Type == "page"
})
defer future.Cancel()

// do something here ...

ctx, cancel := context.WithTimeout(context.TODO(), time.Second*10)
result /* target.TargetCreated */, err := future.Get(ctx)

About

Framework to driving chrome browser

Topics

automationautomation-frameworkautomation-uicdpchromedevtools-protocolgogolang

Resources

Readme
Activity
Custom properties

Stars

17 stars

Watchers

8 watching

Forks

5 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.