Documentation
¶
Overview ¶
Package browsersolver is the official Go SDK for the BrowserSolver API (https://www.browsersolver.com).
Unlock, render, crawl and screenshot any website — anti-bot bypass and technology detection through one API.
Create one client and reuse it:
client, err := browsersolver.NewClient("", nil) // reads BROWSERSOLVER_API_KEY
response, err := client.WebsiteWebunlocker(ctx, ...)
Every documented endpoint has a typed method; Client.Request reaches any other path.
Index ¶
- Constants
- Variables
- func Bool(v bool) *bool
- func Float(v float64) *float64
- func Int(v int64) *int64
- func String(v string) *string
- type APIError
- type BatchResult
- type Client
- func (c *Client) Jobs(ctx context.Context, params *JobsParams, options ...RequestOption) (*Response, error)
- func (c *Client) Request(ctx context.Context, method, path string, params map[string]any, ...) (*Response, error)
- func (c *Client) Stats(ctx context.Context, params *StatsParams, options ...RequestOption) (*Response, error)
- func (c *Client) Usage(ctx context.Context, options ...RequestOption) (*Response, error)
- func (c *Client) WaitForJob(ctx context.Context, jobID string, options *WaitForJobOptions) (*Response, error)
- func (c *Client) WebsiteAntibot(ctx context.Context, params *WebsiteAntibotParams, options ...RequestOption) (*Response, error)
- func (c *Client) WebsiteCrawler(ctx context.Context, params *WebsiteCrawlerParams, options ...RequestOption) (*Response, error)
- func (c *Client) WebsiteRendering(ctx context.Context, params *WebsiteRenderingParams, options ...RequestOption) (*Response, error)
- func (c *Client) WebsiteScreenshot(ctx context.Context, params *WebsiteScreenshotParams, options ...RequestOption) (*Response, error)
- func (c *Client) WebsiteTechnology(ctx context.Context, params *WebsiteTechnologyParams, options ...RequestOption) (*Response, error)
- func (c *Client) WebsiteWebunlocker(ctx context.Context, params *WebsiteWebunlockerParams, ...) (*Response, error)
- type ClientOptions
- type ConfigurationError
- type JobTimeoutError
- type JobsParams
- type RequestOption
- type Response
- type ResponseDecodingError
- type SerializationError
- type StatsParams
- type TransportError
- type WaitForJobOptions
- type WebsiteAntibotParams
- type WebsiteCrawlerParams
- type WebsiteRenderingParams
- type WebsiteScreenshotParams
- type WebsiteTechnologyParams
- type WebsiteWebunlockerParams
Constants ¶
const ( // DefaultBaseURL is the production API origin. DefaultBaseURL = "https://api.browsersolver.com" // DefaultTimeout bounds every request unless ClientOptions.Timeout says otherwise. DefaultTimeout = 120 * time.Second // APIKeyEnvironmentVariable is read when NewClient receives an empty API key. APIKeyEnvironmentVariable = "BROWSERSOLVER_API_KEY" // DefaultConcurrency is the number of tasks Batch runs at the same time. DefaultConcurrency = 10 // MaxRetries is the default number of retries after a network error or a 408, 429, 500, 502, 503 or 504. MaxRetries = 3 // RetryBackoffFactor multiplies the delay before each new retry (a Retry-After header wins). RetryBackoffFactor = 1.5 // DefaultRetryDelay is the delay before the first retry. DefaultRetryDelay = time.Second // MaxRetryDelay caps the delay between two attempts. MaxRetryDelay = 30 * time.Second )
const Version = "0.1.0"
Version is the SDK version sent in the User-Agent header.
Variables ¶
var JobTerminalStatuses = []string{"CompletedJob", "Error", "NotFound", "BadRequest"}
JobTerminalStatuses are the job statuses WaitForJob stops on.
Functions ¶
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
// Message is the "error" (or "message") field of the JSON body, when present.
Message string
Response *Response
}
APIError is returned for non-2xx responses.
func IsAPIError ¶
IsAPIError reports whether err is an *APIError and returns it.
type BatchResult ¶
BatchResult is the outcome of one Batch item.
func Batch ¶
func Batch[I, T any](ctx context.Context, items []I, concurrency int, task func(ctx context.Context, item I) (T, error)) []BatchResult[T]
Batch runs task for every item with at most concurrency calls in flight (DefaultConcurrency when concurrency <= 0) and returns one result per item, in input order. A failing item never stops the others; items not started when ctx is done get ctx.Err().
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a reusable, concurrency-safe BrowserSolver API client.
func NewClient ¶
func NewClient(apiKey string, options *ClientOptions) (*Client, error)
NewClient creates a client. An empty apiKey falls back to the BROWSERSOLVER_API_KEY environment variable.
func (*Client) Jobs ¶
func (c *Client) Jobs(ctx context.Context, params *JobsParams, options ...RequestOption) (*Response, error)
Jobs — Jobs. Poll the status, progress (0–100) and result of a job started with is_async=true. Polling is free. Poll until status is terminal: CompletedJob, Error, NotFound or BadRequest.
GET /v1/jobs/{id}
func (*Client) Request ¶
func (c *Client) Request(ctx context.Context, method, path string, params map[string]any, options ...RequestOption) (*Response, error)
Request sends any request, including endpoints released after this SDK version. GET parameters travel in the query string; POST parameters travel in a JSON body.
func (*Client) Stats ¶
func (c *Client) Stats(ctx context.Context, params *StatsParams, options ...RequestOption) (*Response, error)
Stats — Stats. Infrastructure health for an engine or endpoint over the last hour. Not scoped to your account or tenant. Enabled per account: HTTP 403 means contact support to activate it.
GET /v1/stats
func (*Client) Usage ¶
Usage — Usage. Retrieve real-time usage statistics and credit balance for your BrowserSolver account.
GET /v1/usage
func (*Client) WaitForJob ¶
func (c *Client) WaitForJob(ctx context.Context, jobID string, options *WaitForJobOptions) (*Response, error)
WaitForJob polls GET /v1/jobs/{id} until the job reaches a terminal status and returns the last response.
func (*Client) WebsiteAntibot ¶
func (c *Client) WebsiteAntibot(ctx context.Context, params *WebsiteAntibotParams, options ...RequestOption) (*Response, error)
WebsiteAntibot — Website Antibot. Single-pass scan that names the bot-protection vendor in front of a URL so you can choose the right BrowserSolver fetch tier next. Credit cost: 1 credit per call.
GET /v1/website/antibot
func (*Client) WebsiteCrawler ¶
func (c *Client) WebsiteCrawler(ctx context.Context, params *WebsiteCrawlerParams, options ...RequestOption) (*Response, error)
WebsiteCrawler — Website Crawler. Fast HTTP pull of public HTML with no browser session. Ideal when the first response already contains the content you need. Credit cost: 1 credit per call.
GET / POST /v1/website/crawler
func (*Client) WebsiteRendering ¶
func (c *Client) WebsiteRendering(ctx context.Context, params *WebsiteRenderingParams, options ...RequestOption) (*Response, error)
WebsiteRendering — Website Rendering. Run a managed browser session against a public URL and collect the HTML after client-side scripts finish. Prefer Crawler for static markup; escalate to WebUnlocker on approved hosts when challenges persist. Credit cost: 2 credits per call.
GET /v1/website/rendering
func (*Client) WebsiteScreenshot ¶
func (c *Client) WebsiteScreenshot(ctx context.Context, params *WebsiteScreenshotParams, options ...RequestOption) (*Response, error)
WebsiteScreenshot — Website Screenshot. Turn any public URL into a PNG, JPEG, WebP, or PDF asset rendered by BrowserSolver. No local Chromium fleet to operate. Credit cost: 2 credits per call.
GET / POST /v1/website/screenshot
func (*Client) WebsiteTechnology ¶
func (c *Client) WebsiteTechnology(ctx context.Context, params *WebsiteTechnologyParams, options ...RequestOption) (*Response, error)
WebsiteTechnology — Website Technology. Map CMS, frameworks, analytics, CDN, and security tooling exposed by a public URL. Choose simple lists or expert metadata with confidence scores. Credit cost: 1 credit per call.
GET / POST /v1/website/technology
func (*Client) WebsiteWebunlocker ¶
func (c *Client) WebsiteWebunlocker(ctx context.Context, params *WebsiteWebunlockerParams, options ...RequestOption) (*Response, error)
WebsiteWebunlocker — Website WebUnlocker. BrowserSolver's highest HTML fetch tier for retail and marketplace hosts on your account whitelist. Solves persistent bot challenges that still block Rendering. Credit cost: 3 credits per call.
GET / POST /v1/website/webunlocker
type ClientOptions ¶
type ClientOptions struct {
// BaseURL overrides DefaultBaseURL.
BaseURL string
// Timeout bounds each request. Zero uses DefaultTimeout; a negative value disables it.
Timeout time.Duration
// HTTPClient is copied and used for requests. Redirects are never followed.
HTTPClient *http.Client
// Headers are sent with every request.
Headers map[string]string
// MaxRetries overrides the number of retries. Zero uses MaxRetries; a negative value disables retries.
MaxRetries int
// RetryDelay is the delay before the first retry. Zero uses DefaultRetryDelay.
RetryDelay time.Duration
}
ClientOptions configures a Client. The zero value is valid.
type ConfigurationError ¶
ConfigurationError reports a missing or unusable client configuration.
func (*ConfigurationError) Error ¶
func (e *ConfigurationError) Error() string
func (*ConfigurationError) Unwrap ¶
func (e *ConfigurationError) Unwrap() error
type JobTimeoutError ¶
JobTimeoutError reports an async job that did not finish before the deadline.
func (*JobTimeoutError) Error ¶
func (e *JobTimeoutError) Error() string
type JobsParams ¶
type JobsParams struct {
// The job_id returned by an endpoint called with is_async=true.
ID string `json:"id" api:"id,required"`
}
JobsParams holds the parameters of Jobs (GET /v1/jobs/{id}). Required fields are plain values; optional fields are pointers (use browsersolver.String, browsersolver.Float, browsersolver.Bool) or nil slices and maps.
type RequestOption ¶
type RequestOption func(*requestOptions)
RequestOption customizes one request.
func WithHeader ¶
func WithHeader(name, value string) RequestOption
WithHeader adds a header to one request.
func WithMaxRetries ¶
func WithMaxRetries(n int) RequestOption
WithMaxRetries overrides the number of retries for one request (0 disables them).
func WithMethod ¶
func WithMethod(method string) RequestOption
WithMethod selects GET or POST. Operations default to GET when they support it.
type Response ¶
type Response struct {
StatusCode int
Header http.Header
ContentType string
// Body holds the raw bytes: JSON text, or a file such as an image or PDF.
Body []byte
// IsJSON reports whether the body is JSON (Content-Type application/json or +json).
IsJSON bool
}
Response is a buffered, successful API response.
type ResponseDecodingError ¶
ResponseDecodingError reports a success response that could not be decoded.
func (*ResponseDecodingError) Error ¶
func (e *ResponseDecodingError) Error() string
func (*ResponseDecodingError) Unwrap ¶
func (e *ResponseDecodingError) Unwrap() error
type SerializationError ¶
SerializationError reports a parameter that is missing or cannot be sent.
func (*SerializationError) Error ¶
func (e *SerializationError) Error() string
func (*SerializationError) Unwrap ¶
func (e *SerializationError) Unwrap() error
type StatsParams ¶
type StatsParams struct {
// API family to check, for example website. Provide at least engine or path.
Engine *string `json:"engine" api:"engine"`
// Specific endpoint to check, for example /v1/website/screenshot. If you also pass engine, use an endpoint from that API.
Path *string `json:"path" api:"path"`
}
StatsParams holds the parameters of Stats (GET /v1/stats). Required fields are plain values; optional fields are pointers (use browsersolver.String, browsersolver.Float, browsersolver.Bool) or nil slices and maps.
type TransportError ¶
TransportError reports a failure before a complete HTTP response was received, including client-side timeouts and context cancellation (see Unwrap).
func (*TransportError) Error ¶
func (e *TransportError) Error() string
func (*TransportError) Unwrap ¶
func (e *TransportError) Unwrap() error
type WaitForJobOptions ¶
type WaitForJobOptions struct {
Interval time.Duration
Timeout time.Duration
OnProgress func(job map[string]any)
}
WaitForJobOptions configures WaitForJob. The zero value polls after 3 s, then 1.5x longer each time up to 60 s, for up to 12 hours.
type WebsiteAntibotParams ¶
type WebsiteAntibotParams struct {
// Full URL or bare domain to scan for bot-protection vendors.
Query string `json:"query" api:"query,required"`
// Upper bound for waiting on the target HTTP response, expressed in seconds (defaults to 15).
Timeout *float64 `json:"timeout" api:"timeout"`
// Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
Fields *string `json:"fields" api:"fields"`
// Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob). Default: false.
IsAsync *bool `json:"is_async" api:"is_async"`
// Return HTTP 200 even when an error occurs; the error is then in the response body. Default: false.
SoftFail *bool `json:"soft_fail" api:"soft_fail"`
}
WebsiteAntibotParams holds the parameters of WebsiteAntibot (GET /v1/website/antibot). Required fields are plain values; optional fields are pointers (use browsersolver.String, browsersolver.Float, browsersolver.Bool) or nil slices and maps.
type WebsiteCrawlerParams ¶
type WebsiteCrawlerParams struct {
// Public URL to retrieve with the Crawler tier (plain HTTP, no JavaScript). Include http:// or https://.
Query string `json:"query" api:"query,required"`
// Whether BrowserSolver should chase HTTP redirects for this fetch. Default: true.
AllowRedirects *bool `json:"allow_redirects" api:"allow_redirects"`
// Choose between processed markup and the exact bytes from the origin. Default: false.
ReturnPageSource *bool `json:"return_page_source" api:"return_page_source"`
// Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
Fields *string `json:"fields" api:"fields"`
// Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob). Default: false.
IsAsync *bool `json:"is_async" api:"is_async"`
// Return HTTP 200 even when an error occurs; the error is then in the response body. Default: false.
SoftFail *bool `json:"soft_fail" api:"soft_fail"`
}
WebsiteCrawlerParams holds the parameters of WebsiteCrawler (GET / POST /v1/website/crawler). Required fields are plain values; optional fields are pointers (use browsersolver.String, browsersolver.Float, browsersolver.Bool) or nil slices and maps.
type WebsiteRenderingParams ¶
type WebsiteRenderingParams struct {
// Public URL to load inside BrowserSolver's headless browser. Include http:// or https://.
Query string `json:"query" api:"query,required"`
// Extra pause, in seconds, after the page load event before BrowserSolver returns HTML. Helpful when widgets animate or hydrate late. Default: 0.
WaitInSeconds *float64 `json:"wait_in_seconds" api:"wait_in_seconds"`
// CSS or XPath selector that must appear in the DOM before HTML is returned. The managed browser waits until the node exists (or until timeout).
WaitFor *string `json:"wait_for" api:"wait_for"`
// Skip ad-network requests while the page renders. Default: false.
BlockAds *bool `json:"block_ads" api:"block_ads"`
// Hard ceiling, in seconds, for the render session. When reached, BrowserSolver returns whatever HTML is available. Default: 30.
Timeout *float64 `json:"timeout" api:"timeout"`
// Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
Fields *string `json:"fields" api:"fields"`
// Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob). Default: false.
IsAsync *bool `json:"is_async" api:"is_async"`
// Return HTTP 200 even when an error occurs; the error is then in the response body. Default: false.
SoftFail *bool `json:"soft_fail" api:"soft_fail"`
}
WebsiteRenderingParams holds the parameters of WebsiteRendering (GET /v1/website/rendering). Required fields are plain values; optional fields are pointers (use browsersolver.String, browsersolver.Float, browsersolver.Bool) or nil slices and maps.
type WebsiteScreenshotParams ¶
type WebsiteScreenshotParams struct {
// Page address to render into an image or PDF. Must include a protocol.
URL string `json:"url" api:"url,required"`
// File type returned in the response body. Allowed values: jpeg, jpg, pdf, png, webp. Default: "png".
Format *string `json:"format" api:"format"`
// Swap the desktop viewport for a preset handset or tablet fingerprint. Allowed values: galaxy_fold4, galaxy_s23, galaxy_s23_ultra, galaxy_s8, huawei_mate_50_pro, huawei_p60_pro, ipad, iphone_12, iphone_13_mini, iphone_13_pro_max, iphone_14_pro, iphone_14_pro_max, iphone_x, pixel_5, pixel_6a, pixel_7…
Device *string `json:"device" api:"device"`
// Extend the capture beyond the viewport so the entire scrollable document is included. Default: false.
FullPage *bool `json:"full_page" api:"full_page"`
// Drive a scroll pass first so deferred content mounts before a tall capture. Default: false.
FullPageScroll *bool `json:"full_page_scroll" api:"full_page_scroll"`
// Milliseconds spent scrolling prior to a full-height capture. Default: 400.
FullPageScrollDuration *float64 `json:"full_page_scroll_duration" api:"full_page_scroll_duration"`
// Width of the synthetic desktop window, in pixels. Default: 1280.
ViewportWidth *float64 `json:"viewport_width" api:"viewport_width"`
// Height of the synthetic desktop window, in pixels. Default: 1024.
ViewportHeight *float64 `json:"viewport_height" api:"viewport_height"`
// Pixel density multiplier. Raise it for retina-quality output; files grow accordingly. Default: 1.
ScaleFactor *float64 `json:"scale_factor" api:"scale_factor"`
// Lossy compression level for soft formats. Default: "80".
ImageQuality *string `json:"image_quality" api:"image_quality"`
// Limit the shot to one DOM node matched by this CSS selector.
Selector *string `json:"selector" api:"selector"`
// Serve a stored capture on repeat requests when caching is enabled. Default: false.
Cache *bool `json:"cache" api:"cache"`
// Lifetime of cached captures in seconds. Default: 2592000.
CacheTTL *float64 `json:"cache_ttl" api:"cache_ttl"`
// Hide matching CSS selectors (modals, promo bars, etc.) before shooting.
RemoveSelectors *string `json:"remove_selectors" api:"remove_selectors"`
// Best-effort removal of cookie consent layers before capture. Default: false.
RemoveCookieBanners *bool `json:"remove_cookie_banners" api:"remove_cookie_banners"`
// Best-effort stripping of ad slots before capture. Default: false.
RemoveAds *bool `json:"remove_ads" api:"remove_ads"`
// Resource kinds to discard during load, as a comma list (example: image,stylesheet,font). Allowed values: document, eventsource, fetch, font, image, manifest, media, other, script, stylesheet, texttrack, websocket, xhr.
BlockResources *string `json:"block_resources" api:"block_resources"`
// Substring patterns that should never be fetched (example: analytics,tracking,advertisement). Hosts, paths, or fragments such as .example.com/ work.
BlockUrls *string `json:"block_urls" api:"block_urls"`
// Additional settle time in seconds after the readiness event. Default: 0.
Delay *float64 `json:"delay" api:"delay"`
// Which browser lifecycle event marks the page ready. Allowed values: domcontentloaded, load, networkidle0, networkidle2.
WaitUntil []string `json:"wait_until" api:"wait_until"`
// Hold capture until this CSS node is present.
WaitForSelector *string `json:"wait_for_selector" api:"wait_for_selector"`
// Route the browser through an intermediate proxy.
Proxy *string `json:"proxy" api:"proxy"`
// Secret key used to authenticate uploads.
S3SecretKey *string `json:"s3_secret_key" api:"s3_secret_key"`
// Access key used to authenticate uploads.
S3AccessKeyID *string `json:"s3_access_key_id" api:"s3_access_key_id"`
// Destination bucket for the binary asset.
S3Bucket *string `json:"s3_bucket" api:"s3_bucket"`
// Key under which the object is stored (generated automatically if blank).
S3ObjectKey *string `json:"s3_object_key" api:"s3_object_key"`
// Cloud region of the bucket.
S3Region *string `json:"s3_region" api:"s3_region"`
// Override the default AWS endpoint for S3-compatible backends. Leave blank for AWS. R2 example: https://<accountId>.r2.cloudflarestorage.com.
StorageEndpoint *string `json:"storage_endpoint" api:"storage_endpoint"`
// Upload the binary and include the public object URL in the API response. Default: false.
S3URL *bool `json:"s3_url" api:"s3_url"`
// Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
Fields *string `json:"fields" api:"fields"`
// Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob). Default: false.
IsAsync *bool `json:"is_async" api:"is_async"`
// Return HTTP 200 even when an error occurs; the error is then in the response body. Default: false.
SoftFail *bool `json:"soft_fail" api:"soft_fail"`
}
WebsiteScreenshotParams holds the parameters of WebsiteScreenshot (GET / POST /v1/website/screenshot). Required fields are plain values; optional fields are pointers (use browsersolver.String, browsersolver.Float, browsersolver.Bool) or nil slices and maps.
type WebsiteTechnologyParams ¶
type WebsiteTechnologyParams struct {
// Public URL to fingerprint for CMS, frameworks, analytics, CDN, and security tooling. Include http:// or https://.
Query string `json:"query" api:"query,required"`
// How much detail to include in the stack report. Default: "expert".
Mode *string `json:"mode" api:"mode"`
// Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
Fields *string `json:"fields" api:"fields"`
// Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob). Default: false.
IsAsync *bool `json:"is_async" api:"is_async"`
// Return HTTP 200 even when an error occurs; the error is then in the response body. Default: false.
SoftFail *bool `json:"soft_fail" api:"soft_fail"`
}
WebsiteTechnologyParams holds the parameters of WebsiteTechnology (GET / POST /v1/website/technology). Required fields are plain values; optional fields are pointers (use browsersolver.String, browsersolver.Float, browsersolver.Bool) or nil slices and maps.
type WebsiteWebunlockerParams ¶
type WebsiteWebunlockerParams struct {
// Public URL to fetch with the WebUnlocker tier. Include http:// or https://. The hostname must be on your BrowserSolver whitelist.
Query string `json:"query" api:"query,required"`
// Whether the unlock session should chase HTTP redirects. Default: true.
AllowRedirects *bool `json:"allow_redirects" api:"allow_redirects"`
// Choose between processed markup and the exact post-unlock source. Default: false.
ReturnPageSource *bool `json:"return_page_source" api:"return_page_source"`
// Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
Fields *string `json:"fields" api:"fields"`
// Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob). Default: false.
IsAsync *bool `json:"is_async" api:"is_async"`
// Return HTTP 200 even when an error occurs; the error is then in the response body. Default: false.
SoftFail *bool `json:"soft_fail" api:"soft_fail"`
}
WebsiteWebunlockerParams holds the parameters of WebsiteWebunlocker (GET / POST /v1/website/webunlocker). Required fields are plain values; optional fields are pointers (use browsersolver.String, browsersolver.Float, browsersolver.Bool) or nil slices and maps.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
binary
command
|
|
|
json
command
|
|
|
request
command
|
|
|
wait-for-job
command
|