Overview
The Knowledge Tooltip extension integrates with the Wiktionary REST API to fetch detailed word definitions, etymologies, and usage examples. This powers the Dictionary tab in the tooltip.Wiktionary provides linguistic information including parts of speech, definitions, etymologies, and usage notes. The extension supports both English and Arabic Wiktionary.
Features Using This API
- Dictionary Tab: Displays word definitions and linguistic information
- Multi-language Support: Switches between
en.wiktionary.organdar.wiktionary.org - Etymology & Usage: Shows word origins and example sentences
Definition Endpoint
Retrieves dictionary definitions for a word or term.Endpoint
Wiktionary domain:
en.wiktionary.org or ar.wiktionary.orgURL-encoded word or term to look up (e.g.,
ephemeral, serendipity)Implementation
Frombackground.js:113-125:
Request Example
Response Structure
The API returns definitions organized by language and part of speech.Array of definition groups for each language the word appears in
Response Example
Multi-Language Definitions
Wiktionary entries often include definitions for the same word in multiple languages. For example, “chat” has entries in English, French, and other languages.
Example Multi-Language Response
Looking up “chat” in English Wiktionary:Parts of Speech
Wiktionary categorizes definitions by grammatical function:| Part of Speech | Description | Example |
|---|---|---|
noun | Person, place, thing, or idea | ”The book is on the table” |
verb | Action or state of being | ”She runs every morning” |
adjective | Describes a noun | ”The blue sky” |
adverb | Describes a verb, adjective, or other adverb | ”He ran quickly” |
pronoun | Replaces a noun | ”She went home” |
preposition | Shows relationship between words | ”The cat is under the table” |
conjunction | Connects words or clauses | ”Tea and coffee” |
interjection | Expressive exclamation | ”Wow! That’s amazing” |
Error Handling
Error Flow
Frombackground.js:36-40:
Common Error Scenarios
| Status Code | Reason | Solution |
|---|---|---|
404 | Word not found in Wiktionary | Display “No definition found” message |
400 | Invalid term format | Validate input before sending |
500 | Wiktionary server error | Retry or show error state |
Fallback Strategy
The extension may implement a fallback to the Free Dictionary API when Wiktionary returns no results:The Free Dictionary API provides phonetics, audio pronunciations, and additional definition sources when Wiktionary data is unavailable.
Usage in Content Script
Example implementation for displaying Wiktionary definitions:Rate Limits
Wiktionary REST API rate limits:
- 200 requests/second for anonymous users
- No authentication required
- Same infrastructure as Wikipedia REST API
Best Practices
- Cache results: Store definitions locally to avoid repeat requests
- Debounce requests: Wait for user to finish typing before fetching
- User-Agent header: Identify your extension (handled automatically by Chrome)
Data Processing
Wiktionary definitions often include HTML markup. Process carefully:Related Resources
- Wiktionary REST API Documentation
- Wiktionary Content License
- Free Dictionary API (fallback source)