This document specifies the architecture and implementation details for a Chrome extension that injects a custom button into CKEditor (v4) instances on web pages. The button launches a custom MJML editor for email creation. Users can save MJML templates locally, with metadata, and upon saving, the extension converts MJML to HTML and replaces the CKEditor source view content.
- Content Script: Injects CKEditor button and handles UI integration.
- Background Script: Manages MJML template storage and metadata.
- MJML Editor UI: Custom modal/editor for MJML email creation.
- MJML Conversion Service: Converts MJML to HTML (local or remote API).
- Chrome Storage: Persists MJML templates, names, creation, and last edit dates.
- Content script detects CKEditor instance and injects toolbar button.
- User clicks button; MJML editor modal opens.
- User creates/edits MJML template, names it, and saves.
- MJML, name, and timestamps are stored locally.
- MJML is converted to HTML.
- HTML replaces CKEditor source view content.
- Manifest v3
- Permissions:
- activeTab (inject scripts)
- storage (local MJML template management)
- scripting (DOM manipulation)
- Optional: webRequest if using remote MJML API
- Detect CKEditor instance via CKEDITOR.instances.
- Add command and button using CKEditor API.
- Render button HTML and inject into .cke_toolbar.
- Re-initialize button listeners for functional UI.
- On button click, open MJML editor modal (injected into page DOM).
- Modal includes MJML code editor, name field, and save/cancel actions.
{ "templates": [ { "name": "Welcome Email", "mjml": "...", "created": "2025-12-23T10:00:00Z", "lastEdited": "2025-12-23T10:05:00Z" } ] }
- Use chrome.storage.local for persistence.
- CRUD operations for templates (create, read, update, delete).
- Store template name, creation date, last edit date.
- Display metadata in MJML editor UI for selection and management.
- Local: Bundle MJML JS (if feasible in extension context).
- Remote: Call MJML API (requires network permission).
- Validate MJML before conversion.
- Display conversion errors in modal.
- Fallback to last valid HTML if conversion fails.
- After conversion, switch CKEditor to source view.
- Replace editor content with generated HTML.
- Optionally, switch back to WYSIWYG view.
- Sanitize MJML/HTML before injection.
- Restrict extension to trusted domains if needed.
- Avoid exposing sensitive data in storage.
- Test on Windows, macOS, Linux Chrome browsers.
- Ensure CKEditor v4 compatibility; document limitations for other versions.
- Log extension actions (button injection, MJML save, conversion errors) to console for debugging.
- Optionally, provide user-facing error messages in modal.
- CKEditor button is injected and functional on supported pages.
- MJML editor modal opens, saves, and lists templates with metadata.
- MJML is converted and replaces CKEditor source view content.
- Templates persist across browser sessions.
- All actions are robust against errors and edge cases.
- Button not visible: Check CKEditor version and DOM structure.
- MJML conversion fails: Validate MJML syntax; check API connectivity.
- Templates not saving: Verify Chrome storage permissions.
- HTML not injected: Ensure source view is active and editor instance is correct.
- CKEditor 4 API Documentation: https://ckeditor.com/docs/ckeditor4/latest/api/
- MJML Documentation: https://mjml.io/documentation/
- Chrome Extension Manifest V3: https://developer.chrome.com/docs/extensions/mv3/intro/