### Install chromedp Source: https://pkg.go.dev/github.com/chromedp/chromedp Use the standard Go command to install the chromedp package. ```bash $ go get -u github.com/chromedp/chromedp ``` -------------------------------- ### WaitNewTarget Output Example Source: https://pkg.go.dev/github.com/chromedp/chromedp Example output demonstrating the path captured after waiting for a new target. ```text Output: new tab's path: /second ``` -------------------------------- ### Title Action Output Example Source: https://pkg.go.dev/github.com/chromedp/chromedp Example output showing the result of the Title action. ```text Output: fancy website title ``` -------------------------------- ### ExecAllocator example output Source: https://pkg.go.dev/github.com/chromedp/chromedp Example output for the ExecAllocator, showing that the DevToolsActivePort file has 2 lines. ```text Output: DevToolsActivePort has 2 lines ``` -------------------------------- ### ConsoleLog example output Source: https://pkg.go.dev/github.com/chromedp/chromedp Example output for console logging and exception handling. ```text Output: * console.log call: string - "hello js world" * console.warning call: string - "scary warning" number - 123 * exception "Uncaught" (4:6): TypeError: Cannot read properties of null (reading 'throwsException') at /:5:7 ``` -------------------------------- ### RunResponse Output Example Source: https://pkg.go.dev/github.com/chromedp/chromedp Example output showing the results of RunResponse, which captures navigation responses. ```text Output: first title: / second status code: 200 second title: /foo third status code: 200 ``` -------------------------------- ### AcceptAlert example output Source: https://pkg.go.dev/github.com/chromedp/chromedp Example output for an alert handling operation. ```text Output: closing alert: alert text ``` -------------------------------- ### NewContext ReuseBrowser Example Output Source: https://pkg.go.dev/github.com/chromedp/chromedp Example output demonstrating cookie persistence across browser reuse. ```text Output: Cookies at i=0: "" Cookies at i=1: "foo=bar" ``` -------------------------------- ### Run Function and Browser Executor Example Source: https://pkg.go.dev/github.com/chromedp/chromedp Executes actions against a context. Shows how to perform actions requiring a Browser executor. ```go func Run(ctx context.Context, actions ...Action) error ``` ```go err := chromedp.Run(ctx, chromedp.ActionFunc(func(ctx context.Context) error { c := chromedp.FromContext(ctx) id, err := target.CreateBrowserContext().Do(cdp.WithExecutor(ctx, c.Browser)) return err })) ``` -------------------------------- ### SendKeys Example Source: https://pkg.go.dev/github.com/chromedp/chromedp Performs a SendKeys action on the first element matching a browser CSS query for '#thing'. ```go chromedp.Run(ctx, chromedp.SendKeys(`thing`, chromedp.ByID)) ``` -------------------------------- ### Evaluate example output Source: https://pkg.go.dev/github.com/chromedp/chromedp Example output for the Evaluate action, showing results for various res types including a number, an undefined value, a nil pointer, a slice, a nil slice, an empty map, and an object with an objectId. ```text Output: 3 encountered an undefined value [1 2] slice is nil: true {} objectId is present ``` -------------------------------- ### Dump Example Output Source: https://pkg.go.dev/github.com/chromedp/chromedp Displays the output of a document tree dump operation. ```text Output: Document tree: #document html html head body div#thing #text "a new thing!" div#content [style="display:block;"] #text "the content" ``` -------------------------------- ### NewContext ManyTabs Example Output Source: https://pkg.go.dev/github.com/chromedp/chromedp Example output demonstrating tab behavior in a shared browser context. ```text Output: Same browser: true Same tab: false ``` -------------------------------- ### Key struct example data table Source: https://pkg.go.dev/github.com/chromedp/chromedp/kb Example data for the Key struct for various runes, showing the values for Code, Key, Text, Unmodified, Native, Windows, Shift, and Print fields. ```text Runes | '\r' '\n' | ',' '<' | 'a' 'A' | '\u0a07' | -----------|-------------|------------|------------|-------------| Code | "Enter" | "Comma" | "KeyA" | "MediaStop" | Key | "Enter" | "," "<" | "a" "A" | "MediaStop" | Text | "\r" "\r" | "," "<" | "a" "A" | "" | Unmodified | "\r" "\r" | "," "," | "a" "a" | "" | Native | 0x13 0x13 | 0xbc 0xbc | 0x61 0x41 | 0x00ae | Windows | 0x13 0x13 | 0xbc 0xbc | 0x61 0x41 | 0xe024 | Shift | false false | false true | false true | false | Print | true true | true true | true true | false | ``` -------------------------------- ### RetrieveHTML Example Output Source: https://pkg.go.dev/github.com/chromedp/chromedp Displays the outerHTML content before and after a click interaction. ```text Output: OuterHTML before clicking:

Original content.

OuterHTML after clicking:

New content!

``` -------------------------------- ### DocumentDump Example Output Source: https://pkg.go.dev/github.com/chromedp/chromedp Displays the output of a document tree dump operation. ```text Output: Document tree: #document html html head body div#thing #text "a new thing!" div#content [style="display:block;"] #text "the content" ``` -------------------------------- ### func NewExecAllocator(parent context.Context, opts ...ExecAllocatorOption) (context.Context, context.CancelFunc) Source: https://pkg.go.dev/github.com/chromedp/chromedp Creates a new exec allocator context for launching a browser process. This is used to configure how the browser is started. ```APIDOC ## func NewExecAllocator(parent context.Context, opts ...ExecAllocatorOption) (context.Context, context.CancelFunc) ### Description Creates a new exec allocator context for launching a browser process. This is used to configure how the browser is started. ### Signature func NewExecAllocator(parent context.Context, opts ...ExecAllocatorOption) (context.Context, context.CancelFunc) ### Parameters - parent (context.Context) - Required - The parent context. - opts (...ExecAllocatorOption) - Optional - Options to configure the browser launch. ### Returns - context.Context - The new allocator context. - context.CancelFunc - A function to cancel the allocator and kill the browser process. ``` -------------------------------- ### QueryOption: FromNode Source: https://pkg.go.dev/github.com/chromedp/chromedp Creates a QueryOption that starts the query from a specific node. It is used to scope the query to a subtree. ```APIDOC ## QueryOption: FromNode ### Description Creates a QueryOption that starts the query from a specific node. It is used to scope the query to a subtree. ### Function Signature func FromNode(node *cdp.Node) QueryOption ### Parameters - **node** (*cdp.Node) - Required - The node to start the query from. ### Returns - **QueryOption** - The query option. ``` -------------------------------- ### func EmulateReset() EmulateAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Action to reset the device emulation. Resets the browser's viewport, screen orientation, user-agent, and mobile/touch emulation settings to the original values the browser was started with. ```APIDOC ## func EmulateReset() EmulateAction ### Description Action to reset the device emulation. Resets the browser's viewport, screen orientation, user-agent, and mobile/touch emulation settings to the original values the browser was started with. ### Function Signature func EmulateReset() EmulateAction ### Returns - **EmulateAction** - An action that resets device emulation. ``` -------------------------------- ### WindowSize function Source: https://pkg.go.dev/github.com/chromedp/chromedp Command line option to set the initial window size. ```go func WindowSize(width, height int) ExecAllocatorOption ``` -------------------------------- ### SetUploadFiles Source: https://pkg.go.dev/github.com/chromedp/chromedp Sets the files to upload for the first element node matching the selector. ```APIDOC ## SetUploadFiles ### Description SetUploadFiles is an element query action that sets the files to upload (i.e., for a input[type="file"] node) for the first element node matching the selector. ### Method FUNCTION ### Signature `func SetUploadFiles(sel any, files []string, opts ...QueryOption) QueryAction` ### Parameters - **sel** (any) - Required - The selector to match elements. - **files** ([]string) - Required - The list of file paths to upload. - **opts** (QueryOption) - Optional - Query options to modify the query behavior. ### Returns - **QueryAction** - The action to be executed. ``` -------------------------------- ### func WindowSize Source: https://pkg.go.dev/github.com/chromedp/chromedp WindowSize is the command line option to set the initial window size. ```APIDOC ## func WindowSize ### Description WindowSize is the command line option to set the initial window size. ### Signature `func WindowSize(width, height int) ExecAllocatorOption` ### Parameters - **width** (int) - Required - The width of the window. - **height** (int) - Required - The height of the window. ### Returns - **ExecAllocatorOption** - An option to configure the exec allocator. ``` -------------------------------- ### Allocate browser with ExecAllocator.Allocate Source: https://pkg.go.dev/github.com/chromedp/chromedp Allocate satisfies the Allocator interface. ```go func (a *ExecAllocator) Allocate(ctx context.Context, opts ...BrowserOption) (*Browser, error) ``` -------------------------------- ### SetUploadFiles Source: https://pkg.go.dev/github.com/chromedp/chromedp Sets the upload files for a file input element matching the selector. It is a query action that can be used to set files for upload. ```APIDOC ## SetUploadFiles ### Description Sets the upload files for a file input element matching the selector. It is a query action that can be used to set files for upload. ### Function Signature func SetUploadFiles(sel any, files []string, opts ...QueryOption) QueryAction ### Parameters - **sel** (any) - Required - The selector for the file input. - **files** ([]string) - Required - A slice of file paths. - **opts** (QueryOption) - Optional - Query options. ### Returns - **QueryAction** - The action to execute. ``` -------------------------------- ### ExecAllocator.Allocate(ctx context.Context, opts ...BrowserOption) (*Browser, error) Source: https://pkg.go.dev/github.com/chromedp/chromedp Allocates a new browser instance. ```APIDOC ## ExecAllocator.Allocate(ctx context.Context, opts ...BrowserOption) (*Browser, error) ### Description Allocates a new browser instance. ### Method Allocate ### Signature func (a *ExecAllocator) Allocate(ctx context.Context, opts ...BrowserOption) (*Browser, error) ### Parameters - ctx (context.Context) - The context for allocation. - opts (...BrowserOption) - Browser options. ### Returns - *Browser - The allocated browser. - error - An error if allocation fails. ``` -------------------------------- ### type ExecAllocator Source: https://pkg.go.dev/github.com/chromedp/chromedp ExecAllocator is an Allocator that starts new browser processes on the host machine. ```APIDOC ## type ExecAllocator ### Description ExecAllocator is an Allocator which starts new browser processes on the host machine. ### Type Definition ```go type ExecAllocator struct { // contains filtered or unexported fields } ``` ### Example ``` Output: DevToolsActivePort has 2 lines ``` ``` -------------------------------- ### ExecAllocator type definition Source: https://pkg.go.dev/github.com/chromedp/chromedp ExecAllocator is an Allocator which starts new browser processes on the host machine. ```go type ExecAllocator struct { // contains filtered or unexported fields } ``` -------------------------------- ### KeyOption type Source: https://pkg.go.dev/github.com/chromedp/chromedp KeyOption is a key action option. ```go type KeyOption = func(*input.DispatchKeyEventParams) *input.DispatchKeyEventParams ``` -------------------------------- ### WindowSize(width, height int) ExecAllocatorOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an ExecAllocatorOption that sets the window size. ```APIDOC ## WindowSize(width, height int) ExecAllocatorOption ### Description Returns an ExecAllocatorOption that sets the window size. ### Method WindowSize ### Signature func WindowSize(width, height int) ExecAllocatorOption ### Parameters - width (int) - The window width. - height (int) - The window height. ### Returns - ExecAllocatorOption - An allocator option. ``` -------------------------------- ### Nodes Source: https://pkg.go.dev/github.com/chromedp/chromedp Retrieves the nodes matching the selector. It is a query action that can be used to get the actual DOM nodes. ```APIDOC ## Nodes ### Description Retrieves the nodes matching the selector. It is a query action that can be used to get the actual DOM nodes. ### Function Signature func Nodes(sel any, nodes *[]*cdp.Node, opts ...QueryOption) QueryAction ### Parameters - **sel** (any) - Required - The selector to query. - **nodes** (*[]*cdp.Node) - Required - A pointer to a slice to store the nodes. - **opts** (QueryOption) - Optional - Query options. ### Returns - **QueryAction** - The action to execute. ``` -------------------------------- ### DefaultExecAllocatorOptions Configuration Source: https://pkg.go.dev/github.com/chromedp/chromedp Global default options for the ExecAllocator. Do not modify this global directly; use NewExecAllocator instead. ```go var DefaultExecAllocatorOptions = [...]ExecAllocatorOption{ NoFirstRun, NoDefaultBrowserCheck, Headless, Flag("disable-background-networking", true), Flag("enable-features", "NetworkService,NetworkServiceInProcess"), Flag("disable-background-timer-throttling", true), Flag("disable-backgrounding-occluded-windows", true), Flag("disable-breakpad", true), Flag("disable-client-side-phishing-detection", true), Flag("disable-default-apps", true), Flag("disable-dev-shm-usage", true), Flag("disable-extensions", true), Flag("disable-features", "site-per-process,Translate,BlinkGenPropertyTrees"), Flag("disable-hang-monitor", true), Flag("disable-ipc-flooding-protection", true), Flag("disable-popup-blocking", true), Flag("disable-prompt-on-repost", true), Flag("disable-renderer-backgrounding", true), Flag("disable-sync", true), Flag("force-color-profile", "srgb"), Flag("metrics-recording-only", true), Flag("safebrowsing-disable-auto-update", true), Flag("enable-automation", true), Flag("password-store", "basic"), Flag("use-mock-keychain", true), } ``` -------------------------------- ### Value Source: https://pkg.go.dev/github.com/chromedp/chromedp Retrieves the value of the element matching the selector. It is a query action that can be used to get the value of form elements. ```APIDOC ## Value ### Description Retrieves the value of the element matching the selector. It is a query action that can be used to get the value of form elements. ### Function Signature func Value(sel any, value *string, opts ...QueryOption) QueryAction ### Parameters - **sel** (any) - Required - The selector to query. - **value** (*string) - Required - A pointer to a string to store the value. - **opts** (QueryOption) - Optional - Query options. ### Returns - **QueryAction** - The action to execute. ``` -------------------------------- ### Dimensions(sel any, model **dom.BoxModel, opts ...QueryOption) QueryAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns a QueryAction that gets element dimensions. ```APIDOC ## Dimensions(sel any, model **dom.BoxModel, opts ...QueryOption) QueryAction ### Description Returns a QueryAction that gets element dimensions. ### Method Dimensions ### Signature func Dimensions(sel any, model **dom.BoxModel, opts ...QueryOption) QueryAction ### Parameters - sel (any) - The selector. - model (**dom.BoxModel) - The box model. - opts (...QueryOption) - Additional query options. ### Returns - QueryAction - A query action. ``` -------------------------------- ### ComputedStyle(sel any, style *[]*css.ComputedStyleProperty, opts ...QueryOption) QueryAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns a QueryAction that gets computed style. ```APIDOC ## ComputedStyle(sel any, style *[]*css.ComputedStyleProperty, opts ...QueryOption) QueryAction ### Description Returns a QueryAction that gets computed style. ### Method ComputedStyle ### Signature func ComputedStyle(sel any, style *[]*css.ComputedStyleProperty, opts ...QueryOption) QueryAction ### Parameters - sel (any) - The selector. - style (*[]*css.ComputedStyleProperty) - The computed style properties. - opts (...QueryOption) - Additional query options. ### Returns - QueryAction - A query action. ``` -------------------------------- ### Text Source: https://pkg.go.dev/github.com/chromedp/chromedp Retrieves the text content of the element matching the selector. It is a query action that can be used to get the visible text of an element. ```APIDOC ## Text ### Description Retrieves the text content of the element matching the selector. It is a query action that can be used to get the visible text of an element. ### Function Signature func Text(sel any, text *string, opts ...QueryOption) QueryAction ### Parameters - **sel** (any) - Required - The selector to query. - **text** (*string) - Required - A pointer to a string to store the text. - **opts** (QueryOption) - Optional - Query options. ### Returns - **QueryAction** - The action to execute. ``` -------------------------------- ### WithBrowserLogf option Source: https://pkg.go.dev/github.com/chromedp/chromedp Specifies a function to receive general logging. ```go func WithBrowserLogf(f func(string, ...any)) BrowserOption ``` -------------------------------- ### JavascriptAttribute Source: https://pkg.go.dev/github.com/chromedp/chromedp Retrieves a JavaScript attribute of the element matching the selector. It is a query action that can be used to get a property value from an element. ```APIDOC ## JavascriptAttribute ### Description Retrieves a JavaScript attribute of the element matching the selector. It is a query action that can be used to get a property value from an element. ### Function Signature func JavascriptAttribute(sel any, name string, res any, opts ...QueryOption) QueryAction ### Parameters - **sel** (any) - Required - The selector to query. - **name** (string) - Required - The name of the JavaScript attribute. - **res** (any) - Required - A pointer to store the result. - **opts** (QueryOption) - Optional - Query options. ### Returns - **QueryAction** - The action to execute. ``` -------------------------------- ### Wait for browser with ExecAllocator.Wait Source: https://pkg.go.dev/github.com/chromedp/chromedp Wait satisfies the Allocator interface. ```go func (a *ExecAllocator) Wait() ``` -------------------------------- ### InnerHTML Source: https://pkg.go.dev/github.com/chromedp/chromedp Retrieves the inner HTML of the element matching the selector. It is a query action that can be used to get the HTML content of an element. ```APIDOC ## InnerHTML ### Description Retrieves the inner HTML of the element matching the selector. It is a query action that can be used to get the HTML content of an element. ### Function Signature func InnerHTML(sel any, html *string, opts ...QueryOption) QueryAction ### Parameters - **sel** (any) - Required - The selector to query. - **html** (*string) - Required - A pointer to a string to store the inner HTML. - **opts** (QueryOption) - Optional - Query options. ### Returns - **QueryAction** - The action to execute. ``` -------------------------------- ### NodeIDs Source: https://pkg.go.dev/github.com/chromedp/chromedp Retrieves the node IDs of the elements matching the selector. It is a query action that can be used to get the node IDs of matched elements. ```APIDOC ## NodeIDs ### Description Retrieves the node IDs of the elements matching the selector. It is a query action that can be used to get the node IDs of matched elements. ### Function Signature func NodeIDs(sel any, ids *[]cdp.NodeID, opts ...QueryOption) QueryAction ### Parameters - **sel** (any) - Required - The selector to query. - **ids** (*[]cdp.NodeID) - Required - A pointer to a slice to store the node IDs. - **opts** (QueryOption) - Optional - Query options. ### Returns - **QueryAction** - The action to execute. ``` -------------------------------- ### Action Syntax Template Source: https://pkg.go.dev/github.com/chromedp/chromedp The standard form for writing element selection queries in chromedp. ```go Action(selector[, parameter1, ...parameterN][,result][, queryOptions...]) ``` -------------------------------- ### WithLogf(f func(string, ...any)) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns a ContextOption that sets a logging function. ```APIDOC ## WithLogf(f func(string, ...any)) ContextOption ### Description Returns a ContextOption that sets a logging function. ### Method WithLogf ### Signature func WithLogf(f func(string, ...any)) ContextOption ### Parameters - f (func(string, ...any)) - The logging function. ### Returns - ContextOption - A context option. ``` -------------------------------- ### MatchedStyle Source: https://pkg.go.dev/github.com/chromedp/chromedp Retrieves the matched CSS style for the element matching the selector. It is a query action that can be used to get the computed style of an element. ```APIDOC ## MatchedStyle ### Description Retrieves the matched CSS style for the element matching the selector. It is a query action that can be used to get the computed style of an element. ### Function Signature func MatchedStyle(sel any, style **css.GetMatchedStylesForNodeReturns, opts ...QueryOption) QueryAction ### Parameters - **sel** (any) - Required - The selector to query. - **style** (**css.GetMatchedStylesForNodeReturns) - Required - A pointer to a pointer to store the matched style. - **opts** (QueryOption) - Optional - Query options. ### Returns - **QueryAction** - The action to execute. ``` -------------------------------- ### Attributes(sel any, attributes *map[string]string, opts ...QueryOption) QueryAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns a QueryAction that gets all attributes of an element. ```APIDOC ## Attributes(sel any, attributes *map[string]string, opts ...QueryOption) QueryAction ### Description Returns a QueryAction that gets all attributes of an element. ### Method Attributes ### Signature func Attributes(sel any, attributes *map[string]string, opts ...QueryOption) QueryAction ### Parameters - sel (any) - The selector. - attributes (*map[string]string) - The attributes map. - opts (...QueryOption) - Additional query options. ### Returns - QueryAction - A query action. ``` -------------------------------- ### Navigate function Source: https://pkg.go.dev/github.com/chromedp/chromedp Navigate navigates the current frame. ```go func Navigate(urlstr string) NavigateAction ``` -------------------------------- ### OuterHTML Source: https://pkg.go.dev/github.com/chromedp/chromedp Retrieves the outer HTML of the element matching the selector. It is a query action that can be used to get the full HTML of an element including its tag. ```APIDOC ## OuterHTML ### Description Retrieves the outer HTML of the element matching the selector. It is a query action that can be used to get the full HTML of an element including its tag. ### Function Signature func OuterHTML(sel any, html *string, opts ...QueryOption) QueryAction ### Parameters - **sel** (any) - Required - The selector to query. - **html** (*string) - Required - A pointer to a string to store the outer HTML. - **opts** (QueryOption) - Optional - Query options. ### Returns - **QueryAction** - The action to execute. ``` -------------------------------- ### func WithLogf(f func(string, ...any)) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Shortcut for WithBrowserOption(WithBrowserLogf(f)). Sets a logging function. ```go func WithLogf(f func(string, ...any)) ContextOption ``` -------------------------------- ### AttributesAll(sel any, attributes *[]map[string]string, opts ...QueryOption) QueryAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns a QueryAction that gets attributes of all matching elements. ```APIDOC ## AttributesAll(sel any, attributes *[]map[string]string, opts ...QueryOption) QueryAction ### Description Returns a QueryAction that gets attributes of all matching elements. ### Method AttributesAll ### Signature func AttributesAll(sel any, attributes *[]map[string]string, opts ...QueryOption) QueryAction ### Parameters - sel (any) - The selector. - attributes (*[]map[string]string) - The attributes slice. - opts (...QueryOption) - Additional query options. ### Returns - QueryAction - A query action. ``` -------------------------------- ### BrowserOption type Source: https://pkg.go.dev/github.com/chromedp/chromedp Defines a browser configuration option. ```go type BrowserOption = func(*Browser) ``` -------------------------------- ### AttributeValue(sel any, name string, value *string, ok *bool, opts ...QueryOption) QueryAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns a QueryAction that gets an attribute value. ```APIDOC ## AttributeValue(sel any, name string, value *string, ok *bool, opts ...QueryOption) QueryAction ### Description Returns a QueryAction that gets an attribute value. ### Method AttributeValue ### Signature func AttributeValue(sel any, name string, value *string, ok *bool, opts ...QueryOption) QueryAction ### Parameters - sel (any) - The selector. - name (string) - The attribute name. - value (*string) - The attribute value. - ok (*bool) - Whether the attribute exists. - opts (...QueryOption) - Additional query options. ### Returns - QueryAction - A query action. ``` -------------------------------- ### func WithExistingBrowserContext(id cdp.BrowserContextID) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Sets up a context to create a new target in the specified browser context. ```go func WithExistingBrowserContext(id cdp.BrowserContextID) ContextOption ``` -------------------------------- ### Browser Process method and usage Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns the browser's process object. Useful for monitoring metrics. ```go func (b *Browser) Process() *os.Process ``` ```go if process := chromedp.FromContext(ctx).Browser.Process(); process != nil { fmt.Printf("Browser PID: %v", process.Pid) } ``` -------------------------------- ### func ResetViewport Source: https://pkg.go.dev/github.com/chromedp/chromedp ResetViewport is an action to reset the browser viewport to the default values the browser was started with. Note: does not modify / change the browser's emulated User-Agent, if any. ```APIDOC ## func ResetViewport ### Description ResetViewport is an action to reset the browser viewport to the default values the browser was started with. Note: does not modify / change the browser's emulated User-Agent, if any. ### Signature ```go func ResetViewport() EmulateAction ``` ### Returns - **EmulateAction** - An action that can be executed to reset the viewport. ``` -------------------------------- ### TextContent Source: https://pkg.go.dev/github.com/chromedp/chromedp Retrieves the text content of the element matching the selector, including hidden text. It is a query action that can be used to get the full text content of an element. ```APIDOC ## TextContent ### Description Retrieves the text content of the element matching the selector, including hidden text. It is a query action that can be used to get the full text content of an element. ### Function Signature func TextContent(sel any, text *string, opts ...QueryOption) QueryAction ### Parameters - **sel** (any) - Required - The selector to query. - **text** (*string) - Required - A pointer to a string to store the text content. - **opts** (QueryOption) - Optional - Query options. ### Returns - **QueryAction** - The action to execute. ``` -------------------------------- ### NewExecAllocator Function Signature Source: https://pkg.go.dev/github.com/chromedp/chromedp Creates a context configured with an ExecAllocator for local browser management. ```go func NewExecAllocator(parent context.Context, opts ...ExecAllocatorOption) (context.Context, context.CancelFunc) ``` -------------------------------- ### ProxyServer(proxy string) ExecAllocatorOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an ExecAllocatorOption that sets the proxy server. ```APIDOC ## ProxyServer(proxy string) ExecAllocatorOption ### Description Returns an ExecAllocatorOption that sets the proxy server. ### Method ProxyServer ### Signature func ProxyServer(proxy string) ExecAllocatorOption ### Parameters - proxy (string) - The proxy server address. ### Returns - ExecAllocatorOption - An allocator option. ``` -------------------------------- ### Conn Read method Source: https://pkg.go.dev/github.com/chromedp/chromedp Reads the next message. ```go func (c *Conn) Read(_ context.Context, msg *cdproto.Message) error ``` -------------------------------- ### Conn Write method Source: https://pkg.go.dev/github.com/chromedp/chromedp Writes a message. ```go func (c *Conn) Write(_ context.Context, msg *cdproto.Message) error ``` -------------------------------- ### DumpTo Action Source: https://pkg.go.dev/github.com/chromedp/chromedp Writes a readable tree of the first element node matching the selector with configurable parameters like prefix, indentation, and wait duration. ```go func DumpTo(sel any, w io.Writer, prefix, indent string, nodeIDs bool, depth int64, pierce bool, wait time.Duration, opts ...QueryOption) QueryAction ``` -------------------------------- ### type KeyOption Source: https://pkg.go.dev/github.com/chromedp/chromedp KeyOption is a key action option. ```APIDOC ## type KeyOption ### Description KeyOption is a key action option. ### Type Definition `type KeyOption = func(*input.DispatchKeyEventParams) *input.DispatchKeyEventParams` ``` -------------------------------- ### NewBrowser function Source: https://pkg.go.dev/github.com/chromedp/chromedp Creates a new browser instance. Typically managed by the Allocator interface. ```go func NewBrowser(ctx context.Context, urlstr string, opts ...BrowserOption) (*Browser, error) ``` -------------------------------- ### EmulateViewport(width, height int64, opts ...EmulateViewportOption) EmulateAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an EmulateAction that emulates a viewport size. ```APIDOC ## EmulateViewport(width, height int64, opts ...EmulateViewportOption) EmulateAction ### Description Returns an EmulateAction that emulates a viewport size. ### Method EmulateViewport ### Signature func EmulateViewport(width, height int64, opts ...EmulateViewportOption) EmulateAction ### Parameters - width (int64) - The viewport width. - height (int64) - The viewport height. - opts (...EmulateViewportOption) - Additional viewport options. ### Returns - EmulateAction - An emulate action. ``` -------------------------------- ### Set browser executable path with ExecPath Source: https://pkg.go.dev/github.com/chromedp/chromedp ExecPath returns an ExecAllocatorOption which uses the given path to execute browser processes. The path can be an absolute path to a binary or just the name of the program to find via exec.LookPath. ```go func ExecPath(path string) ExecAllocatorOption ``` -------------------------------- ### EmulateScale(scale float64) EmulateViewportOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an EmulateViewportOption that sets the scale. ```APIDOC ## EmulateScale(scale float64) EmulateViewportOption ### Description Returns an EmulateViewportOption that sets the scale. ### Method EmulateScale ### Signature func EmulateScale(scale float64) EmulateViewportOption ### Parameters - scale (float64) - The scale factor. ### Returns - EmulateViewportOption - A viewport option. ``` -------------------------------- ### func Env Source: https://pkg.go.dev/github.com/chromedp/chromedp Env returns an ExecAllocatorOption that sets environment variables for the new Chrome process. ```APIDOC ## func Env ### Description Env is a list of generic environment variables in the form NAME=value to pass into the new Chrome process. These will be appended to the environment of the Go process as retrieved by os.Environ. ### Method Env ### Signature func Env(vars ...string) ExecAllocatorOption ### Parameters - **vars** (...string) - Required - Environment variables in the form NAME=value. ### Returns - **ExecAllocatorOption** - The option to set environment variables. ``` -------------------------------- ### Browser Execute method Source: https://pkg.go.dev/github.com/chromedp/chromedp Executes a Chrome DevTools Protocol method. ```go func (b *Browser) Execute(ctx context.Context, method string, params, res any) error ``` -------------------------------- ### Env(vars ...string) ExecAllocatorOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an ExecAllocatorOption that sets environment variables. ```APIDOC ## Env(vars ...string) ExecAllocatorOption ### Description Returns an ExecAllocatorOption that sets environment variables. ### Method Env ### Signature func Env(vars ...string) ExecAllocatorOption ### Parameters - vars (...string) - Environment variables. ### Returns - ExecAllocatorOption - An allocator option. ``` -------------------------------- ### Wrap Actions with ActionFunc Source: https://pkg.go.dev/github.com/chromedp/chromedp Use ActionFunc to wrap actions that return multiple values so they can be executed within the Run function. ```go ctx, cancel := chromedp.NewContext(context.Background()) defer cancel() chromedp.Run(ctx, chromedp.ActionFunc(func(ctx context.Context) error { _, err := domain.SomeAction().Do(ctx) return err })) ``` -------------------------------- ### func Headless(a *ExecAllocator) Source: https://pkg.go.dev/github.com/chromedp/chromedp Headless is the command line option to run in headless mode. On top of setting the headless flag, it also hides scrollbars and mutes audio. ```APIDOC ## func Headless(a *ExecAllocator) ### Description Headless is the command line option to run in headless mode. On top of setting the headless flag, it also hides scrollbars and mutes audio. ### Signature func Headless(a *ExecAllocator) ### Parameters - **a** (*ExecAllocator) - The ExecAllocator to apply the option to. ``` -------------------------------- ### Button function Source: https://pkg.go.dev/github.com/chromedp/chromedp Button sets the button to click from a string. ```go func Button(btn string) MouseOption ``` -------------------------------- ### Dump Action Source: https://pkg.go.dev/github.com/chromedp/chromedp Writes a readable tree of the first element node matching the selector and its children up to a specified depth. ```go func Dump(sel any, w io.Writer, opts ...QueryOption) QueryAction ``` -------------------------------- ### func WithLogf(f func(string, ...any)) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Shortcut for WithBrowserOption(WithBrowserLogf(f)). Sets a logging function for the browser. ```APIDOC ## func WithLogf(f func(string, ...any)) ContextOption ### Description Shortcut for WithBrowserOption(WithBrowserLogf(f)). Sets a logging function for the browser. ### Function Signature func WithLogf(f func(string, ...any)) ContextOption ### Parameters - **f** (func(string, ...any)) - Required - The logging function. ### Returns - **ContextOption** - A context option that sets the logging function. ``` -------------------------------- ### Set proxy server with ProxyServer Source: https://pkg.go.dev/github.com/chromedp/chromedp ProxyServer is the command line option to set the outbound proxy server. ```go func ProxyServer(proxy string) ExecAllocatorOption ``` -------------------------------- ### func WithBrowserOption(opts ...BrowserOption) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Allows passing browser options to the allocator when allocating a new browser. Only usable when NewContext is allocating a new browser. ```go func WithBrowserOption(opts ...BrowserOption) ContextOption ``` -------------------------------- ### WithNewBrowserContext(options ...CreateBrowserContextOption) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns a ContextOption that creates a new browser context. ```APIDOC ## WithNewBrowserContext(options ...CreateBrowserContextOption) ContextOption ### Description Returns a ContextOption that creates a new browser context. ### Method WithNewBrowserContext ### Signature func WithNewBrowserContext(options ...CreateBrowserContextOption) ContextOption ### Parameters - options (...CreateBrowserContextOption) - Options for creating the browser context. ### Returns - ContextOption - A context option. ``` -------------------------------- ### NewBrowser Source: https://pkg.go.dev/github.com/chromedp/chromedp Creates a new Browser instance. Typically called by the Allocator interface rather than directly. ```APIDOC ## NewBrowser ### Description Creates a new browser. Typically, this function wouldn't be called directly, as the Allocator interface takes care of it. ### Function Signature func NewBrowser(ctx context.Context, urlstr string, opts ...BrowserOption) (*Browser, error) ### Parameters - ctx (context.Context) - Required - The context for the browser. - urlstr (string) - Required - The URL of the browser. - opts (...BrowserOption) - Optional - Browser options to configure the browser. ### Returns - (*Browser, error) - The created Browser instance and an error if any. ``` -------------------------------- ### func WithTargetID(id target.ID) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Sets up a context to attach to an existing target instead of creating a new one. ```go func WithTargetID(id target.ID) ContextOption ``` -------------------------------- ### func (*ExecAllocator) Allocate Source: https://pkg.go.dev/github.com/chromedp/chromedp Allocate allocates a new Browser using the ExecAllocator. It satisfies the Allocator interface. ```APIDOC ## func (*ExecAllocator) Allocate ### Description Allocate satisfies the Allocator interface. ### Method Allocate ### Signature func (a *ExecAllocator) Allocate(ctx context.Context, opts ...BrowserOption) (*Browser, error) ### Parameters - **ctx** (context.Context) - Required - The context for the allocation. - **opts** (...BrowserOption) - Optional - Browser options. ### Returns - **\*Browser** - The allocated browser. - **error** - An error if allocation fails. ``` -------------------------------- ### func WithDebugf(f func(string, ...any)) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Shortcut for WithBrowserOption(WithBrowserDebugf(f)). Sets a debug logging function. ```go func WithDebugf(f func(string, ...any)) ContextOption ``` -------------------------------- ### WithDebugf(f func(string, ...any)) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns a ContextOption that sets a debug logging function. ```APIDOC ## WithDebugf(f func(string, ...any)) ContextOption ### Description Returns a ContextOption that sets a debug logging function. ### Method WithDebugf ### Signature func WithDebugf(f func(string, ...any)) ContextOption ### Parameters - f (func(string, ...any)) - The debug logging function. ### Returns - ContextOption - A context option. ``` -------------------------------- ### Flag(name string, value any) ExecAllocatorOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an ExecAllocatorOption that sets a command-line flag. ```APIDOC ## Flag(name string, value any) ExecAllocatorOption ### Description Returns an ExecAllocatorOption that sets a command-line flag. ### Method Flag ### Signature func Flag(name string, value any) ExecAllocatorOption ### Parameters - name (string) - The flag name. - value (any) - The flag value. ### Returns - ExecAllocatorOption - An allocator option. ``` -------------------------------- ### ExecPath(path string) ExecAllocatorOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an ExecAllocatorOption that sets the executable path. ```APIDOC ## ExecPath(path string) ExecAllocatorOption ### Description Returns an ExecAllocatorOption that sets the executable path. ### Method ExecPath ### Signature func ExecPath(path string) ExecAllocatorOption ### Parameters - path (string) - The path to the executable. ### Returns - ExecAllocatorOption - An allocator option. ``` -------------------------------- ### FullScreenshot(res *[]byte, quality int) EmulateAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an EmulateAction that takes a full screenshot. ```APIDOC ## FullScreenshot(res *[]byte, quality int) EmulateAction ### Description Returns an EmulateAction that takes a full screenshot. ### Method FullScreenshot ### Signature func FullScreenshot(res *[]byte, quality int) EmulateAction ### Parameters - res (*[]byte) - The result buffer for the screenshot. - quality (int) - The quality of the screenshot. ### Returns - EmulateAction - An emulate action. ``` -------------------------------- ### func (Tasks) Do Source: https://pkg.go.dev/github.com/chromedp/chromedp Do executes the list of Actions sequentially, using the provided context and frame handler. ```APIDOC ## func (Tasks) Do ### Description Do executes the list of Actions sequentially, using the provided context and frame handler. ### Signature ```go func (t Tasks) Do(ctx context.Context) error ``` ### Parameters - **ctx** (context.Context) - Required - The context. ### Returns - **error** - An error if execution fails. ``` -------------------------------- ### WithConsolef option Source: https://pkg.go.dev/github.com/chromedp/chromedp Specifies a function to receive chrome log events. Note: Not yet implemented. ```go func WithConsolef(f func(string, ...any)) BrowserOption ``` -------------------------------- ### Browser.Execute Source: https://pkg.go.dev/github.com/chromedp/chromedp Executes a Chrome DevTools Protocol command on the browser. ```APIDOC ## Browser.Execute ### Description Executes a Chrome DevTools Protocol command on the browser. ### Method Execute ### Function Signature func (b *Browser) Execute(ctx context.Context, method string, params, res any) error ### Parameters - ctx (context.Context) - Required - The context for the execution. - method (string) - Required - The CDP method name. - params (any) - Required - The parameters for the method. - res (any) - Required - The result of the method. ### Returns - error - An error if the execution fails. ``` -------------------------------- ### func WithNewBrowserContext(options ...CreateBrowserContextOption) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Sets up a context to create a new BrowserContext and a new target in it. Child contexts will also use this BrowserContext unless overridden. The new BrowserContext is disposed when the context is done. ```go func WithNewBrowserContext(options ...CreateBrowserContextOption) ContextOption ``` -------------------------------- ### type Device interface definition Source: https://pkg.go.dev/github.com/chromedp/chromedp Defines the Device interface with a Device() method returning device.Info. See the device package for off-the-shelf devices. ```go type Device interface { // Device returns the device info. Device() device.Info } ``` -------------------------------- ### Emulate(device Device) EmulateAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an EmulateAction that emulates a device. ```APIDOC ## Emulate(device Device) EmulateAction ### Description Returns an EmulateAction that emulates a device. ### Method Emulate ### Signature func Emulate(device Device) EmulateAction ### Parameters - device (Device) - The device to emulate. ### Returns - EmulateAction - An emulate action. ``` -------------------------------- ### NavigateBack() NavigateAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns a NavigateAction that navigates back. ```APIDOC ## NavigateBack() NavigateAction ### Description Returns a NavigateAction that navigates back. ### Method NavigateBack ### Signature func NavigateBack() NavigateAction ### Returns - NavigateAction - A navigate action. ``` -------------------------------- ### func NewBrowser(ctx context.Context, urlstr string, opts ...BrowserOption) (*Browser, error) Source: https://pkg.go.dev/github.com/chromedp/chromedp Creates a new Browser instance connected to the given WebSocket URL. This is a lower-level function for advanced use. ```APIDOC ## func NewBrowser(ctx context.Context, urlstr string, opts ...BrowserOption) (*Browser, error) ### Description Creates a new Browser instance connected to the given WebSocket URL. This is a lower-level function for advanced use. ### Signature func NewBrowser(ctx context.Context, urlstr string, opts ...BrowserOption) (*Browser, error) ### Parameters - ctx (context.Context) - Required - The context to use. - urlstr (string) - Required - The WebSocket URL of the browser. - opts (...BrowserOption) - Optional - Options to configure the browser. ### Returns - *Browser - A new Browser instance. - error - An error if the connection fails. ``` -------------------------------- ### func EmulateReset() EmulateAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Action to reset device emulation to the original browser settings, including viewport, screen orientation, user-agent, and mobile/touch emulation. ```go func EmulateReset() EmulateAction ``` -------------------------------- ### Mouse Action Options Source: https://pkg.go.dev/github.com/chromedp/chromedp Functions to set the mouse button for dispatching mouse events. ```go func ButtonLeft(p *input.DispatchMouseEventParams) *input.DispatchMouseEventParams ``` ```go func ButtonMiddle(p *input.DispatchMouseEventParams) *input.DispatchMouseEventParams ``` ```go func ButtonNone(p *input.DispatchMouseEventParams) *input.DispatchMouseEventParams ``` ```go func ButtonRight(p *input.DispatchMouseEventParams) *input.DispatchMouseEventParams ``` -------------------------------- ### func Emulate(device Device) EmulateAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Action to emulate a specific device. See the device package for off-the-shelf devices and modes. ```go func Emulate(device Device) EmulateAction ``` -------------------------------- ### WithBrowserOption(opts ...BrowserOption) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns a ContextOption that sets browser options for the context. ```APIDOC ## WithBrowserOption(opts ...BrowserOption) ContextOption ### Description Returns a ContextOption that sets browser options for the context. ### Method WithBrowserOption ### Signature func WithBrowserOption(opts ...BrowserOption) ContextOption ### Parameters - opts (...BrowserOption) - Browser options to apply. ### Returns - ContextOption - A context option. ``` -------------------------------- ### EmulateReset() EmulateAction Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an EmulateAction that resets emulation. ```APIDOC ## EmulateReset() EmulateAction ### Description Returns an EmulateAction that resets emulation. ### Method EmulateReset ### Signature func EmulateReset() EmulateAction ### Returns - EmulateAction - An emulate action. ``` -------------------------------- ### UserDataDir(dir string) ExecAllocatorOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an ExecAllocatorOption that sets the user data directory. ```APIDOC ## UserDataDir(dir string) ExecAllocatorOption ### Description Returns an ExecAllocatorOption that sets the user data directory. ### Method UserDataDir ### Signature func UserDataDir(dir string) ExecAllocatorOption ### Parameters - dir (string) - The user data directory path. ### Returns - ExecAllocatorOption - An allocator option. ``` -------------------------------- ### NavigateBack function Source: https://pkg.go.dev/github.com/chromedp/chromedp NavigateBack navigates the current frame backwards in its history. ```go func NavigateBack() NavigateAction ``` -------------------------------- ### EmulateTouch function Source: https://pkg.go.dev/github.com/chromedp/chromedp EmulateTouch enables touch emulation for the device viewport. ```go func EmulateTouch(p1 *emulation.SetDeviceMetricsOverrideParams, p2 *emulation.SetTouchEmulationEnabledParams) ``` -------------------------------- ### NavigateForward function Source: https://pkg.go.dev/github.com/chromedp/chromedp NavigateForward navigates the current frame forwards in its history. ```go func NavigateForward() NavigateAction ``` -------------------------------- ### CombinedOutput(w io.Writer) ExecAllocatorOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns an ExecAllocatorOption that sets the combined output writer. ```APIDOC ## CombinedOutput(w io.Writer) ExecAllocatorOption ### Description Returns an ExecAllocatorOption that sets the combined output writer. ### Method CombinedOutput ### Signature func CombinedOutput(w io.Writer) ExecAllocatorOption ### Parameters - w (io.Writer) - The writer for combined output. ### Returns - ExecAllocatorOption - An allocator option. ``` -------------------------------- ### func WithNewBrowserContext(options ...CreateBrowserContextOption) ContextOption Source: https://pkg.go.dev/github.com/chromedp/chromedp Sets up a context to create a new BrowserContext, and create a new target in this BrowserContext. A child context will create its target in this BrowserContext too, unless it's set up with other options. The new BrowserContext will be disposed when the context is done. ```APIDOC ## func WithNewBrowserContext(options ...CreateBrowserContextOption) ContextOption ### Description Sets up a context to create a new BrowserContext, and create a new target in this BrowserContext. A child context will create its target in this BrowserContext too, unless it's set up with other options. The new BrowserContext will be disposed when the context is done. ### Function Signature func WithNewBrowserContext(options ...CreateBrowserContextOption) ContextOption ### Parameters - **options** (...CreateBrowserContextOption) - Optional - Options for creating the new browser context. ### Returns - **ContextOption** - A context option that creates a new browser context. ``` -------------------------------- ### Browser.Process Source: https://pkg.go.dev/github.com/chromedp/chromedp Returns the process object of the browser. Useful for monitoring system metrics. ```APIDOC ## Browser.Process ### Description Returns the process object of the browser. It could be nil when the browser is allocated with RemoteAllocator. It could be useful for a monitoring system to collect process metrics of the browser process. ### Method Process ### Function Signature func (b *Browser) Process() *os.Process ### Returns - *os.Process - The process object of the browser. ### Example if process := chromedp.FromContext(ctx).Browser.Process(); process != nil { fmt.Printf("Browser PID: %v", process.Pid) } ```