runner

package
v0.0.0-...-9e9a0cf Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package runner provides a Chrome process runner.

Index

Constants

View Source
const (
	// DefaultChromePath is the default path to the google-chrome executable.
	DefaultChromePath = "/usr/bin/google-chrome"
)
View Source
const (
	// DefaultUserDataDirPrefix is the default user data directory prefix.
	DefaultUserDataDirPrefix = "chromedp-runner.%d."
)
View Source
const (
	// DefaultUserDataTmpDir is the default directory path for created user
	// data directories.
	DefaultUserDataTmpDir = "/tmp"
)

Variables

This section is empty.

Functions

func ForceKill

func ForceKill(m map[string]interface{}) error

ForceKill is a Chrome command line option that forces Chrome to be killed when the parent is killed.

Note: sets exec.Cmd.SysProcAttr.Setpgid = true (only for Linux)

func KillProcessGroup

func KillProcessGroup(m map[string]interface{}) error

KillProcessGroup is a Chrome command line option that will instruct the invoked child Chrome process to terminate when the parent process (ie, the Go application) dies.

Note: sets exec.Cmd.SysProcAttr.Setpgid = true and does nothing on Windows.

func NoSandbox

func NoSandbox(m map[string]interface{}) error

NoSandbox is the Chrome comamnd line option to disable the sandbox.

Types

type ByteCount

type ByteCount uint64

ByteCount is a type byte count const.

const (
	Byte     ByteCount = 1
	Kilobyte ByteCount = 1024 * Byte
	Megabyte ByteCount = 1024 * Kilobyte
	Gigabyte ByteCount = 1024 * Megabyte
)

ByteCount values.

type CommandLineOption

type CommandLineOption func(map[string]interface{}) error

CommandLineOption is a Chrome command line option.

see: http://peter.sh/experiments/chromium-command-line-switches/

func CmdOpt

func CmdOpt(o func(*exec.Cmd) error) CommandLineOption

CmdOpt is a Chrome command line option to modify the underlying exec.Cmd prior to invocation.

func ExecPath

func ExecPath(path string) CommandLineOption

ExecPath is a Chrome command line option to set the exec path.

func Flag

func Flag(name string, value interface{}) CommandLineOption

Flag is a generic Chrome command line option to pass a name=value flag to Chrome.

func Headless

func Headless(path string, port int) CommandLineOption

Headless is the Chrome command line option to set the default settings for running the headless_shell executable. If path is empty, then an attempt will be made to find headless_shell on the path.

func LimitCoreDump

func LimitCoreDump(sz ByteCount) CommandLineOption

LimitCoreDump is a Chrome command line option to set the soft core dump limit for a running Chrome process.

Note: uses Linux prlimit system call, and is invoked after the child process has been started.

func LimitMemory

func LimitMemory(mem ByteCount) CommandLineOption

LimitMemory is a Chrome command line option to set the soft memory limit for a running Chrome process.

Note: uses Linux prlimit system call, and is invoked after the child process has been started.

func Path

func Path(path string) CommandLineOption

Path sets the path to the Chrome executable and sets default run options for Chrome. This will also set the remote debugging port to 9222, and disable the first run / default browser check.

Note: use ExecPath if you do not want to set other options.

func Port

func Port(port int) CommandLineOption

Port is the Chrome command line option to set the remote debugging port.

func ProcessOpt

func ProcessOpt(o func(*os.Process) error) CommandLineOption

ProcessOpt is a Chrome command line option to modify the child os.Process after started exec.Cmd.Start.

func Proxy

func Proxy(proxy string) CommandLineOption

Proxy is the Chrome command line option to set the outbound proxy.

func ProxyPacURL

func ProxyPacURL(pacURL url.URL) CommandLineOption

ProxyPacURL is the Chrome command line option to set the URL of a proxy PAC file.

func Rlimit

func Rlimit(res int, cur, max uint64) CommandLineOption

Rlimit is a Chrome command line option to set the soft rlimit value for res on a running Chrome process.

Note: uses Linux prlimit system call, and is invoked after the child process has been started.

see: man 2 prlimit

func StartMaximized

func StartMaximized() CommandLineOption

StartMaximized is the Chrome command line option to start with maximized window size.

func StartURL

func StartURL(urlstr string) CommandLineOption

StartURL is the Chrome command line option to set the initial URL.

func UserAgent

func UserAgent(userAgent string) CommandLineOption

UserAgent is the Chrome command line option to set the default User-Agent header.

func UserDataDir

func UserDataDir(dir string) CommandLineOption

UserDataDir is the Chrome command line option to set the user data dir.

func WindowSize

func WindowSize(width, height int) CommandLineOption

WindowSize is the Chrome command line option to set the initial window size.

type Runner

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

Runner holds information about a running Chrome process.

func New

func New(opts ...CommandLineOption) (*Runner, error)

New creates a new Chrome process using the supplied command line options.

func Run

func Run(ctxt context.Context, opts ...CommandLineOption) (*Runner, error)

Run starts a new Chrome process runner, using the provided context and command line options.

func (*Runner) Client

func (r *Runner) Client(opts ...client.Option) *client.Client

Client returns a Chrome Debugging Protocol client for the running Chrome process.

func (*Runner) Port

func (r *Runner) Port() int

Port returns the port the process was launched with.

func (*Runner) Shutdown

func (r *Runner) Shutdown(ctxt context.Context, opts ...client.Option) error

Shutdown shuts down and all the Chrome tabs.

func (*Runner) Start

func (r *Runner) Start(ctxt context.Context) error

Start starts a Chrome process using the specified context. The Chrome process can be terminated by closing the passed context.

func (*Runner) Wait

func (r *Runner) Wait() error

Wait waits for the previously started Chrome process to terminate, returning any encountered error.

func (*Runner) WatchPageTargets

func (r *Runner) WatchPageTargets(ctxt context.Context, opts ...client.Option) <-chan client.Target

WatchPageTargets returns a channel that will receive new page targets as they are created.

Jump to

Keyboard shortcuts

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