Skip to main content
The Summary tab is the default view when you open Knowledge Tooltip. It fetches and displays a concise Wikipedia summary of your selected term, complete with an optional thumbnail image and a link to the full article.

How It Works

1

Text Selection

Select any text on a webpage (minimum 2 characters). The Knowledge button appears above your selection.
2

Fetch Wikipedia Data

When clicked, the extension sends a request to Wikipedia’s REST API using the search term.
3

Fallback Search

If no exact match is found (404 error), the extension uses Wikipedia’s OpenSearch API to find the closest matching article.
4

Display Results

The tooltip displays the article title, thumbnail (if available), extract text, and a “Read more” link.

API Endpoint Used

The Summary tab uses Wikipedia’s REST API v1:
// Primary fetch
`https://{lang}.wikipedia.org/api/rest_v1/page/summary/{term}`

// Fallback search if 404
`https://{lang}.wikipedia.org/w/api.php?action=opensearch&search={term}&limit=1&format=json&origin=*`
The extension automatically detects language: it uses ar.wikipedia.org for Arabic text and en.wikipedia.org for English.

Code Implementation

From content.js, the main fetch logic:
async function fetchAndShowSummary(searchTerm) {
  const cleanedTerm = cleanSearchTerm(searchTerm, currentLanguage);
  
  // Check cache first
  if (cache.has(cacheKey)) {
    renderSummaryContent(cache.get(cacheKey), contentArea);
    return;
  }

  // Fetch from Wikipedia
  let response = await chrome.runtime.sendMessage({
    action: 'fetchWikipedia',
    term: cleanedTerm,
    language: currentLanguage
  });

  // Fallback to search if not found
  if (!response.success && response.error?.includes('404')) {
    const searchResult = await searchWikipedia(cleanedTerm, currentLanguage);
    if (searchResult) {
      response = await chrome.runtime.sendMessage({
        action: 'fetchWikipedia',
        term: searchResult,
        language: currentLanguage
      });
    }
  }
}
See content.js:393-465 for the complete implementation.

What Users See

The Summary tab displays:
  1. Thumbnail Image - If the Wikipedia article has a lead image
  2. Article Title - The official Wikipedia article title
  3. Extract Text - A 2-3 sentence summary (provided by Wikipedia)
  4. Read More Link - Opens the full Wikipedia article in a new tab
The extension caches up to 30 results per session to minimize API calls and improve performance.

Language Support

The Summary tab fully supports both English and Arabic:
  • Automatic detection: Uses Arabic regex pattern to detect Arabic text
  • Manual override: Users can set a preferred language in extension settings
  • RTL support: Tooltip automatically applies right-to-left layout for Arabic
// Language detection from content.js:145-151
function detectLanguage(text) {
  if (preferredLanguage !== 'auto') {
    return preferredLanguage;
  }
  return containsArabic(text) ? 'ar' : 'en';
}

Error Handling

The Summary tab handles several error cases:
When Wikipedia returns a 404 error, the extension automatically performs a search query to find similar articles. If a match is found, it fetches that article instead. If no match exists, displays: “No Wikipedia article found for [term].”
Displays: “Too many requests. Please try again in a moment.” This occurs when the user makes too many requests in a short time.
Displays: “Unable to connect. Please check your internet connection.” when the request fails due to connectivity issues.

Data Source

Wikipedia REST API: Free, no authentication required

Build docs developers (and LLMs) love