Skip to content

Conversation

@007DXR
Copy link

@007DXR 007DXR commented Dec 23, 2025

🎯 Summary

Extended the Chrome extension's page content reading capability from supporting only the active tab to reading all tabs in the current browser window, enabling the AI assistant to answer questions about any open tab.


🔧 Changes

Modified Files

  • src/popup.ts - Refactored the fetchPageContents() function

Core Improvements

  1. Expanded Query Scope

    • Changed from chrome.tabs.query({ currentWindow: true, active: true })
      To chrome.tabs.query({ currentWindow: true })
    • Now fetches all tabs in the current window
  2. Parallel Multi-tab Processing

    • Use forEach to iterate through all tabs
    • Establish independent message port connections for each tab
    • Use a counter completedTabs to track processing progress
  3. Structured Data Storage

    const allTabContents: { title: string; url: string; content: string }[] = [];
    • Store title, URL, and content for each tab
    • Facilitates distinguishing and referencing different tabs
  4. Formatted Output

    • Consolidate all tab contents into a unified format
    • Each tab includes clear separators and metadata
    • Format: === Tab X: Title ===\nURL: xxx\n\nContent\n\n
  5. Enhanced Error Handling

    • Added try-catch blocks to handle connection failures
    • Added onDisconnect listeners to handle inaccessible pages (e.g., chrome:// pages)
    • Ensures failures on some tabs do not affect processing of others
  6. Updated System Prompt

    • System message explicitly states it contains content from all tabs
    • Prompt changed from "current webpage" to "all X tabs"

⚠️ Notes

  • Only reads tabs from the current window, excluding other windows
  • Some special pages (e.g., chrome://, edge://) cannot be injected with content scripts and will be automatically skipped
  • Initialization performance may be affected when there is a large number of tabs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant