Claude Skills Guide

AI Study Helper Chrome Extension: A Developer’s Guide

Chrome extensions have become powerful tools for enhancing productivity, and AI-powered study helpers represent one of the most impactful categories. Whether you’re building your own extension or customizing an existing one, understanding the architecture and implementation patterns helps you create something truly useful for learners.

This guide covers the technical foundations of building an AI study helper Chrome extension, with practical code examples you can adapt for your own projects.

Core Architecture

An AI study helper extension typically consists of three main components:

  1. Content script - Injected into web pages to capture content and interact with the DOM
  2. Background service worker - Handles long-running tasks, API calls, and state management
  3. Popup interface - Provides user controls and displays results

Here’s a minimal manifest.json structure:

{
  "manifest_version": 3,
  "name": "AI Study Helper",
  "version": "1.0.0",
  "permissions": ["activeTab", "storage"],
  "host_permissions": ["<all_urls>"],
  "background": {
    "service_worker": "background.js"
  },
  "content_scripts": [{
    "matches": ["<all_urls>"],
    "js": ["content.js"]
  }],
  "action": {
    "default_popup": "popup.html"
  }
}

Content Script Implementation

The content script acts as your bridge between the web page and your AI functionality. For a study helper, you’ll likely want to extract selected text, article content, or form inputs.

// content.js
class ContentBridge {
  constructor() {
    this.init();
  }

  init() {
    // Listen for text selection
    document.addEventListener('mouseup', (e) => {
      const selection = window.getSelection().toString().trim();
      if (selection.length > 10) {
        this.notifySelection(selection);
      }
    });
  }

  notifySelection(text) {
    chrome.runtime.sendMessage({
      type: 'TEXT_SELECTED',
      payload: {
        text: text,
        url: window.location.href,
        title: document.title,
        timestamp: Date.now()
      }
    });
  }

  // Extract article content using readability patterns
  extractPageContent() {
    const article = document.querySelector('article') || 
                    document.querySelector('.content') ||
                    document.querySelector('main');
    return article ? article.innerText : document.body.innerText;
  }
}

new ContentBridge();

Background Worker and AI Integration

The background service worker handles API calls to AI providers. This separation keeps your API keys secure and prevents blocking the UI during AI processing.

// background.js
const AI_CONFIG = {
  provider: 'anthropic', // or 'openai', 'google'
  model: 'claude-3-haiku-2025-02-19',
  maxTokens: 1024
};

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message.type === 'TEXT_SELECTED') {
    handleAIContent(message.payload)
      .then(result => {
        chrome.tabs.sendMessage(sender.tab.id, {
          type: 'AI_RESPONSE',
          payload: result
        });
      });
  }
  return true;
});

async function handleAIContent(payload) {
  const prompt = buildStudyPrompt(payload.text);
  
  const response = await fetch('https://api.anthropic.com/v1/messages', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': await getApiKey(),
      'anthropic-version': '2023-06-01'
    },
    body: JSON.stringify({
      model: AI_CONFIG.model,
      max_tokens: AI_CONFIG.maxTokens,
      messages: [{ role: 'user', content: prompt }]
    })
  });

  return response.json();
}

function buildStudyPrompt(text) {
  return `Analyze the following text and provide:
1. Key concepts and definitions
2. A brief summary (2-3 sentences)
3. Suggested study questions

Text: ${text.substring(0, 4000)}`;
}

async function getApiKey() {
  const result = await chrome.storage.local.get(['ai_api_key']);
  return result.ai_api_key;
}

Storage and Settings Management

Users need to configure their AI API keys and preferences. Use Chrome’s storage API for persistent settings:

// popup.js - Settings management
document.getElementById('saveSettings').addEventListener('click', async () => {
  const apiKey = document.getElementById('apiKey').value;
  const provider = document.getElementById('provider').value;
  
  await chrome.storage.local.set({
    ai_api_key: apiKey,
    ai_provider: provider
  });
  
  document.getElementById('status').textContent = 'Settings saved!';
});

Practical Features for Study Helpers

Beyond basic text analysis, consider implementing these features:

Flashcard Generation

Parse content and create spaced repetition cards using APIs:

async function generateFlashcards(text, count = 5) {
  const prompt = `Generate ${count} flashcards from this content. 
Format as JSON array with "front" and "back" fields.
Content: ${text}`;
  
  // Call AI and parse response as JSON
  const response = await callAI(prompt);
  return JSON.parse(response.content[0].text);
}

Quiz Mode

Create interactive quizzes from reading material:

function createQuizMode(questions) {
  const quizContainer = document.createElement('div');
  quizContainer.className = 'study-quiz-overlay';
  
  questions.forEach((q, i) => {
    const questionEl = document.createElement('div');
    questionEl.innerHTML = `
      <p><strong>Q${i+1}:</strong> ${q.question}</p>
      ${q.options.map((opt, j) => 
        `<label><input type="radio" name="q${i}" value="${j}"> ${opt}</label>`
      ).join('')}
    `;
    quizContainer.appendChild(questionEl);
  });
  
  document.body.appendChild(quizContainer);
}

Highlight and Annotations

Let users highlight text and add personal notes:

function enableHighlighting() {
  document.addEventListener('mouseup', (e) => {
    const selection = window.getSelection();
    if (selection.toString().trim()) {
      const range = selection.getRangeAt(0);
      const mark = document.createElement('mark');
      mark.className = 'study-highlight';
      mark.dataset.note = '';
      
      range.surroundContents(mark);
      selection.removeAllRanges();
    }
  });
}

Security Considerations

When building AI study helpers, keep these security practices in mind:

Performance Optimization

For extensions that process large amounts of content:

  1. Chunk long content - Break articles into smaller segments before API calls
  2. Cache responses - Store previous analyses in chrome.storage to avoid redundant calls
  3. Use web workers - Offload computational tasks from the main thread
  4. Implement debouncing - Prevent excessive API calls during rapid user interactions

Deployment and Distribution

Once your extension is ready:

  1. Test thoroughly using Chrome’s developer mode (Load unpacked)
  2. Create a clean icon and description for the Chrome Web Store
  3. Implement proper error handling and user feedback
  4. Consider open-sourcing on GitHub for community contributions

Building an AI study helper Chrome extension combines web development skills with AI integration, creating a genuinely useful tool for learners. Start with the basics - text selection and analysis - then iterate based on user feedback.

Built by theluckystrike — More at zovo.one