MOOC Utils

Utils like auto assignment solver extension and course notice announcment notification for MOOC courses

Page information handler

Introduction#

Detects assignment pages and pulls metadata so the rest of the pipeline knows what it is looking at. Bridges the background worker and content script for NPTEL, SWAYAM, and similar layouts.

Project structure#

Page Information Handler sits in the background layer. Nearby pieces:

Core components#

The Page Information Handler consists of several interconnected components working together to provide detailed assignment detection and metadata extraction:

Primary handler functions#

  • Assignment Detection: Identifies NPTEL/SWAYAM assignment pages using URL patterns and content selectors
  • Metadata Extraction: Collects page title, question counts, and structural information
  • Context Validation: Ensures content script availability and proper initialization
  • Response Formatting: Returns standardized metadata for downstream processing

Supporting services#

  • Extractor Service: Provides HTML extraction and image processing capabilities
  • Message Routing: Manages bidirectional communication between background and content scripts
  • Platform Adapters: Handles browser-specific implementations for tabs, scripting, and runtime APIs

Architecture overview#

The Page Information Handler operates within a detailed message-driven architecture that enables smooth communication between extension components:

The handler detects assignment context and leaves HTML extraction to the content-script services.

Detailed component analysis#

Page information handler implementation#

The core handler implements a assignment detection mechanism with detailed error handling and fallback strategies:

Assignment detection logic#

The handler uses a multi-layered approach to identify assignment pages:

Metadata extraction process#

The handler coordinates with the content script to extract detailed page metadata:

Content script integration#

The content script provides essential page analysis capabilities through the extractor service:

Page structure analysis#

The extractor service implements detailed DOM traversal to identify assignment containers and question structures:

Question format detection#

The extractor implements intelligent question format identification through CSS selector targeting:

Message communication protocol#

The handler uses a fixed message protocol for communication:

Dependency analysis#

The Page Information Handler stays loosely coupled to its dependencies while providing essential orchestration:

Platform compatibility#

Cross-browser behavior goes through the platform adapters:

Performance considerations#

The Page Information Handler implements several optimization strategies for efficient operation:

Asynchronous processing#

  • Non-blocking tab operations using Promise-based APIs
  • Configurable retry mechanisms for transient failures
  • Optimistic content script loading with verification

Resource management#

  • Selective DOM querying to minimize performance impact
  • Image extraction with size filtering to reduce bandwidth
  • Graceful degradation when content scripts are unavailable

Error resilience#

  • Detailed error handling with fallback responses
  • Connection error detection and retry logic
  • Timeout management for external operations

Troubleshooting guide#

Common issues and solutions#

Content script loading failures#

Symptoms: Handler reports “Content script not loaded” errors Causes:

  • Content script injection timeout
  • Cross-origin restrictions
  • Browser extension policy limitations

Solutions:

  • Verify content script permissions in manifest
  • Check host permissions for target domains
  • Implement manual content script reload

Assignment detection failures#

Symptoms: Pages not recognized as assignments despite valid URLs Causes:

  • Incorrect URL patterns for new platform versions
  • Dynamic content loading affecting selector detection
  • Missing question containers in DOM

Solutions:

  • Update selector patterns in extractor service
  • Implement dynamic content waiting mechanisms
  • Add fallback detection methods

Message communication errors#

Symptoms: “Receiving end does not exist” or connection failures Causes:

  • Background script initialization delays
  • Firefox-specific timing issues
  • Extension context invalidation

Solutions:

  • Implement retry logic with exponential backoff
  • Use connection error detection and recovery
  • Add timeout mechanisms for message operations

Conclusion#

Page info is the cheap gate before expensive Gemini calls. Wrong platform detection wastes quota and confuses applicators.