Complete guide to installing, using, and contributing to the extension.
git clone https://github.com/starmorph/mermaid-anywhere.git
pnpm install && pnpm build
chrome://extensions in Chromedist folderMermaid Anywhere uses a multi-step architecture to render diagrams safely within Chrome's extension security model.
Content Script detects Mermaid code
Scans the page for code blocks with the language-mermaid CSS class. Runs at document_idle and observes DOM mutations for dynamically loaded content.
Service Worker receives render request
The content script sends the Mermaid source code to the background service worker via chrome.runtime.sendMessage.
Offscreen Document renders SVG
The service worker forwards the request to an offscreen document where mermaid.js runs with full DOM access and no CSP restrictions.
SVG injected into the page
The rendered SVG is sent back through the service worker to the content script, which injects it into a Shadow DOM container on the page.
Mermaid.js v10+ uses Function() internally for dynamic code evaluation. Chrome extensions enforce a strict Content Security Policy (CSP) that blocks eval() and Function() in content scripts and service workers. The offscreen document runs in its own context with relaxed CSP, allowing mermaid.js to function normally. The offscreen document auto-closes after 30 seconds of inactivity to conserve resources.
Each rendered diagram is wrapped in a Shadow DOM container. This ensures the extension's styles (toolbar, diagram wrapper, error messages) don't leak into the host page, and the host page's CSS doesn't affect the diagram rendering. The result is consistent, clean diagrams on any website.
Mermaid Anywhere works on any page that uses language-mermaid or language-mmd CSS classes on code blocks. Here are the sites we've tested:
| Site | Domain | Notes |
|---|---|---|
ChatGPT | Renders Mermaid code blocks in AI responses | |
Claude | Renders Mermaid artifacts and code blocks | |
GitHub | README files, issues, PRs, comments | |
Stack Overflow | Questions and answers with Mermaid code | |
Confluence | Wiki pages with Mermaid code blocks | |
Jira | Issue descriptions and comments | |
Notion | Code blocks marked as Mermaid |
Don't see your site? Open an issue and we'll investigate adding support.
Mermaid Anywhere requests only two permissions — the minimum needed to function.
activeTabAccess the current tab to detect and replace Mermaid code blocks with rendered SVG diagrams.
offscreenCreate an offscreen document where mermaid.js can run safely. Required because Mermaid v10+ uses Function() which Chrome extension CSP blocks in content scripts.
No host permissions. The extension uses content_scripts with <all_urls> matching to inject the detector, but the only data it reads is the text content of Mermaid code blocks. No network requests, no cookies, no browsing history.
Each rendered diagram includes a toolbar with three actions:
Opens the diagram in mermaideditor.io with your code pre-loaded. Edit the diagram with syntax highlighting, theme presets, and export as PNG, SVG, or PDF.
Copies the rendered SVG markup to your clipboard. Paste it directly into Figma, Google Slides, or any tool that accepts SVG.
Toggle between the rendered diagram and the original Mermaid source code. Useful for quick reference or copying the raw syntax.

Toolbar rendering a Mermaid diagram on ChatGPT
No analytics, no telemetry, no tracking. The extension collects absolutely no data about you or your browsing.
All Mermaid rendering happens locally in your browser. Your diagram code never leaves your machine.
The extension makes zero network requests. No data is sent to any server, ever.
The full source code is available on GitHub. Audit it yourself.
Still having issues? Open a bug report with your browser version, the site URL, and the Mermaid code that isn't rendering.
Report a BugMermaid Anywhere is open source and MIT licensed. Contributions are welcome.
1. Clone the repository
git clone https://github.com/starmorph/mermaid-anywhere.git cd mermaid-anywhere
2. Install dependencies
pnpm install
3. Start development mode (watch & rebuild)
pnpm dev
4. Build for production
pnpm build
5. Load in Chrome
Open chrome://extensions, enable Developer mode, click “Load unpacked”, and select the dist folder.
mermaid-anywhere/ ├── src/ │ ├── content/ # Content script (detector + injector) │ │ ├── detector.ts # Finds Mermaid code blocks on the page │ │ ├── injector.ts # Replaces code blocks with rendered SVGs │ │ ├── styles.ts # Shadow DOM styles for diagrams & toolbar │ │ └── index.ts # Entry point │ ├── offscreen/ # Offscreen document for mermaid.js rendering │ │ ├── offscreen.html │ │ └── offscreen.ts │ ├── shared/ # Shared types and constants │ └── background.ts # Service worker (message routing) ├── assets/ # Extension icons ├── manifest.json # Chrome extension manifest (MV3) └── package.json
Install the extension and render Mermaid diagrams on any website — no configuration required.