Overview
MaskAgent is a privacy-first browser automation tool that runs entirely on your local machine. It combines a Chrome extension with Ollama to enable AI-driven browser interactions while automatically redacting sensitive information before it reaches the model.
- ๐ Local-first: All AI inference runs on your machine via Ollama
- ๐ก๏ธ Privacy-preserving: PII is detected and redacted before AI processing
- ๐ฏ Goal-driven: Describe what you want, and the agent figures out the steps
- ๐ง Extensible: Add new PII detectors, actions, or AI models
What it Does
Given a natural language goal (e.g., "Fill out this contact form" or "Extract the main article text"), MaskAgent:
- Analyzes the current page's DOM and visual state
- Detects and redacts PII (emails, phone numbers, passwords, etc.)
- Sends sanitized context to a local AI model via Ollama
- Receives structured actions (CLICK, TYPE, SCROLL, SELECT, DONE)
- Validates and executes actions on the page
- Repeats until the goal is achieved
What it Doesn't Do
- No cloud dependencies โ everything runs locally
- No data storage โ page data is processed ephemerally
- No credential capture โ passwords are redacted
- No cross-origin automation โ works within a single tab
Quick Start
1. Clone the repository
git clone https://github.com/bhuvanesh-m-dev/maskagent.git
cd maskagent
2. Install Ollama & pull a model
# Install Ollama (macOS/Linux)
curl -fsSL https://ollama.com/install.sh | sh
# Pull a supported model
ollama pull deepseek-coder
# Verify models
ollama list
3. Load the extension in Chrome
- Open
chrome://extensions/ - Enable Developer Mode
- Click Load unpacked
- Select the
maskagent/code_files/directory
4. Run your first agent
- Navigate to any webpage
- Click the MaskAgent extension icon
- Enter a goal (e.g., "Find and click the login button")
- Click Run Agent
See Architecture to understand the system, or Codebase Guide to dive into the source.
Requirements
| Component | Requirement | Notes |
|---|---|---|
| Browser | Chrome 88+ / Brave / Edge | Manifest V3 support required |
| Ollama | Latest version | Must be running locally |
| Model | deepseek-coder / llava / qwen2.5-vl | At least one text model required |
| Git | 2.x+ | For cloning the repository |
MaskAgent uses Manifest V3 and Chrome-specific APIs. Firefox support is not currently implemented.
Installation
Directory Structure
maskagent/
โโโ code_files/ # โ Extension source
โ โโโ manifest.json # Extension configuration
โ โโโ background.js # Service worker & AI orchestration
โ โโโ content.js # Page interaction & privacy
โ โโโ popup.html # UI
โ โโโ popup.js # UI controller
โ โโโ styles.css # UI styling
โโโ img/ # Assets
โโโ docs/ # Documentation
โโโ README.md
Loading the Extension
- Open Chrome and navigate to
chrome://extensions/ - Toggle Developer Mode on (top-right)
- Click Load unpacked
- Select the
code_files/directory inside the repository - Verify MaskAgent appears in your extensions list
Verifying Ollama Connection
# Check if Ollama is running
curl http://localhost:11434/api/tags
# If not, start it
ollama serve
# List installed models
ollama list
After changing any source file, reload the extension at
chrome://extensions/ by clicking the refresh icon
on the MaskAgent card.
Architecture
MaskAgent is composed of three primary runtime components that communicate via Chrome's message-passing APIs.
Trust Boundaries
Privacy is enforced at multiple boundaries in the system:
| Boundary | Before | After |
|---|---|---|
| Content Script | Full DOM, raw text, raw screenshots | Redacted DOM, redacted text, masked screenshot |
| Background โ AI | Sanitized context | AI inference (no data stored) |
| AI โ Action | AI-generated action | Validated action before execution |
No PII ever leaves the content script's privacy boundary. The AI model never sees raw sensitive data.
Codebase Guide
manifest.json
Extension configuration defining permissions, entry points, and content script injection rules.
{
"manifest_version": 3,
"name": "MaskAgent",
"permissions": ["activeTab", "storage", "scripting"],
"host_permissions": [
"http://localhost:11434/*",
"https://*/",
"http://*/"
],
"background": { "service_worker": "background.js" },
"action": { "default_popup": "popup.html" },
"content_scripts": [
{
"matches": [""],
"js": ["content.js"],
"run_at": "document_idle"
}
]
}
background.js
Purpose: Service worker orchestrating the agent loop, communicating with Ollama, and coordinating between popup and content script.
Key Functions
runAgent(goal, model)โ Initializes a new agent sessionagentLoop()โ Main execution loop (get state โ AI โ execute โ repeat)queryOllama(prompt)โ Sends prompt to Ollama, parses JSON responsevalidateAction(action)โ Validates action schema and parametersexecuteAction(action)โ Sends action to content script
State Management
let session = {
id: string,
tabId: number,
goal: string,
model: string,
step: number,
maxSteps: 10,
history: [{ step, action, result }],
status: 'idle' | 'running' | 'complete' | 'error'
};
content.js
Purpose: Runs in page context for DOM analysis, PII detection/redaction, screenshot capture, and action execution.
Key Functions
getPageState(options)โ Collects DOM, text, and optionally screenshotextractDOM()โ Builds structured element list with bounding rectsdetectPII(dom)โ Scans for sensitive patterns (email, phone, password, etc.)redactPII(dom)โ Replaces sensitive values with***REDACTED***captureScreenshot()โ Captures canvas, redacts sensitive areasexecuteAction(action)โ Executes CLICK, TYPE, SCROLL, SELECT, DONE
PII Detection Patterns
const patterns = {
email: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/,
phone: /[\+\d]?[\( ]?\d{3}[\)\- ]?\d{3}[\- ]?\d{4}/,
password: /password|passwd|pwd/i,
creditCard: /\d{4}[\- ]?\d{4}[\- ]?\d{4}[\- ]?\d{4}/
};
popup.html & popup.js
Purpose: UI and controller for the extension popup. Handles goal input, model selection, and displays agent status/logs.
| File | Sends To | Receives From |
|---|---|---|
popup.js | background.js | background.js |
background.js | content.js, Ollama | popup.js, content.js |
content.js | background.js | background.js |
Agent Pipeline
Action Schema
The AI model must respond with a JSON object matching one of these schemas:
| Action | Schema | Description |
|---|---|---|
CLICK |
{ "type": "CLICK", "target": "#button-id" } |
Clicks the specified element |
TYPE |
{ "type": "TYPE", "target": "#input", "value": "text" } |
Types text into an input/textarea |
SCROLL |
{ "type": "SCROLL", "target": "down" } |
Scrolls (up/down/top/bottom) |
SELECT |
{ "type": "SELECT", "target": "#select", "value": "option" } |
Selects an option from a dropdown |
DONE |
{ "type": "DONE" } |
Signals task completion |
All actions are validated before execution. Invalid actions (missing target, unknown type) are rejected and logged.
Privacy Architecture
MaskAgent's privacy model is built on the principle of data minimization โ only the minimum necessary information is sent to the AI model.
DOM-Level Redaction
The content script scans the DOM and marks elements as sensitive based on:
- Field type:
input[type="password"]โ automatically sensitive - Field name:
name="email",name="phone", etc. - Pattern matching: Email addresses, phone numbers, credit card numbers
Sensitive values are replaced with ***REDACTED***
before being sent to the background script.
Visual Redaction
When screenshots are captured (for vision models), the canvas is redacted by drawing black rectangles over sensitive element bounding boxes.
What the AI Sees
- DOM: Element tags, IDs, classes, attributes โ but values are redacted
- Text: Page text with patterns replaced by
[EMAIL],[PHONE], etc. - Screenshot: Page image with sensitive areas masked in black
- Never: Passwords, credit card numbers, private addresses
Limitations
- False negatives: Some sensitive fields may not be detected
- False positives: Non-sensitive fields may be unnecessarily redacted
- Dynamic content: JavaScript-rendered content may be missed
- Shadow DOM: Limited support for shadow DOM elements
Always verify redaction works on your test pages. See the Testing section for guidelines.
Ollama Integration
API Endpoint
MaskAgent communicates with Ollama via the local API endpoint:
http://localhost:11434/api/generate
Request Format
POST /api/generate
{
"model": "deepseek-coder",
"prompt": "... sanitized context + goal ...",
"stream": false
}
Supported Models
| Model | Type | Use Case |
|---|---|---|
deepseek-coder | Text | General browser automation (recommended) |
llava | Vision | Visual understanding of page layouts |
qwen2.5-vl | Vision | Alternative vision model |
Model Selection
Models are selected via the popup dropdown. The extension does not automatically detect installed models โ the user must choose one that is installed.
Verifying Models
# List installed models
ollama list
# Pull a model
ollama pull deepseek-coder
# Check model details
ollama show deepseek-coder
The extension has host_permissions for
http://localhost:11434/*, which allows
communication with Ollama without CORS issues.
Models
MaskAgent currently supports three model types, each with different strengths and requirements.
DeepSeek-Coder (Recommended)
- Size: ~4.7GB
- Type: Text-only
- Strength: Excellent at code-like structured outputs
- Use: Most automation tasks, form filling, navigation
LLaVA
- Size: ~4.3GB
- Type: Vision + Text
- Strength: Understands visual layout and UI elements
- Use: Finding buttons by appearance, visual QA
Qwen2.5-VL
- Size: ~7GB
- Type: Vision + Text
- Strength: Alternative vision model with strong reasoning
- Use: Complex visual understanding tasks
Start with deepseek-coder for most tasks.
Switch to a vision model when the agent needs to "see" the page layout.
Action Contract
The AI model must output actions in a specific JSON format. MaskAgent validates these actions before execution.
CLICK
{
"type": "CLICK",
"target": "#submit-button"
}
Clicks the element matching the target selector.
Target can be ID (#id), class (.class),
or any valid CSS selector.
TYPE
{
"type": "TYPE",
"target": "#email-input",
"value": "test@example.com"
}
Types the given value into the target input/textarea.
Triggers input and change events.
SCROLL
{
"type": "SCROLL",
"target": "down"
}
Scrolls the page. Valid targets: "up", "down",
"top", "bottom".
SELECT
{
"type": "SELECT",
"target": "#country",
"value": "US"
}
Selects an option in a <select> dropdown.
Triggers a change event.
DONE
{
"type": "DONE"
}
Signals that the task is complete. The agent loop will stop.
To teach the model about these actions, include the action schema in the system prompt or examples.
Testing
Local Test Page
Create a test HTML page with various form elements:
<!DOCTYPE html>
<html>
<body>
<h2>Test Form</h2>
<form>
<label>Name: <input type="text" name="name" value="John Doe"></label><br>
<label>Email: <input type="email" name="email" value="john@example.com"></label><br>
<label>Phone: <input type="tel" name="phone" value="123-456-7890"></label><br>
<label>Password: <input type="password" name="password" value="secret123"></label><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
Privacy Tests
- Verify email addresses are redacted โ
[EMAIL] - Verify phone numbers are redacted โ
[PHONE] - Verify password fields are marked sensitive
- Verify screenshot redaction masks sensitive areas
Agent Tests
- Test
CLICKon buttons and links - Test
TYPEinto input fields - Test
SCROLLnavigation - Test
SELECTdropdown options - Test
DONEcompletion detection
Negative Tests
- Missing element โ agent should handle gracefully
- Invalid action โ validation should reject
- Ollama unavailable โ error handling
- Malformed model output โ parse errors
Always use synthetic test data. Never submit real personal information, credentials, or sensitive content.
Debugging
Extension Debugging
Popup Console:
- Right-click the extension icon โ Inspect Popup
- View logs in the Console tab
Service Worker Console:
- Go to
chrome://extensions/ - Find MaskAgent and click service worker (or background page)
- View logs in the Console tab
Content Script Console:
- Open the page's developer tools (F12 or Cmd+Opt+I)
- Look for logs from
content.js
Ollama Debugging
# Check Ollama status
ollama list
# View Ollama logs
ollama serve
# Test Ollama API directly
curl -X POST http://localhost:11434/api/generate \
-H "Content-Type: application/json" \
-d '{"model": "deepseek-coder", "prompt": "Hello", "stream": false}'
Common Issues
| Issue | Likely Cause | Solution |
|---|---|---|
| Extension not loading | Wrong directory selected | Select code_files/ directory |
| Ollama connection error | Ollama not running | Run ollama serve |
| Model not found | Model not installed | Run ollama pull deepseek-coder |
| Invalid JSON from model | Model output not JSON | Check prompt, adjust examples |
| Action target not found | Element not in page | Wait for page to load, check selector |
Extending MaskAgent
Adding a New PII Detector
- Open
content.js - Locate the
detectPII()function - Add your pattern to the
patternsobject - Update the
redactPII()function if needed
// In content.js - detectPII()
const patterns = {
email: /.../,
phone: /.../,
// Add your new pattern here
customId: /CUST-\d{4}-\d{4}/
};
Adding a New Browser Action
- Define the action schema in the prompt (background.js)
- Update validation in
validateAction()(background.js) - Implement execution in
executeAction()(content.js) - Add tests (see Testing)
- Update documentation
// In content.js - executeAction()
case 'NEW_ACTION':
// Implement your logic
// Return { success: true, action: 'new_action' }
break;
Adding a New AI Model
- Add the model to the
<select>inpopup.html - The model must support the same API contract (JSON response)
- Test with the new model
When adding new functionality, test with synthetic data first. Use the Testing guide for examples.
Contributing
Development Workflow
- Fork the repository on GitHub
- Clone your fork locally
- Create a branch for your change
- Make changes following the code style
- Test locally (see Testing)
- Verify privacy โ no sensitive data in logs
- Update documentation if needed
- Commit with clear messages
- Push to your fork
- Open a Pull Request
Pull Request Requirements
- Explain what changed and why
- Describe how you tested it
- Confirm no privacy regression occurred
- Update documentation if you changed behavior
Areas for Contribution
- Privacy: Better PII detection, visual redaction, OCR
- Agent Intelligence: Planning, better validation, task completion
- Security: Prompt injection, action permissions, auditing
- Performance: Faster inference, DOM extraction, context compression
- Browser Compatibility: More browsers, better support
Do not include real credentials, personal data, or sensitive information in test cases, screenshots, logs, or pull requests.
Security Model
Local Inference
All AI processing runs locally via Ollama. No data leaves your machine.
The extension only communicates with localhost:11434.
Permission Model
activeTabโ Only active tab accessstorageโ Local settings onlyscriptingโ Required for content script injectionhost_permissionsโ For Ollama and web pages
Action Validation
- All AI-generated actions are validated before execution
- Invalid actions are rejected with errors
- Actions are limited to safe operations (no destructive commands)
Known Risks
- Prompt Injection: User goals could influence model behavior
- Model Hallucinations: AI may generate unexpected actions
- Unintended Actions: The model might target wrong elements
- Dynamic Content: Page changes after state capture
If you discover a security vulnerability, please open a GitHub issue (private if sensitive) or contact the maintainers directly.
Limitations
| Area | Limitation | Status |
|---|---|---|
| Browser | Chrome/Chromium only | Firefox not supported |
| Single Tab | Operates on one tab at a time | Architecture constraint |
| Cross-Origin | Cannot interact with iframes | Browser security boundary |
| PII Detection | Not perfect (false positives/negatives) | Improvement needed |
| Shadow DOM | Limited support | Improvement needed |
| Dynamic Content | May miss changes after initial capture | Improvement needed |
| Model Dependence | Quality depends on LLM capabilities | Model-specific |
| Max Steps | 10-step limit (configurable in code) | Hard-coded |
These limitations are known and being addressed. Contributions are welcome in all these areas.
MaskAgent ยท Smart India Hackathon 2026 (SIH26171) ยท GitHub ยท Back to top โ
MaskAgent