How iasunsea/chrome-extension-notion-excalidraw-helper works
Project type and purpose
• There is no separate server or cloud component—everything runs in the browser via content scripts, background scripts, and the Notion/Excalidraw web apps.
File structure
• Top‐level:
• build/ – bundled extension artifacts (main.bundle.js, assets, manifest.json)
• src/ – TypeScript/JavaScript source (img/, js/, manifest.json)
• utils/ – build helper (utils/build.js)
• webpack.config.js, .babelrc – build tool config
• src/js/ contains three core modules:
• main.js – orchestrator (listens for keyboard shortcuts, coordinates copy/paste)
• notion_api.js – abstraction over Notion’s internal API for uploading/fetching images
• The build step (yarn build) uses webpack to produce a single bundle and to inject the manifest.
README for additional insights
• Usage flow:
b. Paste into Notion: extension intercepts paste, uploads image+embedded JSON via notion_api.js.
c. In Notion: when hovering over an image with embedded Excalidraw data, click “Excalidraw” button → data is sent back to Excalidraw for re-import.
• No external backend; communication is between extension scripts and the host page contexts (Excalidraw/Notion).
a. Main components:
• Chrome Extension Contexts:
• Content Script A (runs on Excalidraw domain)
• Content Script B (runs on Notion domain)
• Background Script (optional if messaging is used)
• Host Applications: Excalidraw Web App, Notion Web App
• Build Pipeline: Webpack + Babel
• Storage: chrome.storage (for shortcuts or settings)
b. Relationships & interactions:
1. User triggers keyboard shortcut in Excalidraw → Content Script A captures selection → calls utils.js to serialize data → writes JSON+PNG to clipboard.
2. User pastes into Notion → Content Script B intercepts paste event → notions_api.js uploads blob + JSON payload to Notion server → receives image URL → replaces paste with Notion image block.
3. Hover over image in Notion → Content Script B detects embedded JSON → shows “Excalidraw” button → on click, sends message to Content Script A (via chrome.runtime) with JSON → Excalidraw page re-imports and renders.
4. Build: webpack.config.js bundles src/js into build/main.bundle.js and merges manifests.
c. Architectural patterns & principles:
• Modular content scripts per domain boundary
• Single‐page host apps (Excalidraw/Notion) as external services
• Message passing (chrome.runtime.sendMessage) for cross‐context coordination
• Build‐time bundling to maximize performance and minimize footprint
d. Key technologies:
• Chrome Extension APIs (content scripts, messaging, storage, commands)
• Webpack + Babel for build and transpilation
• Notion’s internal REST/GraphQL endpoints (encapsulated in notion_api.js)
• Excalidraw data model (embedded JSON in PNG data URL)