cdpui

package module
v0.0.1-rc0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

cdpui

only support headless_shell,chrome,chromium

GoDoc Go.Dev reference Build Status codecov Action Status Go Report Card License Tag

example

package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/thinkgos/cdpui"
)

func main() {
	ui := cdpui.New("http://localhost:8080")
	defer ui.Close()

	go func() {
		http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
			fmt.Fprint(w, indexHTML)
		})
		http.ListenAndServe(":8080", nil)
	}()
	time.Sleep(time.Millisecond * 5)
	ui.Run()
	// go func() {
	// 	time.Sleep(time.Second * 15)
	// 	ui.Close()
	// }()
	<-ui.Wait()
}

const indexHTML = `<!doctype html>
<html>
<head>
  <title>example</title>
</head>
<body>
  <div>
	<input id="input1" type="submit" value="dian">
  </div>
  <div id="box3">
	<textarea id="textarea1" style="width:500px;height:400px">textarea</textarea><br><br>
	<input id="input2" type="submit" value="Next">
	<select id="select1">
		<option value="one">1</option>
		<option value="two">2</option>
		<option value="three">3</option>
		<option value="four">4</option>
	</select>
  </div>
</body>
</html>`

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fullscreen

func Fullscreen() chromedp.ExecAllocatorOption

Fullscreen 全屏显示

func Maximized

func Maximized() chromedp.ExecAllocatorOption

Maximized 无论先前的设置如何,都启动浏览器最大化

func WindowPosition

func WindowPosition(x, y int) chromedp.ExecAllocatorOption

WindowPosition 指定初始窗口位置:-窗口位置=x,y

func WindowSize

func WindowSize(width, height int) chromedp.ExecAllocatorOption

WindowSize 设置初始窗口大小: 800,600

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config 配置参数

type Option

type Option func(c *Config)

Option config option

func WithContextOptions

func WithContextOptions(opts ...chromedp.ContextOption) Option

WithContextOptions with some context options.

func WithExecAllocatorFlags

func WithExecAllocatorFlags(flags ...chromedp.ExecAllocatorOption) Option

WithExecAllocatorFlags with some exec allocator options.

type UI

type UI struct {
	// contains filtered or unexported fields
}

UI ui

func New

func New(url string, opts ...Option) UI

New new a ui with option flags

func (UI) Close

func (sf UI) Close() error

Close close ui

func (UI) Run

func (sf UI) Run()

Run show ui 如果show失败,直接panic

func (UI) Wait

func (sf UI) Wait() <-chan struct{}

Wait return the chan wait ui close

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL