launcher

package
v0.46.6 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2020 License: MIT Imports: 23 Imported by: 280

README

Overview

A lib to help launch or download browser. You can also use it as a standalone lib without Rod.

Documentation

Index

Constants

View Source
const DefaultRevision = 768783

DefaultRevision for chrome curl -s -S https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Mac%2FLAST_CHANGE\?alt\=media

View Source
const HeaderName = "Rod-Launcher"

HeaderName for remote launch

View Source
const HostGoogle = "https://storage.googleapis.com"

HostGoogle to download browser

View Source
const HostTaobao = "https://npm.taobao.org/mirrors"

HostTaobao to download browser

Variables

This section is empty.

Functions

func GetWebSocketDebuggerURL

func GetWebSocketDebuggerURL(ctx context.Context, u string) (string, error)

GetWebSocketDebuggerURL from browser remote url

Types

type Browser

type Browser struct {
	Context context.Context

	// Hosts to download browser, examples:
	// https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/748030/chrome-linux.zip
	// https://storage.googleapis.com/chromium-browser-snapshots/Mac/748030/chrome-mac.zip
	// https://storage.googleapis.com/chromium-browser-snapshots/Win/748030/chrome-win.zip
	Hosts []string

	// Revision of the browser to use
	Revision int

	// Dir default is the filepath.Join(os.TempDir(), "rod")
	Dir string

	// Log to print output
	Log func(string)
}

Browser is a helper to download browser smartly

func NewBrowser

func NewBrowser() *Browser

NewBrowser with default values

func (*Browser) Download

func (lc *Browser) Download() error

Download chromium

func (*Browser) ExecPath

func (lc *Browser) ExecPath() string

ExecPath of the chromium executable

func (*Browser) Get

func (lc *Browser) Get() (string, error)

Get is a smart helper to get the browser executable binary. It will first try to find the browser from local disk, if not exists it will try to download the chromium to Dir.

type Launcher

type Launcher struct {
	Flags map[string][]string `json:"flags"`
	// contains filtered or unexported fields
}

Launcher is a helper to launch browser binary smartly

func New

func New() *Launcher

New returns the default arguments to start browser. "--" is optional, with or without it won't affect the result. List of switches: https://peter.sh/experiments/chromium-command-line-switches/

func NewRemote

func NewRemote(remoteURL string) *Launcher

NewRemote create a Launcher instance from remote defaults

func NewUserMode

func NewUserMode() *Launcher

NewUserMode is a preset to enable reusing current user data. Useful for automation of personal browser. If you see any error, it may because you can't launch debug port for existing browser, the solution is to completely close the running browser. Unfortunately, there's no API for rod to tell it automatically yet.

func (*Launcher) Bin

func (l *Launcher) Bin(path string) *Launcher

Bin set browser executable file path

func (*Launcher) Client

func (l *Launcher) Client() *cdp.Client

Client for launching browser remotely

func (*Launcher) Context

func (l *Launcher) Context(ctx context.Context) *Launcher

Context set the context

func (*Launcher) Delete

func (l *Launcher) Delete(name string) *Launcher

Delete flag

func (*Launcher) Devtools

func (l *Launcher) Devtools(autoOpenForTabs bool) *Launcher

Devtools switch to auto open devtools for each tab

func (*Launcher) FormatArgs

func (l *Launcher) FormatArgs() []string

FormatArgs returns the formated arg list for cli

func (*Launcher) Get

func (l *Launcher) Get(name string) (string, bool)

Get flag's first value

func (*Launcher) GetFlags

func (l *Launcher) GetFlags(name string) ([]string, bool)

GetFlags from settings

func (*Launcher) Headless

func (l *Launcher) Headless(enable bool) *Launcher

Headless switch

func (*Launcher) JSON

func (l *Launcher) JSON() []byte

JSON serialization

func (*Launcher) KeepUserDataDir

func (l *Launcher) KeepUserDataDir() *Launcher

KeepUserDataDir after remote browser is closed. By default user-data-dir will be removed.

func (*Launcher) Launch

func (l *Launcher) Launch() string

Launch a standalone temp browser instance and returns the debug url. bin and profileDir are optional, set them to empty to use the default values. If you want to reuse sessions, such as cookies, set the userDataDir to the same location.

func (*Launcher) LaunchE

func (l *Launcher) LaunchE() (string, error)

LaunchE doc is similar to the method Launch

func (*Launcher) Log

func (l *Launcher) Log(log func(string)) *Launcher

Log function to handle stdout and stderr from browser

func (*Launcher) PID

func (l *Launcher) PID() int

PID returns the browser process pid

func (*Launcher) Reap

func (l *Launcher) Reap(enable bool) *Launcher

Reap enable/disable a guard to cleanup zombie processes

func (*Launcher) RemoteDebuggingPort

func (l *Launcher) RemoteDebuggingPort(port int) *Launcher

RemoteDebuggingPort arg

func (*Launcher) Set

func (l *Launcher) Set(name string, values ...string) *Launcher

Set flag

func (*Launcher) UserDataDir

func (l *Launcher) UserDataDir(dir string) *Launcher

UserDataDir is where the browser will look for all of its state, such as cookie and cache. When set to empty, system user's default dir will be used.

type Proxy

type Proxy struct {
	Log func(string)
}

Proxy to help launch browser remotely. Any http request will return a default Launcher based on remote OS environment. Any websocket request will start a new browser and the request will be proxied to the browser. The websocket header "Rod-Launcher" holds the options to launch browser. If the websocket is closed, the browser will be killed.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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