Skip to main content

Installation

go get github.com/wraithbytes/sdk-go
Requires Go 1.21+.

Quick Start

package main

import (
    "context"
    "fmt"
    "log"

    rustybrowser "github.com/wraithbytes/sdk-go"
)

func main() {
    client := rustybrowser.NewClient("YOUR_API_KEY")

    // Create a browser
    browser, err := client.CreateBrowser(context.Background())
    if err != nil {
        log.Fatal(err)
    }
    defer client.DeleteBrowser(context.Background(), browser.ID)

    // Navigate to a URL
    if err := client.Navigate(context.Background(), browser.ID, "https://example.com"); err != nil {
        log.Fatal(err)
    }

    // Fetch page text
    text, err := client.FetchText(context.Background(), browser.ID)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(text)
}

Client

NewClient(apiKey string) *Client

Creates a new API client. Connects to https://api.rustybrowser.com automatically.
client := rustybrowser.NewClient("YOUR_API_KEY")

Methods

Browser Management

CreateBrowser(ctx) (*Browser, error)

Spawn a new browser instance.
browser, err := client.CreateBrowser(ctx)
fmt.Println(browser.ID) // UUID

GetBrowser(ctx, id) (*Browser, error)

Get the current state of a browser.
browser, err := client.GetBrowser(ctx, "550e8400-e29b-41d4-a716-446655440000")

DeleteBrowser(ctx, id) error

Close a browser and stop billing.
err := client.DeleteBrowser(ctx, "550e8400-e29b-41d4-a716-446655440000")

Commands

Navigate to a URL.
err := client.Navigate(ctx, browser.ID, "https://example.com")

Click(ctx, id, selector) error

Click an element.
err := client.Click(ctx, browser.ID, "#submit-button")

NodeClick(ctx, id, node) error

Click by node reference.
err := client.NodeClick(ctx, browser.ID, nodeRef)

Type(ctx, id, req) error

Type text into a field.
err := client.Type(ctx, browser.ID, &rustybrowser.TypeRequest{
    Selector: "#search-input",
    Text:     "rusty browser",
})

ScrollBy(ctx, id, x, y) error

Scroll by a relative amount.
err := client.ScrollBy(ctx, browser.ID, 0, 500)

ScrollTo(ctx, id, req) error

Scroll to an element or position.
err := client.ScrollTo(ctx, browser.ID, &rustybrowser.ScrollToRequest{
    Selector: "#footer",
})

Screenshot(ctx, id) (*Screenshot, error)

Capture a screenshot.
shot, err := client.Screenshot(ctx, browser.ID)

FetchHTML(ctx, id) (string, error)

Fetch the current page HTML.
html, err := client.FetchHTML(ctx, browser.ID)

FetchText(ctx, id) (string, error)

Fetch the current page text.
text, err := client.FetchText(ctx, browser.ID)

Eval(ctx, id, expression) (interface{}, error)

Evaluate a JavaScript expression.
result, err := client.Eval(ctx, browser.ID, "document.title")

Instruct(ctx, id, instruction) (*InstructResult, error)

Issue a natural language instruction.
result, err := client.Instruct(ctx, browser.ID, "Find and return all product prices on this page")

Types

Browser

type Browser struct {
    ID string `json:"id"`
}

TypeRequest

type TypeRequest struct {
    Text     string `json:"text"`
    Selector string `json:"selector,omitempty"`
}

ScrollToRequest

type ScrollToRequest struct {
    Selector string  `json:"selector,omitempty"`
    X        float64 `json:"x,omitempty"`
    Y        float64 `json:"y,omitempty"`
}

ErrorDetail

type ErrorDetail struct {
    Code    string `json:"code"`
    Message string `json:"message"`
}