https://github.com/copyleftdev/goscry

GoScry is a server application written in Go that acts as a bridge between a controlling system (like an LLM or script) and a web browser.

https://github.com/copyleftdev/goscry

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.8%) to scientific vocabulary

Keywords

ai automation golang mcp-server
Last synced: 9 months ago · JSON representation

Repository

GoScry is a server application written in Go that acts as a bridge between a controlling system (like an LLM or script) and a web browser.

Basic Info
  • Host: GitHub
  • Owner: copyleftdev
  • License: mit
  • Language: Go
  • Default Branch: master
  • Homepage: https://goscry.vercel.app/
  • Size: 2.39 MB
Statistics
  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
ai automation golang mcp-server
Created about 1 year ago · Last pushed about 1 year ago
Metadata Files
Readme Changelog License

README.md

GoScry

GoScry Logo

GoScry CI Go Report Card Go Code Quality: Expert Go Version Latest Release Go Reference License Issues Stars Docker Pulls Platforms

GoScry is a server application written in Go that acts as a bridge between a controlling system (like an LLM or script) and a web browser. It uses the Chrome DevTools Protocol (CDP) to interact with websites based on tasks submitted via its API. GoScry can perform actions like navigation, clicking, typing, handling authentication (with hooks for 2FA), and extracting DOM content. Results and status updates can be reported back via webhooks using the Model Context Protocol (MCP) format.

Features

  • Remote Browser Control: Uses CDP (via chromedp) to control headless or headed Chrome/Chromium instances.
  • Task-Based API: Submit sequences of browser actions (navigate, click, type, wait, get DOM, screenshot, etc.) via a simple JSON API.
  • Authentication Handling: Supports basic username/password login sequences within tasks.
  • 2FA Support (Manual Hook): Detects potential 2FA prompts and signals back via API/callback, allowing an external system or user to provide the code to continue the task.
  • DOM Extraction: Retrieve full HTML, text content, or a simplified version of the DOM.
  • DOM AST: Generate a structured Abstract Syntax Tree representation of the DOM with optional scope control.
  • MCP Output: Formats asynchronous results/status updates (e.g., via callbacks) according to the Model Context Protocol (spec 2025-03-26) for clear, structured context reporting.
  • Configurable: Manage server port, browser settings, logging, and security via a YAML file or environment variables.

Architecture Diagram

```mermaid sequenceDiagram participant Client as LLM System / API Client participant GS as GoScry Server (API) participant TM as Task Manager participant BM as Browser Manager participant DOM as DOM Processor participant CDP as Chrome (via CDP) participant Site as Target Website

Client->>+GS: POST /api/v1/tasks (Task JSON)
GS->>+TM: SubmitTask(task)
TM-->>GS: TaskID
GS-->>-Client: 202 Accepted (TaskID)
Note right of TM: Task Execution starts async
TM->>BM: ExecuteActions(actions)
BM->>+CDP: Run CDP Commands (Navigate, Click, etc.)
CDP->>+Site: HTTP Request
Site-->>-CDP: HTTP Response (HTML, etc.)
CDP-->>-BM: Action Result / DOM State
BM-->>TM: Action Completed / Error

alt DOM AST Retrieval
    Client->>+GS: POST /api/v1/dom/ast (URL, ParentSelector)
    GS->>+DOM: GetDomAST(URL, ParentSelector)
    DOM->>+CDP: ChromeDP Actions (Navigate, GetHTML)
    CDP->>+Site: HTTP Request
    Site-->>-CDP: HTTP Response (HTML)
    CDP-->>-DOM: HTML Content
    DOM-->>-GS: DOM AST Structure
    GS-->>-Client: 200 OK (AST JSON)
end

alt 2FA Required (e.g., after login action)
    TM->>BM: ExecuteAction(detect2FAPrompt)
    BM->>CDP: Check page state for 2FA indicators
    CDP->>BM: Presence result
    BM->>TM: Prompt detected/not detected
    opt Prompt Detected
        TM->>TM: Update Task Status (WaitingFor2FA)
        TM-->>Client: Notify Callback (MCP 2FA Request)
        Note over Client, TM: Client retrieves code externally
        Client->>+GS: POST /api/v1/tasks/{id}/2fa (Code)
        GS->>+TM: Provide2FACode(id, code)
        TM->>TM: Signal/Resume Task Execution
        Note right of TM: Next action types the 2FA code
        TM->>BM: ExecuteActions(type 2FA code, submit)
        BM->>+CDP: Type Code, Submit
        CDP->>+Site: Verify 2FA
        Site-->>-CDP: Login Success/Failure
        CDP-->>-BM: Result
        BM-->>TM: Action Completed
    end
end
TM->>TM: Process Final Result / Format MCP
TM-->>Client: Notify Callback (MCP Result/Status)
TM->>TM: Update Task Status (Completed/Failed)
Note over TM: Task finished execution.

```

Package Structure

  • cmd/goscry: Main application entry point
  • internal/taskstypes: Core data types shared across packages
  • internal/tasks: Task management and execution
  • internal/browser: Browser control and CDP interactions
  • internal/server: HTTP API handlers
  • internal/config: Configuration handling
  • internal/dom: DOM processing utilities

Prerequisites

  • Go: Version 1.21 or later.
  • Chrome / Chromium: A compatible version installed on the system where GoScry will run. Ensure the browser executable is in the system PATH or provide the path in the configuration.

Installation

  1. Clone the repository: bash git clone [https://github.com/copyleftdev/goscry.git](https://github.com/copyleftdev/goscry.git) cd goscry
  2. Build the executable: bash go build -o goscry ./cmd/goscry/ This will create the goscry binary in the project root.

  3. Alternatively, download a pre-built binary from the releases page.

Docker Deployment

GoScry can be easily deployed using Docker and Docker Compose with a variety of deployment options.

Quick Start with Docker

  1. Clone the repository: bash git clone [https://github.com/copyleftdev/goscry.git](https://github.com/copyleftdev/goscry.git) cd goscry

  2. Start the container: bash docker compose up -d

  3. Access the API at http://localhost:8090

Deployment Options

GoScry provides several pre-configured deployment profiles:

  1. Basic Deployment - Just the GoScry service: bash docker compose up -d

  2. Production Deployment - Includes Traefik reverse proxy with TLS termination: bash docker compose --profile production up -d

  3. Monitoring Deployment - Adds Prometheus and Grafana for observability: bash docker compose --profile monitoring up -d

Docker Configuration

  • Environment Variables: Configure the service using environment variables:

    • GOSCRY_API_KEY: API key for authentication
    • LOG_LEVEL: Logging level (debug, info, warn, error)
    • AUTO_GENERATE_API_KEY: Auto-generate a secure API key
  • Volumes: The Docker setup includes persistent volumes for:

    • Configuration data
    • Prometheus metrics (when using monitoring profile)
    • Grafana dashboards (when using monitoring profile)

For detailed Docker deployment instructions, see DOCKER.md.

Continuous Integration and Deployment

GoScry uses GitHub Actions for CI/CD:

  • Automated testing on each push to main and pull request
  • Automated binary builds for Linux, macOS (Intel and ARM), and Windows
  • Automatic releases when a version tag is pushed (e.g., v1.0.0)

For detailed information about the release process, see RELEASING.md.

Configuration

GoScry is configured via a config.yaml file or environment variables.

  1. Copy the example configuration: bash cp config.example.yaml config.yaml
  2. Edit config.yaml to suit your environment:
    • server.port: Port the API server listens on.
    • browser.executablePath: Absolute path to the Chrome/Chromium executable (leave empty to attempt auto-detect).
    • browser.headless: true to run headless, false for headed mode.
    • browser.userDataDir: Path to a persistent user profile directory (optional, creates temporary profile if empty).
    • browser.maxSessions: Maximum concurrent browser instances.
    • log.level: Logging level (debug, info, warn, error).
    • security.allowedOrigins: List of origins allowed for CORS requests. Use specific domains in production instead of *.
    • security.apiKey: A secret key required for API access (set via GOSCRY_SECURITY_APIKEY environment variable for better security).

Environment variables override file settings. They are prefixed with GOSCRY_ and use underscores instead of dots (e.g., GOSCRY_SERVER_PORT=9090, GOSCRY_SECURITY_APIKEY=your-secret-key).

Running the Server

bash ./goscry -config config.yaml

Or, if using environment variables primarily:

```bash export GOSCRYSECURITYAPIKEY="your-secret-key"

export GOSCRYBROWSEREXECUTABLEPATH="/path/to/chrome" # Optional

./goscry ```

The server will start and log output to the console based on the configured log level.

API Usage

The API listens on the configured port (default 8080) under the /api/v1 path prefix. Authentication via X-API-Key or Authorization: Bearer <key> header is required if security.apiKey is set.

Endpoints

  • POST /api/v1/tasks: Submit a new browser task.

    • Request Body: SubmitTaskRequest JSON (see internal/server/handlers.go). Includes actions, optional credentials, two_factor_auth info, and callback_url.
    • Response (Success): 202 Accepted with SubmitTaskResponse JSON containing the task_id.
    • Response (Error): 400 Bad Request, 401 Unauthorized, 403 Forbidden, 500 Internal Server Error.
  • GET /api/v1/tasks/{taskID}: Get the current status and result of a task.

    • URL Parameter: taskID (UUID string).
    • Response (Success): 200 OK with Task JSON (see internal/tasks/task.go).
    • Response (Error): 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
  • POST /api/v1/tasks/{taskID}/2fa: Provide a 2FA code for a task waiting for it.

    • URL Parameter: taskID (UUID string).
    • Request Body: Provide2FACodeRequest JSON (e.g., {"code": "123456"}).
    • Response (Success): 200 OK with simple success message.
    • Response (Error): 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Conflict (if task not waiting), 408 Request Timeout (if task timed out waiting), 500 Internal Server Error.
  • POST /api/v1/dom/ast: Get a DOM Abstract Syntax Tree from a URL with optional parent selector.

    • Request Body: GetDomASTRequest JSON (e.g., {"url": "https://example.com", "parent_selector": "div#main"} - the parent_selector is optional).
    • Response (Success): 200 OK with a structured DOM tree represented as nested DomNode objects.
    • Response (Error): 400 Bad Request, 401 Unauthorized, 403 Forbidden, 500 Internal Server Error.

Action Types

The actions array in the submit request defines the steps:

| Type | Description | selector Used | value Used | format Used | | :---------------- | :-------------------------------------------------------------------------- | :-------------- | :------------------------------------------------------------------------- | :-------------------------- | | Maps | Navigates the browser to a URL. | No | URL string | No | | wait_visible | Waits for an element matching the selector to become visible. | Yes | Optional duration (e.g., "5s", default "30s") | No | | wait_hidden | Waits for an element matching the selector to become hidden. | Yes | Optional duration (e.g., "5s", default "30s") | No | | wait_delay | Pauses execution for a specified duration. | No | Duration string (e.g., "2s", "500ms") | No | | click | Waits for an element to be visible and clicks it. | Yes | No | No | | type | Types text into an element. Use {{task.tfa_code}} for 2FA code injection. | Yes | Text string, or {{task.tfa_code}} | No | | select | Selects an option within a <select> element by its value attribute. | Yes | Option value string | No | | scroll | Scrolls the page (top, bottom) or an element into view. | If value is not top/bottom | top, bottom, or empty (uses selector) | No | | screenshot | Captures a full-page screenshot. Result attached to task result. | No | Optional JPEG quality (0-100, default 90) | base64 (string) or png (bytes) | | get_dom | Retrieves DOM content. Result attached to task result. | Optional (defaults to body) | No | full_html, simplified_html, text_content | | run_script | Executes arbitrary JavaScript in the page context. Result attached. | No | JavaScript code string | No |

Using the DOM AST API

Overview

The DOM AST API provides a structured representation of a webpage's Document Object Model (DOM) as an Abstract Syntax Tree. This functionality enables:

  • Analyzing page structure programmatically
  • Extracting specific sections of a page with their hierarchical relationships intact
  • Performing targeted content extraction with scope control

Endpoint

POST /api/v1/dom/ast

Request Parameters

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | url | string | Yes | The URL of the webpage to analyze | | parent_selector | string | No | CSS selector to scope the AST to a specific element (e.g., #main-content, div.container) |

Response Structure

Each node in the DOM AST has the following structure:

json { "nodeType": "element", // "element", "text", "comment", or "document" "tagName": "div", // HTML tag name (for element nodes) "id": "main", // ID attribute (if present) "classes": ["container"], // Array of CSS classes (if present) "attributes": { // Map of all attributes "id": "main", "class": "container" }, "textContent": "", // Text content (primarily for text nodes) "children": [] // Array of child nodes }

Example Usage

Request:

bash curl -X POST http://localhost:8080/api/v1/dom/ast \ -H "Content-Type: application/json" \ -H "X-API-Key: your-api-key" \ -d '{ "url": "[https://example.com](https://example.com)", "parent_selector": "#main-content" }'

Response:

json { "nodeType": "element", "tagName": "div", "attributes": {"id": "main-content"}, "children": [ { "nodeType": "element", "tagName": "h1", "attributes": {"class": "title"}, "children": [], "textContent": "Welcome to Example.com" }, { "nodeType": "element", "tagName": "p", "attributes": {}, "children": [], "textContent": "This domain is for use in illustrative examples in documents." } ] }

Implementation Notes

  • The DOM AST feature uses ChromeDP's selector support for robust CSS selector matching
  • Waits 5 seconds for JavaScript-heavy pages to fully load before processing
  • Works with both simple sites and complex modern web applications that use frameworks like React, Vue, or Angular
  • Handles a wide range of CSS selectors including tag, class, ID, and nested selectors

Contribution

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

```

Owner

  • Name: Donald Johnson
  • Login: copyleftdev
  • Kind: user
  • Location: Los Angeles

GitHub Events

Total
  • Watch event: 2
  • Push event: 23
  • Pull request event: 6
  • Create event: 4
Last Year
  • Watch event: 2
  • Push event: 23
  • Pull request event: 6
  • Create event: 4

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 0
  • Total pull requests: 3
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 minute
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 3
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 minute
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • copyleftdev (6)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads: unknown
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
proxy.golang.org: github.com/copyleftdev/goscry
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.6%
Average: 5.8%
Dependent repos count: 6.0%
Last synced: 9 months ago

Dependencies

.github/workflows/ci.yml actions
  • actions/checkout v4 composite
  • actions/setup-go v5 composite
go.mod go
  • github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc
  • github.com/chromedp/cdproto v0.0.0-20250319231242-a755498943c8
  • github.com/chromedp/chromedp v0.13.3
  • github.com/chromedp/sysutil v1.1.0
  • github.com/davecgh/go-spew v1.1.1
  • github.com/fsnotify/fsnotify v1.8.0
  • github.com/go-chi/chi/v5 v5.2.1
  • github.com/go-chi/cors v1.2.1
  • github.com/go-json-experiment/json v0.0.0-20250211171154-1ae217ad3535
  • github.com/go-viper/mapstructure/v2 v2.2.1
  • github.com/gobwas/httphead v0.1.0
  • github.com/gobwas/pool v0.2.1
  • github.com/gobwas/ws v1.4.0
  • github.com/google/uuid v1.6.0
  • github.com/pelletier/go-toml/v2 v2.2.3
  • github.com/pmezard/go-difflib v1.0.0
  • github.com/pquerna/otp v1.4.0
  • github.com/sagikazarmark/locafero v0.9.0
  • github.com/sourcegraph/conc v0.3.0
  • github.com/spf13/afero v1.14.0
  • github.com/spf13/cast v1.7.1
  • github.com/spf13/pflag v1.0.6
  • github.com/spf13/viper v1.20.1
  • github.com/stretchr/testify v1.10.0
  • github.com/subosito/gotenv v1.6.0
  • go.uber.org/multierr v1.11.0
  • go.uber.org/zap v1.27.0
  • golang.org/x/net v0.38.0
  • golang.org/x/sync v0.12.0
  • golang.org/x/sys v0.31.0
  • golang.org/x/text v0.23.0
  • gopkg.in/yaml.v3 v3.0.1
go.sum go
  • github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc
  • github.com/chromedp/cdproto v0.0.0-20250319231242-a755498943c8
  • github.com/chromedp/chromedp v0.13.3
  • github.com/chromedp/sysutil v1.1.0
  • github.com/davecgh/go-spew v1.1.0
  • github.com/davecgh/go-spew v1.1.1
  • github.com/frankban/quicktest v1.14.6
  • github.com/fsnotify/fsnotify v1.8.0
  • github.com/go-chi/chi/v5 v5.2.1
  • github.com/go-chi/cors v1.2.1
  • github.com/go-json-experiment/json v0.0.0-20250211171154-1ae217ad3535
  • github.com/go-viper/mapstructure/v2 v2.2.1
  • github.com/gobwas/httphead v0.1.0
  • github.com/gobwas/pool v0.2.1
  • github.com/gobwas/ws v1.4.0
  • github.com/google/go-cmp v0.6.0
  • github.com/google/uuid v1.6.0
  • github.com/kr/pretty v0.3.1
  • github.com/kr/text v0.2.0
  • github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80
  • github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde
  • github.com/pelletier/go-toml/v2 v2.2.3
  • github.com/pmezard/go-difflib v1.0.0
  • github.com/pquerna/otp v1.4.0
  • github.com/rogpeppe/go-internal v1.9.0
  • github.com/sagikazarmark/locafero v0.9.0
  • github.com/sourcegraph/conc v0.3.0
  • github.com/spf13/afero v1.14.0
  • github.com/spf13/cast v1.7.1
  • github.com/spf13/pflag v1.0.6
  • github.com/spf13/viper v1.20.1
  • github.com/stretchr/objx v0.1.0
  • github.com/stretchr/testify v1.3.0
  • github.com/stretchr/testify v1.10.0
  • github.com/subosito/gotenv v1.6.0
  • go.uber.org/goleak v1.3.0
  • go.uber.org/multierr v1.11.0
  • go.uber.org/zap v1.27.0
  • golang.org/x/net v0.38.0
  • golang.org/x/sync v0.12.0
  • golang.org/x/sys v0.6.0
  • golang.org/x/sys v0.31.0
  • golang.org/x/text v0.23.0
  • gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
  • gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15
  • gopkg.in/yaml.v3 v3.0.1