See the Hidden Environmental Cost of Your Browsing
GreenTab is a Chrome extension that tracks your browsing habits and calculates the environmental impact (energy, water, and COβ emissions) of the websites you visit. It includes a comprehensive dashboard with AI-generated insights and weekly email recaps.
- π Real-time tracking - Monitors which website you're on and tracks time spent
- π Environmental impact calculation - Estimates energy (Wh), water (L), and COβ (g) usage
- π’ Green hosting detection - Checks if websites use renewable energy via Green Web Foundation API
- π Live stats - See your impact in real-time as you browse
- π€ Google OAuth authentication - Sign in to sync data across devices
- π Privacy-first - Only tracks domain + time, no content or personal data
- π± Dashboard link - Quick access to your full analytics dashboard
- π Interactive charts - View energy, water, and COβ usage over the last 30 days
- π Trend analysis - See percentage changes compared to previous month
- π― Top domains - Identify which websites consume the most resources
- π€ AI insights - Claude-generated personalized insights and recommendations
- π§ Weekly email recaps - Opt-in to receive "GreenTab Wrapped" style summaries
- π¨ Modern UI - Dark theme with beautiful visualizations
- Manifest V3 - Modern Chrome extension architecture
- JavaScript - Vanilla JS (no frameworks)
- Chrome Storage API - Local and sync storage
- Chrome Identity API - OAuth authentication
- Chrome Alarms API - Persistent background sync
- Next.js 16 - React framework with App Router
- TypeScript - Type-safe development
- React 19 - UI library
- Tailwind CSS 4 - Utility-first styling
- Recharts - Chart visualization library
- Supabase - Backend (PostgreSQL + Auth)
- Supabase - PostgreSQL database, authentication, and storage
- Claude API (Anthropic) - AI-generated insights and email content
- Resend - Email delivery service
- Green Web Foundation API - Green hosting detection
- Website Carbon API - Carbon intensity data
Before you begin, ensure you have:
-
Node.js (v20.9.0 or higher)
- Check:
node --version - Install: nodejs.org or use
nvm install 20
- Check:
-
npm (comes with Node.js)
- Check:
npm --version
- Check:
-
Google Chrome browser
-
Accounts for APIs (all have free tiers):
- Supabase - Database & Auth
- Anthropic Claude - AI insights (optional)
- Resend - Email service (optional, for weekly emails)
- Google Cloud Console - OAuth credentials
git clone https://github.com/priyagokhale1/green-tab-claude-hackathon.git
cd green-tab-claude-hackathon-
Create a Supabase project:
- Go to supabase.com
- Create a new project
- Note your Project URL and Anon Key from Settings β API
-
Set up the database schema:
- Go to SQL Editor in Supabase
- Run this SQL to create the tracking data table:
-- Create tracking_data table
CREATE TABLE IF NOT EXISTS tracking_data (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
date DATE NOT NULL,
domain TEXT NOT NULL,
total_seconds INTEGER NOT NULL DEFAULT 0,
energy_wh FLOAT,
water_liters FLOAT,
co2_grams FLOAT,
synced_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE(user_id, date, domain)
);
-- Create indexes
CREATE INDEX IF NOT EXISTS idx_tracking_data_user_date
ON tracking_data(user_id, date DESC);
CREATE INDEX IF NOT EXISTS idx_tracking_data_user_domain
ON tracking_data(user_id, domain);
-- Enable Row Level Security
ALTER TABLE tracking_data ENABLE ROW LEVEL SECURITY;
-- Create policies
CREATE POLICY "Users can view own tracking data"
ON tracking_data FOR SELECT
USING (auth.uid() = user_id);
CREATE POLICY "Users can insert own tracking data"
ON tracking_data FOR INSERT
WITH CHECK (auth.uid() = user_id);
CREATE POLICY "Users can update own tracking data"
ON tracking_data FOR UPDATE
USING (auth.uid() = user_id);- Create email subscriptions table (for weekly emails):
-- Create email_subscriptions table
CREATE TABLE IF NOT EXISTS email_subscriptions (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id UUID NOT NULL UNIQUE REFERENCES auth.users(id) ON DELETE CASCADE,
email TEXT NOT NULL,
opted_in BOOLEAN DEFAULT true,
last_sent_at TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Create index
CREATE INDEX IF NOT EXISTS idx_email_subscriptions_user_id
ON email_subscriptions(user_id);
-- Enable Row Level Security
ALTER TABLE email_subscriptions ENABLE ROW LEVEL SECURITY;
-- Create policies
CREATE POLICY "Users can view own email subscription"
ON email_subscriptions FOR SELECT
USING (auth.uid() = user_id);
CREATE POLICY "Users can insert own email subscription"
ON email_subscriptions FOR INSERT
WITH CHECK (auth.uid() = user_id);
CREATE POLICY "Users can update own email subscription"
ON email_subscriptions FOR UPDATE
USING (auth.uid() = user_id);- Enable Google OAuth:
- Go to Authentication β Providers in Supabase
- Enable Google provider
- Get OAuth credentials from Google Cloud Console:
- Create OAuth 2.0 Client ID
- Add authorized redirect URI:
https://[your-project-id].supabase.co/auth/v1/callback
- Add Client ID and Client Secret to Supabase
- Update Supabase credentials in
popup.jsandbackground.js:
// Lines 19-20 in both files
const SUPABASE_URL = 'https://your-project-id.supabase.co';
const SUPABASE_ANON_KEY = 'your-anon-key-here';- Add extension redirect URL to Supabase:
- Load the extension in Chrome first (see Step 5)
- Get your extension ID from
chrome://extensions - In Supabase β Authentication β URL Configuration
- Add redirect URL:
https://[extension-id].chromiumapp.org/
- Navigate to dashboard directory:
cd dashboard- Install dependencies:
npm install- Create environment file:
Create dashboard/.env.local:
# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=https://your-project-id.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key-here
# Claude API (optional - for AI insights)
CLAUDE_API_KEY=your-claude-api-key-here
# Resend API (optional - for weekly emails)
RESEND_API_KEY=re_your-resend-api-key-here
RESEND_FROM_EMAIL=GreenTab <[email protected]>-
Get API keys:
-
Claude API Key (optional):
- Sign up at console.anthropic.com
- Create an API key
- Add to
.env.localasCLAUDE_API_KEY
-
Resend API Key (optional, for weekly emails):
- Sign up at resend.com
- Create an API key
- Add to
.env.localasRESEND_API_KEY - Set
RESEND_FROM_EMAIL(can use default for testing)
-
-
Update Supabase redirect URLs:
- In Supabase β Authentication β URL Configuration
- Add:
http://localhost:3000/api/auth/callback
-
Open Chrome Extensions:
- Go to
chrome://extensions - Enable "Developer mode" (toggle in top right)
- Go to
-
Load the extension:
- Click "Load unpacked"
- Select the
green-tab-claude-hackathonfolder (root directory, not dashboard) - Note your Extension ID (displayed under the extension name)
-
Complete OAuth setup:
- Add the extension redirect URL to Supabase (see Step 3)
- Add the extension redirect URL to Google Cloud Console OAuth credentials
- Start the development server:
cd dashboard
npm run dev- Open in browser:
- Navigate to
http://localhost:3000 - Sign in with the same Google account used in the extension
- Navigate to
-
Supabase (Backend & Auth)
- Purpose: Database storage, user authentication, OAuth
- Setup: supabase.com
- Free tier: 500MB database, 2GB bandwidth
- Credentials needed: Project URL, Anon Key
-
Green Web Foundation API
- Purpose: Check if websites use green hosting
- Endpoint:
https://api.thegreenwebfoundation.org/greencheck/ - Rate limit: Free, no authentication required
- Documentation: thegreenwebfoundation.org
-
Website Carbon API
- Purpose: Get carbon intensity data for websites
- Endpoint:
https://api.websitecarbon.com/site - Rate limit: Free tier available
- Documentation: websitecarbon.com
-
Anthropic Claude API (AI Insights)
- Purpose: Generate personalized insights and email content
- Endpoint:
https://api.anthropic.com/v1/messages - Setup: console.anthropic.com
- Free tier: Pay-as-you-go, very affordable
- Model used:
claude-3-haiku-20240307 - Credentials needed: API key
-
Resend API (Weekly Emails)
- Purpose: Send weekly "GreenTab Wrapped" email recaps
- Endpoint:
https://api.resend.com/emails - Setup: resend.com
- Free tier: 3,000 emails/month
- Credentials needed: API key
No environment variables needed - credentials are in code:
popup.js(lines 19-20):SUPABASE_URL,SUPABASE_ANON_KEYpopup.js(line 24):DASHBOARD_URL(default:http://localhost:3000)
Create dashboard/.env.local:
# Required
NEXT_PUBLIC_SUPABASE_URL=https://your-project-id.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key-here
# Optional - for AI insights
CLAUDE_API_KEY=sk-ant-api03-...
# Optional - for weekly emails
RESEND_API_KEY=re_...
RESEND_FROM_EMAIL=GreenTab <[email protected]>green-tab-claude-hackathon/
βββ manifest.json # Chrome extension configuration
βββ popup.js # Extension popup logic & UI
βββ background.js # Background service worker (tracking & sync)
βββ hello.html # Extension popup HTML
βββ green_tab_logo.png # Extension icon
β
βββ dashboard/ # Next.js dashboard application
β βββ app/
β β βββ page.tsx # Landing page
β β βββ dashboard/
β β β βββ page.tsx # Main dashboard page
β β βββ api/
β β βββ auth/ # Authentication routes
β β βββ insights/ # AI insights endpoint
β β βββ email/ # Email subscription endpoints
β βββ components/
β β βββ charts/ # Chart components (Energy, Water, COβ)
β β βββ Insights.tsx # AI-generated insights
β β βββ EmailOptIn.tsx # Email subscription UI
β β βββ StatsCards.tsx # Summary statistics
β β βββ DomainList.tsx # Top domains list
β βββ lib/
β β βββ claude.ts # Claude API integration
β β βββ email.ts # Resend email integration
β β βββ queries.ts # Supabase queries
β β βββ supabase/ # Supabase clients
β βββ public/ # Static assets
β βββ .env.local # Environment variables (create this)
β βββ package.json # Dependencies
β
βββ README.md # This file
-
Background Script (
background.js):- Monitors active tab changes
- Tracks time spent on each domain
- Calculates environmental impact using APIs
- Syncs data to Supabase every 30 seconds (if authenticated)
- Uses Chrome Alarms API for persistence
-
Popup (
popup.js+hello.html):- Displays real-time stats (energy, water, COβ)
- Shows current domain and session time
- Handles Google OAuth sign-in
- Provides link to dashboard
-
Data Sync:
- Local data stored in
chrome.storage.local - When authenticated, syncs to Supabase every 30 seconds
- Updates
synced_attimestamp on each sync
- Local data stored in
-
Authentication:
- Uses Supabase OAuth (same as extension)
- Server-side session management
- Protected routes with redirect
-
Data Visualization:
- Fetches aggregated data from Supabase
- Displays charts using Recharts
- Shows trends and comparisons
-
AI Insights:
- Calls Claude API with user's data
- Generates personalized insights per category
- Displays concise recommendations
-
Weekly Emails:
- Users can opt-in with email address
- Weekly cron job (or manual trigger) sends emails
- Claude generates "GreenTab Wrapped" style content
-
Load in Chrome:
# No build step needed - just load the folder # Go to chrome://extensions β Load unpacked
-
Test:
- Click the extension icon
- Browse some websites
- Watch the stats update in real-time
-
Start development server:
cd dashboard npm run dev -
Access dashboard:
- Open
http://localhost:3000 - Sign in with Google
- View your data and insights
- Open
-
Test email (optional):
- Opt in to weekly emails on dashboard
- Click "Send Test Email" button
- Check your inbox
"Chrome Identity API not available"
- Reload the extension:
chrome://extensionsβ Reload - Close and reopen the popup
- Restart Chrome
"OAuth redirect URL mismatch"
- Ensure extension redirect URL is added to:
- Supabase β Authentication β URL Configuration
- Google Cloud Console β OAuth credentials
Data not syncing
- Check if signed in (should see "Hi [Name]!" in popup)
- Check browser console for errors:
Ctrl+Shift+J - Verify Supabase credentials in
popup.jsandbackground.js
"Cannot connect to Supabase"
- Check
.env.localhas correctNEXT_PUBLIC_SUPABASE_URLandNEXT_PUBLIC_SUPABASE_ANON_KEY - Restart dev server after changing
.env.local
"No data showing"
- Ensure extension is tracking and syncing data
- Check you're signed in with the same Google account
- Wait a few minutes for data to sync
Insights not generating
- Check
CLAUDE_API_KEYis set in.env.local - Check browser console for API errors
- Verify you have data (insights need at least some tracking data)
Email not sending
- Check
RESEND_API_KEYis set in.env.local - Verify email address format
- Check Resend dashboard for delivery status
Port 3000 already in use:
# Check what's using the port
lsof -i :3000
# Or use a different port
npm run dev -- -p 3001
# Then update DASHBOARD_URL in popup.jsUser Browses
β
Background Script Tracks Domain + Time
β
Fetch Carbon Data (Website Carbon API)
β
Calculate Impact (Energy, Water, COβ)
β
Store Locally (Chrome Storage)
β
[If Authenticated] Sync to Supabase (every 30s)
β
Dashboard Fetches Data
β
Display Charts & Insights
- β No content tracking - Only domain names and time spent
- β Local-first - Data stored locally by default
- β Opt-in sync - Only syncs when user signs in
- β HTTPS only - All API calls use secure connections
- β Row Level Security - Supabase RLS ensures users only see their own data
- β JWT tokens - Secure authentication with expiration
- β No personal data - No URLs, page content, or keystrokes tracked
-
Popup console:
- Right-click extension icon β "Inspect popup"
- Or:
Ctrl+Shift+Jwhen popup is open
-
Background script console:
- Go to
chrome://extensions - Find GreenTab β "service worker" (click to open console)
- Go to
-
Storage inspection:
- DevTools β Application β Storage β Chrome Storage
- Browser console:
F12orCtrl+Shift+J - Server logs: Check terminal where
npm run devis running - Network tab: Inspect API calls in DevTools
- Extension: Reload extension after changes (
chrome://extensionsβ Reload) - Dashboard: Hot reloads automatically (Next.js)
- Environment variables: Restart dev server after changing
.env.local
- Supabase: 500MB database, 2GB bandwidth/month
- Green Web Foundation: No limits (public API)
- Website Carbon: Free tier available
- Claude API: Pay-as-you-go (~$0.25 per 1M tokens)
- Resend: 3,000 emails/month free
- Supabase: Free (within limits)
- Claude API: ~$0.01 (for insights)
- Resend: Free (within 3,000 emails)
- Total: Essentially free for small-scale use
In popup.js (line 24):
const DASHBOARD_URL = 'http://localhost:3000'; // Change to your URLIn dashboard/app/globals.css, update CSS variables:
--energy-color: #facc15; /* Yellow */
--water-color: #38bdf8; /* Blue */
--carbon-color: #fb7185; /* Pink */In background.js, change the alarm interval (line ~304):
chrome.alarms.create('syncData', { periodInMinutes: 0.5 }); // 30 seconds- Chrome Extensions Documentation
- Next.js Documentation
- Supabase Documentation
- Recharts Documentation
- Claude API Documentation
This is a hackathon project. Feel free to fork and modify for your own use!
Built with πΏ for a more sustainable web
- Check browser console for errors
- Verify all environment variables are set
- Ensure all APIs are configured correctly
- Check Supabase database schema is created
- Verify OAuth redirect URLs are configured
For detailed troubleshooting, check the browser console and server logs.