Cookie Compliance Checker Agent
A specialized agent that evaluates websites for cookie compliance with privacy regulations like GDPR and ePrivacy Directive. Built using Browserbase's Stagehand and Mastra for AI-powered web interactions.
Overview
This agent automatically checks if websites set non-essential cookies before obtaining user consent, which is a violation of privacy regulations. It provides a comprehensive analysis of cookie compliance and assigns a compliance score to each website.
Features
- Cookie Compliance Detection: Identifies cookies set before consent is given
- Cookie Categorization: Classifies cookies as essential or non-essential
- Consent Banner Interaction: Automatically finds and interacts with cookie consent mechanisms
- Before/After Analysis: Compares cookies set before and after consent
- Compliance Scoring: Provides a numerical compliance score based on findings
- Detailed Reporting: Lists all cookies with their categories and compliance status
Installation
Prerequisites
- Node.js (v20+)
- pnpm
- Browserbase account
- OpenAI API access
Setup
-
Clone the repository:
1git clone https://github.com/yourusername/cookie-compliance-agent.git 2cd cookie-compliance-agent
-
Install dependencies:
pnpm install
-
Create a
.env
file with your API keys:1BROWSERBASE_PROJECT_ID=your_project_id 2BROWSERBASE_API_KEY=your_api_key 3OPENAI_API_KEY=your_openai_key
Usage
-
Start the agent:
pnpm start
-
Interact with the agent by providing a URL to check for cookie compliance.
-
The agent will:
- Visit the website
- Detect cookies set before consent
- Attempt to find and interact with cookie consent mechanisms
- Detect cookies set after consent
- Provide a detailed compliance analysis and score
Compliance Score Interpretation
- 100: Fully compliant (no non-essential cookies before consent)
- 90-99: Minor issues (1 non-essential cookie)
- 70-89: Moderate issues (2-3 non-essential cookies)
- 50-69: Significant issues (4-5 non-essential cookies)
- 0-49: Severe compliance problems (6+ non-essential cookies)
Development
Running the development server
pnpm run dev
This will start the Mastra development server, giving you access to the integrated web agent.
Architecture
Core Components
-
Stagehand Session Manager
- Handles browser session initialization and management
- Implements automatic session timeouts
- Provides error recovery and reconnection logic
-
Mastra Tools
stagehandActTool
: Performs actions on web pagesstagehandObserveTool
: Identifies elements on web pagesstagehandExtractTool
: Extracts data from web pages
-
Web Agent
- AI-powered agent using OpenAI's model
- Provides natural language interface to web automation
- Integrates all tools into a unified experience
Flow Diagram
User Query → Mastra Agent → Stagehand Tools → Browser Interaction → Web Page → Data/Results → Agent Response
Configuration
The project can be configured through the .env
file and by modifying the agent instructions in src/mastra/agents/index.ts
.
Credits
This project is built with:
- Mastra - AI Agent framework
- Stagehand by Browserbase - Browser automation
- OpenAI - AI models