A browser extension that shows morphological analysis and dictionary definitions for Arabic words on any webpage. Hover over an Arabic word to see its root, pattern, part of speech, and definitions from Hans Wehr and Wiktionary.
Hover over any Arabic word on a webpage to see a tooltip with:
- Morpheme breakdown — prefixes, stem, and suffixes, color-coded
- Root — the Arabic root letters
- Lemma — dictionary form(s)
- Part of speech — with grammatical features (gender, number, etc.)
- Pattern — morphological pattern when available
- Definitions — from Hans Wehr and/or Wiktionary
Click a word to pin the tooltip so it stays visible while you interact with the page. Click elsewhere to dismiss it.
Dialect selection — click the extension icon to choose the Arabic dialect (MSA, Gulf, or Egyptian). The analyzer uses the corresponding CAMeL Tools morphology database, and the dialect's dictionary is shown automatically.
Dictionary selection — choose which dictionaries to include (Hans Wehr, Wiktionary, or both). Unchecking both hides the definitions section entirely.
POS language — toggle part-of-speech labels between English and Arabic.
Enable / disable — turn the extension on or off without uninstalling it. All settings persist across sessions.
sarf/
├── extension/ # Browser extension (WXT + TypeScript)
│ ├── entrypoints/
│ │ ├── content.ts # Content script — hover/click handling
│ │ ├── background.ts # Background script — analysis + dictionary lookup
│ │ └── popup/ # Extension popup — dictionary checkboxes
│ │ ├── index.html
│ │ └── main.ts
│ ├── lib/
│ │ ├── alkhalil.ts # AlKhalil MorphoSys API client (fallback)
│ │ ├── arabic.ts # Arabic text utilities
│ │ ├── cache.ts # TTL cache for analysis results
│ │ ├── camel.ts # CAMeL analysis type conversion
│ │ ├── dict-prefs.ts # Dictionary/dialect/POS preferences (chrome.storage)
│ │ ├── dict-store.ts # IndexedDB dictionary store
│ │ ├── dictionary.ts # Dictionary lookup with fallback strategies
│ │ ├── filter.ts # Filter dictionary entries by source
│ │ ├── pos-translate.ts # POS tag translation (Arabic ↔ English)
│ │ ├── stream-types.ts # Streaming message types for port communication
│ │ ├── timeout.ts # Promise timeout utility
│ │ ├── tooltip.ts # Tooltip rendering
│ │ ├── types.ts # Shared TypeScript types
│ │ └── __tests__/ # Vitest unit tests
│ ├── assets/
│ │ └── tooltip.css # Tooltip styles
│ ├── public/
│ │ ├── dict-compact.json # Bundled dictionary data (loaded into IndexedDB)
│ │ ├── pyodide/ # Pyodide runtime + CAMeL Tools (local analysis)
│ │ │ ├── offscreen.html # Offscreen document entry point
│ │ │ ├── offscreen.js # Pyodide loader + multi-dialect analysis engine
│ │ │ ├── data/ # Gzip-compressed morphology databases
│ │ │ └── [runtime files] # Pyodide WASM, stdlib, Python wheels
│ ├── wxt.config.ts # WXT/manifest configuration
│ └── package.json
├── scripts/
│ ├── build-wiktionary.ts # Downloads + processes Wiktionary Arabic data
│ ├── build-dialect-wiktionary.ts # Downloads + processes dialect Wiktionary data
│ └── compact-dictionaries.ts # Merges Hans Wehr + Wiktionary into compact format
└── pkg/ # Legacy WASM build artifacts (unused)
Prerequisites: Node.js and pnpm.
cd extension
pnpm installDevelopment (auto-reloads on changes):
pnpm dev # Chrome
pnpm dev:firefox # FirefoxProduction build:
pnpm build # Chrome — output in .output/chrome-mv3
pnpm build:firefox # FirefoxPackage for distribution:
pnpm zip # Chrome
pnpm zip:firefox # Firefoxcd extension
pnpm test # Run all tests (Vitest)
pnpm run typecheck # TypeScript type checkingThe compact dictionary file (extension/public/dict-compact.json) is checked into the repo. To rebuild it from source:
-
Download and process Wiktionary data:
cd extension pnpm run build:wiktionary -
Merge sources into the compact format:
npx tsx ../scripts/compact-dictionaries.ts
- The content script listens for mouse movement over Arabic text on any webpage
- When a word is detected, it sends a message to the background script
- The background script forwards the word to an offscreen document running Pyodide (Python in WebAssembly), which loads CAMeL Tools for morphological analysis — entirely local, no network request
- If Pyodide analysis fails, the extension falls back to the AlKhalil MorphoSys API (network request)
- Definitions are looked up in IndexedDB (populated from the bundled compact dictionary on first load)
- Results are filtered by the user's dictionary preferences and sent back to the content script
- The tooltip renders the analysis with color-coded morphemes and expandable definitions
Primary analysis runs entirely locally using CAMeL Tools via Pyodide (Python compiled to WebAssembly). Morphology databases for Gulf, MSA, and Egyptian Arabic are bundled with the extension. No word is sent to any external service for primary analysis.
AlKhalil MorphoSys — morphosyntactic analyzer for Standard Arabic, developed by Université Mohammed Premier (Oujda, Morocco). Used as a fallback only when Pyodide analysis fails. When triggered, the hovered Arabic word is sent to their API. No other page content is transmitted.