Skip to content
VanTranHongPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Privacy Opt-Out Agent

An AI-powered web application that automates privacy opt-out requests (CCPA "Do Not Sell My Personal Information") on any website. You fill in your details once — Claude navigates the site, finds the opt-out form, fills it, and submits it while you watch in real time.


How It Works

User fills form  →  Flask validates URL  →  Playwright opens browser
                                                     ↓
Claude (Sonnet 4.6) calls tools in a loop ←→ reads page / clicks / fills / submits
                                                     ↓
Live screenshots + action log stream back to UI via Server-Sent Events
  1. URL validation — the backend checks whether the URL is reachable. If not, Claude Haiku suggests likely intended sites.
  2. Agent loop — Claude receives a system prompt with the user's details and a step-by-step privacy workflow. It then calls browser tools in a loop (up to 20 turns) until the opt-out is complete.
  3. Live streaming — every action, tool result, and browser screenshot is pushed to the browser in real time over SSE so you can watch the agent work.

Stack

Layer Technology
Backend Python · Flask
AI model Anthropic Claude Sonnet 4.6 (agent) · Claude Haiku 4.5 (URL suggestions)
Browser automation Playwright (Chromium, headless=False)
HTTP client httpx
Frontend Vanilla HTML/CSS/JS (single file, no framework)
Streaming Server-Sent Events (SSE)

Project Structure

WebAgent/
├── server.py       # Flask backend — tools, agent loop, SSE streaming
├── index.html      # Single-page frontend
├── requirements.txt
└── .env            # ANTHROPIC_API_KEY (not committed)

Setup

1. Prerequisites

2. Install dependencies

# From the repo root, activate the shared virtual environment
source env_list/langchain/bin/activate

# Install Python packages
pip install -r agents_practice/claude_code/WebAgent/requirements.txt

# Install Playwright's Chromium browser
playwright install chromium

3. Configure environment

Create a .env file in the WebAgent/ directory:

ANTHROPIC_API_KEY=sk-ant-...

4. Run the server

cd agents_practice/claude_code/WebAgent
python server.py

Then open http://localhost:5002 in your browser.


Usage

  1. Paste a website URL (e.g. amazon.com, target.com).
  2. Enter your name and email (required). Phone, address, city, state, and ZIP are optional but improve form-fill accuracy.
  3. Select your state — US states with strong privacy laws (CA CCPA/CPRA, CO CPA, VA VCDPA, etc.) are highlighted.
  4. Click Start Opt-Out.

The UI switches to a live view showing:

  • A browser screenshot pane that updates as the agent navigates pages.
  • An action log listing every tool the agent calls and the result.
  • A result card with Claude's final confirmation once the form is submitted.

A real Chromium window also opens on your desktop so you can follow along directly.


Claude's Browser Tools

Claude has access to seven tools that control the Playwright browser:

Tool Description
get_page_content Reads visible text, all links, buttons, and form fields from the current page
navigate Navigates to a URL
click_element Clicks a link or button by visible text (fuzzy match)
fill_form_field Types a value into an input field, found by label / placeholder / name / id
check_checkbox Ticks a checkbox by its label
scroll_down Scrolls down to reveal more content (footer links, cookie banners)
submit_form Clicks the submit/send/confirm button

The agent follows this workflow:

  1. Read the page → look for "Do Not Sell", "Your Privacy Choices", "Opt Out" links.
  2. If not found, scroll down 2–3 times (opt-out links are often in footers).
  3. Click the link → read the opt-out form → fill fields → check consent boxes → submit.
  4. Report the confirmation message to the user.

The agent handles cookie consent managers, multi-step forms, and sites that use toggle switches instead of traditional forms. If a CAPTCHA is detected, it reports that and stops rather than attempting to bypass it.


API Endpoints

POST /suggest-urls

Validates a URL and returns suggestions if it is unreachable.

Request

{ "url": "amazn.com" }

Response (reachable)

{ "reachable": true, "url": "https://www.amazon.com/" }

Response (unreachable)

{
  "reachable": false,
  "url": "https://www.amazn.com",
  "suggestions": [
    { "url": "https://www.amazon.com", "label": "Amazon — popular retail marketplace" },
    ...
  ]
}

POST /opt-out-start

Creates a job and returns its ID.

Request

{
  "url": "https://www.target.com",
  "first_name": "Jane",
  "last_name": "Doe",
  "email": "[email protected]",
  "phone": "+1 555 000 0000",
  "address": "123 Main St",
  "city": "Los Angeles",
  "state": "CA",
  "zip_code": "90001"
}

Response

{ "job_id": "a3f7c12b" }

GET /opt-out-stream/<job_id>

SSE stream that runs the Playwright + Claude agent and pushes events.

Event Payload Description
status { "message": "…" } Human-readable status update
screenshot { "image": "<base64 JPEG>", "url": "…", "caption": "…" } Browser screenshot
action { "tool": "click_element", "label": "Clicking 'Privacy Choices'" } Tool call starting
tool_result { "tool": "…", "result": "…" } Tool execution result
agent_text { "text": "…" } Claude's narrative / final summary
done {} Agent finished successfully
error { "message": "…" } Unrecoverable error

The two-phase design (POST to create job → GET to stream) avoids browser and proxy timeout issues with long-running SSE responses.


Architecture Notes

Two-phase job design

The frontend first POSTs to /opt-out-start to register the job, then immediately opens an EventSource to /opt-out-stream/<job_id>. This keeps the SSE response separate from the initial form submission and prevents connection timeouts.

SSE keepalives

Before every Claude API call (which can take 5–30 seconds), the server emits an SSE comment (: keepalive) to keep the HTTP connection alive through proxies and load balancers.

Screenshot streaming

After every tool call, the server takes a JPEG screenshot (quality 72), base64-encodes it, and sends it as an SSE event. The frontend renders it directly from the data URI — no file I/O required.

Graceful error handling

Every top-level exception in the generator is caught and surfaced as an error SSE event instead of silently dropping the connection. Screenshots are also wrapped so a screenshot failure never crashes the stream.


Privacy & Security

  • No data storage — user details exist only in memory for the duration of one job and are discarded immediately after.
  • No third-party tracking — the agent uses a standard browser user-agent and makes requests directly to the target website.
  • CAPTCHA policy — the agent will not attempt to solve CAPTCHAs. It reports their presence and stops.
  • Credential handling — the Anthropic API key is loaded from .env and never logged or exposed to the frontend.

Limitations

  • Works best on sites that implement CCPA-compliant opt-out flows via standard HTML forms.
  • Sites that require SMS verification, account login, or image CAPTCHAs cannot be automated.
  • JavaScript-heavy single-page apps may require additional wait time; the agent uses domcontentloaded + 1.5 s settling delays.
  • The agent is capped at 20 turns to prevent runaway API usage.

Dependencies

anthropic       # Claude API client
flask           # Web server
python-dotenv   # .env loading
httpx           # URL reachability check
beautifulsoup4  # (available for HTML parsing if needed)
playwright      # Browser automation

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages