Skip to main content
The Define tab provides comprehensive dictionary definitions including parts of speech, multiple meanings, phonetic transcriptions, audio pronunciations, and etymological information.

How It Works

1

Primary Source: Wiktionary

The extension first queries Wiktionary’s REST API for the word definition (converted to lowercase).
2

Fallback: Free Dictionary API

If Wiktionary returns no results or fails, the extension falls back to the Free Dictionary API.
3

Parse and Organize

Definitions are grouped by part of speech (noun, verb, adjective, etc.) with up to 3 definitions per category.
4

Display Results

Shows the word, phonetic transcription, audio button, definitions, and etymology (if available).

API Endpoints Used

The Define tab uses two dictionary APIs in sequence:

1. Wiktionary REST API (Primary)

// From background.js:113-125
`https://{lang}.wiktionary.org/api/rest_v1/page/definition/{term}`
Wiktionary provides definitions in multiple languages with rich linguistic data but may not have entries for all terms.

2. Free Dictionary API (Fallback)

// From background.js:127-139
`https://api.dictionaryapi.dev/api/v2/entries/{lang}/{term}`
The Free Dictionary API provides phonetics, audio pronunciations, and etymologies. It works best for English terms.

Code Implementation

From content.js:501-562, the fetch logic with fallback:
async function fetchDefineData(term) {
  try {
    // Try Wiktionary first
    let defineData = null;
    
    const wiktResponse = await chrome.runtime.sendMessage({
      action: 'fetchWiktionary',
      term: term.toLowerCase(),
      language: currentLanguage
    });

    if (wiktResponse.success && wiktResponse.data) {
      defineData = parseWiktionaryData(wiktResponse.data, term);
    }

    // Fallback to Free Dictionary API
    if (!defineData || defineData.definitions.length === 0) {
      const fdResponse = await chrome.runtime.sendMessage({
        action: 'fetchFreeDictionary',
        term: term.toLowerCase(),
        language: currentLanguage
      });

      if (fdResponse.success && fdResponse.data) {
        defineData = parseFreeDictionaryData(fdResponse.data, term);
      }
    }
  } catch (error) {
    // Handle error
  }
}

What Users See

The Define tab displays:

1. Word Header

The search term displayed prominently at the top

2. Phonetic Information

  • Phonetic transcription: IPA notation (e.g., /fəˈnɛtɪk/)
  • Audio button: Play button with speaker icon to hear pronunciation
// Audio playback from content.js:692-696
if (data.audioUrl) {
  const audioBtn = document.createElement('button');
  audioBtn.addEventListener('click', () => {
    const audio = new Audio(data.audioUrl);
    audio.play().catch(() => {});
  });
}

3. Definitions by Part of Speech

Organized sections for each grammatical category:
  • Part of speech label (noun, verb, adjective, etc.)
  • Numbered list of up to 3 definitions per category
HTML tags from Wiktionary responses are automatically stripped for clean display: definition.replace(/<[^>]*>/g, '')

4. Etymology Section

If available from Free Dictionary API, displays the word’s origin and historical development.
// Etymology display from content.js:723-738
if (data.etymology) {
  const etymDiv = document.createElement('div');
  const etymLabel = document.createElement('div');
  etymLabel.textContent = currentLanguage === 'ar' 
    ? 'أصل الكلمة' 
    : 'Etymology';
  const etymText = document.createElement('p');
  etymText.textContent = data.etymology;
}

Data Structure

The extension parses dictionary responses into a unified format:
const defineData = {
  word: "example",
  phonetic: "/ɪɡˈzæmpəl/",
  audioUrl: "https://api.dictionaryapi.dev/media/pronunciations/en/example.mp3",
  definitions: [
    {
      partOfSpeech: "noun",
      meanings: [
        "A thing characteristic of its kind or illustrating a general rule.",
        "A person or thing regarded in terms of their fitness to be imitated."
      ]
    },
    {
      partOfSpeech: "verb",
      meanings: [
        "Be illustrated or exemplified."
      ]
    }
  ],
  etymology: "Late Middle English: from Old French, from Latin exemplum..."
}

Parsing Logic

Wiktionary Parser

// From content.js:564-602
function parseWiktionaryData(data, term) {
  // Wiktionary REST API returns an object with language keys
  // Each language has an array of entries with partOfSpeech and definitions
  for (const langKey in data) {
    const entries = data[langKey];
    for (const entry of entries) {
      const pos = entry.partOfSpeech || '';
      const defs = [];
      
      if (entry.definitions) {
        for (let i = 0; i < Math.min(entry.definitions.length, 3); i++) {
          const cleanDef = def.definition.replace(/<[^>]*>/g, '');
          if (cleanDef) defs.push(cleanDef);
        }
      }
    }
  }
}

Free Dictionary Parser

// From content.js:604-667
function parseFreeDictionaryData(data, term) {
  const entry = data[0];
  
  // Extract phonetic and audio
  if (entry.phonetics) {
    for (const p of entry.phonetics) {
      if (p.audio) {
        result.audioUrl = p.audio;
        if (!result.phonetic && p.text) {
          result.phonetic = p.text;
        }
        break;
      }
    }
  }
  
  // Parse meanings
  if (entry.meanings) {
    for (const meaning of entry.meanings) {
      const defList = meaning.definitions || [];
      for (let i = 0; i < Math.min(defList.length, 3); i++) {
        defs.push(defList[i].definition);
      }
    }
  }
}

Error Handling

Both APIs must fail before an error is shown to the user. This dual-source approach maximizes definition coverage.
Displays: “No definition found for [term].” when both Wiktionary and Free Dictionary return no results.
Displays: “Unable to fetch definition. Please try again.” when the request fails.

Language Support

  • English: Full support with both Wiktionary and Free Dictionary
  • Arabic: Limited support (Wiktionary only, Free Dictionary API has limited Arabic coverage)
  • Case handling: All terms are converted to lowercase before querying

Data Sources

Wiktionary REST API: Free, no authentication required Free Dictionary API: Free, no authentication required

Build docs developers (and LLMs) love