Documentation ¶
Overview ¶
Package runner provides a Chrome process runner.
Index ¶
- Constants
- Variables
- func DisableGPU(m map[string]interface{}) error
- func ForceKill(m map[string]interface{}) error
- func Headless(m map[string]interface{}) error
- func KillProcessGroup(m map[string]interface{}) error
- func LookChromeNames(additional ...string) string
- func NoDefaultBrowserCheck(m map[string]interface{}) error
- func NoFirstRun(m map[string]interface{}) error
- func NoSandbox(m map[string]interface{}) error
- type ByteCount
- type CommandLineOption
- func CmdOpt(o func(*exec.Cmd) error) CommandLineOption
- func ExecPath(path string) CommandLineOption
- func Flag(name string, value interface{}) CommandLineOption
- func LimitCoreDump(sz ByteCount) CommandLineOption
- func LimitMemory(mem ByteCount) CommandLineOption
- func Path(path string) CommandLineOption
- func ProcessOpt(o func(*os.Process) error) CommandLineOption
- func ProxyServer(proxy string) CommandLineOption
- func RemoteDebuggingPort(port int) CommandLineOption
- func Rlimit(res int, cur, max uint64) CommandLineOption
- func URL(urlstr string) CommandLineOption
- func UserAgent(userAgent string) CommandLineOption
- func UserDataDir(dir string) CommandLineOption
- func WindowSize(width, height int) CommandLineOption
- type Error
- type Runner
Constants ¶
const ( // DefaultChromePath is the default path to use for Chrome if the // executable is not in $PATH. DefaultChromePath = "/usr/bin/google-chrome" )
const (
// DefaultUserDataDirPrefix is the default user data directory prefix.
DefaultUserDataDirPrefix = "chromedp-runner.%d."
)
Variables ¶
var DefaultChromeNames = []string{
"google-chrome",
"chromium-browser",
"chromium",
"google-chrome-beta",
"google-chrome-unstable",
}
DefaultChromeNames are the default Chrome executable names to look for in $PATH.
Functions ¶
func DisableGPU ¶
DisableGPU is the command line option to disable the GPU process.
func ForceKill ¶
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 ¶
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 LookChromeNames ¶
LookChromeNames looks for the platform's DefaultChromeNames and any additional names using exec.LookPath, returning the first encountered location or the platform's DefaultChromePath if no names are found on the path.
func NoDefaultBrowserCheck ¶
NoDefaultBrowserCheck is the Chrome comamnd line option to disable the default browser check.
func NoFirstRun ¶
NoFirstRun is the Chrome comamnd line option to disable the first run dialog.
Types ¶
type CommandLineOption ¶
CommandLineOption is a runner 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 command line option to modify the underlying exec.Cmd prior to the call to exec.Cmd.Start in Run.
func ExecPath ¶
func ExecPath(path string) CommandLineOption
ExecPath is a command line option to set the exec path.
func Flag ¶
func Flag(name string, value interface{}) CommandLineOption
Flag is a generic command line option to pass a name=value flag to Chrome.
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 ProcessOpt ¶
func ProcessOpt(o func(*os.Process) error) CommandLineOption
ProcessOpt is a command line option to modify the child os.Process after the call to exec.Cmd.Start in Run.
func ProxyServer ¶
func ProxyServer(proxy string) CommandLineOption
ProxyServer is the command line option to set the outbound proxy server.
func RemoteDebuggingPort ¶
func RemoteDebuggingPort(port int) CommandLineOption
RemoteDebuggingPort is the command line option to set the remote debugging port.
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 URL ¶
func URL(urlstr string) CommandLineOption
URL is the command line option to add a URL to open on process start.
Note: this can be specified multiple times, and each URL will be opened in a new tab.
func UserAgent ¶
func UserAgent(userAgent string) CommandLineOption
UserAgent is the command line option to set the default User-Agent header.
func UserDataDir ¶
func UserDataDir(dir string) CommandLineOption
UserDataDir is the command line option to set the user data dir.
Note: set this option to manually set the profile directory used by Chrome. When this is not set, then a default path will be created in the /tmp directory.
func WindowSize ¶
func WindowSize(width, height int) CommandLineOption
WindowSize is the command line option to set the initial window size.
type Error ¶
type Error string
Error is a runner error.
const ( // ErrAlreadyStarted is the already started error. ErrAlreadyStarted Error = "already started" // ErrAlreadyWaiting is the already waiting error. ErrAlreadyWaiting Error = "already waiting" // ErrInvalidURLs is the invalid url-opts error. ErrInvalidURLOpts Error = "invalid url-opts" // ErrInvalidCmdOpts is the invalid cmd-opts error. ErrInvalidCmdOpts Error = "invalid cmd-opts" // ErrInvalidProcessOpts is the invalid process-opts error. ErrInvalidProcessOpts Error = "invalid process-opts" // ErrInvalidExecPath is the invalid exec-path error. ErrInvalidExecPath Error = "invalid exec-path" )
Error values.
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 ¶
Client returns a Chrome DevTools Protocol client for the running Chrome process.