Documentation ¶
Overview ¶
Package chromedpundetected provides a chromedp context with an undetected Chrome browser.
Package chromedpundetected provides a chromedp context with an undetected Chrome browser.
Index ¶
- Constants
- Variables
- func BlockURLs(url ...string) chromedp.ActionFunc
- func LoadCookies(cookies []Cookie) chromedp.ActionFunc
- func LoadCookiesFromFile(path string) chromedp.ActionFunc
- func New(config Config) (context.Context, context.CancelFunc, error)
- func RunCommand(method string, params any) chromedp.ActionFunc
- func RunCommandWithRes(method string, params, res any) chromedp.ActionFunc
- func SaveCookies(cookies *[]Cookie) chromedp.ActionFunc
- func SaveCookiesTo(path string) chromedp.ActionFunc
- func SendKeys(sel any, v string, opts ...chromedp.QueryOption) chromedp.ActionFunc
- func UserAgentOverride(userAgent string) chromedp.ActionFunc
- type Config
- type Cookie
- type Option
- func WithChromeBinary(path string) Option
- func WithChromeFlags(opts ...chromedp.ExecAllocatorOption) Option
- func WithContext(ctx context.Context) Option
- func WithHeadless() Option
- func WithLogLevel(level int) Option
- func WithNoSandbox(b bool) Option
- func WithPort(port int) Option
- func WithTimeout(timeout time.Duration) Option
- func WithUserDataDir(dir string) Option
Constants ¶
const ( // DefaultNoSandbox enables the 'no-sandbox' flag by default. DefaultNoSandbox = true )
Variables ¶
var (
DefaultUserDirPrefix = "chromedp-undetected-"
)
Defaults.
var (
ErrXvfbNotFound = errors.New("xvfb not found. Please install (Linux only)")
)
Errors.
Functions ¶
func BlockURLs ¶
func BlockURLs(url ...string) chromedp.ActionFunc
BlockURLs blocks a set of URLs in Chrome.
func LoadCookies ¶
func LoadCookies(cookies []Cookie) chromedp.ActionFunc
LoadCookies will load a set of cookies into the browser.
func LoadCookiesFromFile ¶
func LoadCookiesFromFile(path string) chromedp.ActionFunc
LoadCookiesFromFile takes a file path to a json file containing cookies, and loads in the cookies into the browser.
func RunCommand ¶
func RunCommand(method string, params any) chromedp.ActionFunc
RunCommand runs any Chrome Dev Tools command, with any params.
In contrast to the native method of chromedp, with this method you can directly pass in a map with the data passed to the command.
func RunCommandWithRes ¶
func RunCommandWithRes(method string, params, res any) chromedp.ActionFunc
RunCommandWithRes runs any Chrome Dev Tools command, with any params and sets the result to the res parameter. Make sure it is a pointer.
In contrast to the native method of chromedp, with this method you can directly pass in a map with the data passed to the command.
func SaveCookies ¶
func SaveCookies(cookies *[]Cookie) chromedp.ActionFunc
SaveCookies extracts the cookies from the current URL and appends them to provided array.
func SaveCookiesTo ¶
func SaveCookiesTo(path string) chromedp.ActionFunc
SaveCookiesTo extracts the cookies from the current page and saves them as JSON to the provided path.
func SendKeys ¶
func SendKeys(sel any, v string, opts ...chromedp.QueryOption) chromedp.ActionFunc
SendKeys does the same as chromedp.SendKeys excepts it randomly waits 100-500ms between sending key presses.
func UserAgentOverride ¶
func UserAgentOverride(userAgent string) chromedp.ActionFunc
UserAgentOverride overwrites the Chrome user agent.
It's better to use this method than emulation.UserAgentOverride.
Types ¶
type Config ¶
type Config struct { // Ctx is the base context to use. By default a background context will be used. Ctx context.Context `json:"-" yaml:"-"` // ContextOptions are chromedp context option. ContextOptions []chromedp.ContextOption `json:"-" yaml:"-"` // ChromeFlags are additional Chrome flags to pass to the browser. // // NOTE: adding additional flags can make the detection unstable, so test, // and be careful of what flags you add. Mostly intended to configure things // like a proxy. Also check if the flags you want to set are not already set // by this library. ChromeFlags []chromedp.ExecAllocatorOption // UserDataDir is the path to the directory where Chrome user data is stored. // // By default a temporary directory will be used. UserDataDir string `json:"userDataDir" yaml:"userDataDir"` // LogLevel is the Chrome log level, 0 by default. LogLevel int `json:"logLevel" yaml:"logLevel"` // NoSandbox dictates whether the no-sanbox flag is added. Defaults to true. NoSandbox bool `json:"noSandbox" yaml:"noSandbox"` // ChromePath is a specific binary path for Chrome. // // By default the chrome or chromium on your PATH will be used. ChromePath string `json:"chromePath" yaml:"chromePath"` // Port is the Chrome debugger port. By default a random port will be used. Port int `json:"port" yaml:"port"` // Timeout is the context timeout. Timeout time.Duration `json:"timeout" yaml:"timeout"` // Headless dicates whether Chrome will start headless (without a visible window) // // It will NOT use the '--headless' option, rather it will use a virtual display. // Requires Xvfb to be installed, only available on Linux. Headless bool `json:"headless" yaml:"headless"` // language to be used otherwise system/OS defaults are used // https://developer.chrome.com/docs/webstore/i18n/#localeTable Language string }
Config is a undetected Chrome config.
type Cookie ¶
type Cookie struct { Name string `json:"name" yaml:"name"` Value string `json:"value" yaml:"value"` Domain string `json:"domain" yaml:"domain"` Path string `json:"path" yaml:"path"` Expires float64 `json:"expires" yaml:"expires"` HTTPOnly bool `json:"httpOnly" yaml:"httpOnly"` Secure bool `json:"secure" yaml:"secure"` }
Cookie is used to set browser cookies.
type Option ¶
type Option func(*Config)
Option is a functional option.
func WithChromeBinary ¶
WithChromeBinary sets the chrome binary path.
func WithChromeFlags ¶
func WithChromeFlags(opts ...chromedp.ExecAllocatorOption) Option
WithChromeFlags add chrome flags.
func WithNoSandbox ¶
WithNoSandbox enable/disable sandbox. Disabled by default.
func WithTimeout ¶
WithTimeout sets the context timeout.
func WithUserDataDir ¶
WithUserDataDir sets the user data directory to a custom path.