Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/herudi/cdv

Headless Browser in V
https://github.com/herudi/cdv

chrome devtools-protocol firefox headless-chrome headless-edge headless-firefox msedge vlang

Last synced: 4 days ago
JSON representation

Headless Browser in V

Awesome Lists containing this project

README

        

# CDV

Headless Browser in V.

> Status: Experimental.

> This project based on CDP spec https://chromedevtools.github.io/devtools-protocol.

## Browser Support
- Chrome/Chromium
- Edge
- Firefox
- Safari soon...
- Opera soon...

## Install
```bash
v install --git https://github.com/herudi/cdv
```

## Import
```v
import cdv
```

## Usage
```v
mut browser := cdv.open_chrome()!
defer { browser.close() }

mut page := browser.new_page()
page.user_agent('my-user-agent')
page.navigate('https://vlang.io')

// code here for listen event fired before wait until page load finished.
page.on_request(fn (mut req cdv.Request) ! {
println(req)
})

page.wait_until()

// code here for other method.
page.save_as_png('./vlang.png')

```
## Example
this example automate fb login.
```v
mut browser := cdv.open_chrome()!
defer { browser.close() }

mut page := browser.new_page()
page.navigate('https://facebook.com')
page.wait_until()

mut form := page.selector('form')
form.input('#email', '[email protected]')
form.input('#pass', 'my_password')
form.click('button[type="submit"]')

page.wait_until()

pathname := page.eval('window.location.pathname').str()
if pathname.starts_with('/login') {
println('login failed...')
} else {
println('login success...')
}
```

## License

[MIT](LICENSE)